From 6f16274256f8fd6155dae37a28eb4a2dd495005f Mon Sep 17 00:00:00 2001
From: christianwenifr <christianwen18@gmail.com>
Date: Thu, 23 Feb 2023 15:06:46 +0700
Subject: [PATCH 1/5] fix: logout crash issue

---
 src/components/OnyxProvider.js      | 2 +-
 src/components/createOnyxContext.js | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/components/OnyxProvider.js b/src/components/OnyxProvider.js
index 17868890d672..9ddea6ad0738 100644
--- a/src/components/OnyxProvider.js
+++ b/src/components/OnyxProvider.js
@@ -6,7 +6,7 @@ import ComposeProviders from './ComposeProviders';
 
 // Set up any providers for individual keys. This should only be used in cases where many components will subscribe to
 // the same key (e.g. FlatList renderItem components)
-const [withNetwork, NetworkProvider] = createOnyxContext(ONYXKEYS.NETWORK);
+const [withNetwork, NetworkProvider] = createOnyxContext(ONYXKEYS.NETWORK, {});
 const [withPersonalDetails, PersonalDetailsProvider] = createOnyxContext(ONYXKEYS.PERSONAL_DETAILS);
 const [withCurrentDate, CurrentDateProvider] = createOnyxContext(ONYXKEYS.CURRENT_DATE);
 const [withReportActionsDrafts, ReportActionsDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
diff --git a/src/components/createOnyxContext.js b/src/components/createOnyxContext.js
index a64d17e9c55b..3cde524e3d12 100644
--- a/src/components/createOnyxContext.js
+++ b/src/components/createOnyxContext.js
@@ -9,7 +9,7 @@ const propTypes = {
     children: PropTypes.node.isRequired,
 };
 
-export default (onyxKeyName) => {
+export default (onyxKeyName, defaultValue) => {
     const Context = createContext();
     const Provider = props => (
         <Context.Provider value={props[onyxKeyName]}>
@@ -35,6 +35,11 @@ export default (onyxKeyName) => {
                         ...props,
                         [propName]: transformValue ? transformValue(value, props) : value,
                     };
+
+                    if (propsToPass[propName] === undefined && defaultValue) {
+                        propsToPass[propName] = defaultValue;
+                        //propsToPass[propName] = propsToPass[propName] || {};
+                    }
                     return (
                         // eslint-disable-next-line react/jsx-props-no-spreading
                         <WrappedComponent {...propsToPass} ref={ref} />

From 23d215723c83fd806d11bc5ac8d4aa9f47740e0a Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Tue, 28 Feb 2023 20:12:20 +0700
Subject: [PATCH 2/5] fix: remove comments

---
 src/components/createOnyxContext.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/components/createOnyxContext.js b/src/components/createOnyxContext.js
index 3cde524e3d12..c8452eb9ee83 100644
--- a/src/components/createOnyxContext.js
+++ b/src/components/createOnyxContext.js
@@ -38,7 +38,6 @@ export default (onyxKeyName, defaultValue) => {
 
                     if (propsToPass[propName] === undefined && defaultValue) {
                         propsToPass[propName] = defaultValue;
-                        //propsToPass[propName] = propsToPass[propName] || {};
                     }
                     return (
                         // eslint-disable-next-line react/jsx-props-no-spreading

From c280c3b16a0f252348af707ebf0d9b6940180fc1 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Fri, 24 Mar 2023 18:18:16 +0700
Subject: [PATCH 3/5] fix: unit test

---
 tests/unit/NetworkTest.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/unit/NetworkTest.js b/tests/unit/NetworkTest.js
index 0f4772ad602a..22eb3ded1593 100644
--- a/tests/unit/NetworkTest.js
+++ b/tests/unit/NetworkTest.js
@@ -33,7 +33,6 @@ beforeEach(() => {
     HttpUtils.cancelPendingRequests();
     PersistedRequests.clear();
     NetworkStore.checkRequiredData();
-
     // Wait for any Log command to finish and Onyx to fully clear
     jest.advanceTimersByTime(CONST.NETWORK.PROCESS_REQUEST_DELAY_MS);
     return waitForPromisesToResolve()

From 65cff3d73f785c3e2d01b7903e9c9f30c7641d27 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Mon, 24 Apr 2023 16:22:00 +0700
Subject: [PATCH 4/5] fix: clean code

---
 tests/unit/NetworkTest.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/unit/NetworkTest.js b/tests/unit/NetworkTest.js
index 22eb3ded1593..12a90b72d656 100644
--- a/tests/unit/NetworkTest.js
+++ b/tests/unit/NetworkTest.js
@@ -33,6 +33,7 @@ beforeEach(() => {
     HttpUtils.cancelPendingRequests();
     PersistedRequests.clear();
     NetworkStore.checkRequiredData();
+    
     // Wait for any Log command to finish and Onyx to fully clear
     jest.advanceTimersByTime(CONST.NETWORK.PROCESS_REQUEST_DELAY_MS);
     return waitForPromisesToResolve()

From ab0d56f97331959932af1c5f4312c43ea5d8d812 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Mon, 24 Apr 2023 16:24:11 +0700
Subject: [PATCH 5/5] fix: clean code

---
 tests/unit/NetworkTest.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/NetworkTest.js b/tests/unit/NetworkTest.js
index 12a90b72d656..0f4772ad602a 100644
--- a/tests/unit/NetworkTest.js
+++ b/tests/unit/NetworkTest.js
@@ -33,7 +33,7 @@ beforeEach(() => {
     HttpUtils.cancelPendingRequests();
     PersistedRequests.clear();
     NetworkStore.checkRequiredData();
-    
+
     // Wait for any Log command to finish and Onyx to fully clear
     jest.advanceTimersByTime(CONST.NETWORK.PROCESS_REQUEST_DELAY_MS);
     return waitForPromisesToResolve()
