From 377dae70590d90b13704c4177f43843b79a334c0 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 16:47:06 -1000 Subject: [PATCH 1/7] add JS global so guides can enable memory only keys from JS console --- src/setup/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/setup/index.js b/src/setup/index.js index 92a84d45a571..221feeb4ed37 100644 --- a/src/setup/index.js +++ b/src/setup/index.js @@ -42,6 +42,13 @@ export default function () { }, }); + // When enabled we will skip persisting to disk any server-side downloaded objects (e.g. workspaces, chats, etc) that can hog up a user's resources. + window.enableMemoryOnlyKeys = () => Onyx.setMemoryOnlyKeys([ + ONYXKEYS.COLLECTION.REPORT, + ONYXKEYS.COLLECTION.POLICY, + ONYXKEYS.PERSONAL_DETAILS_LIST, + ]); + Device.setDeviceID(); // Force app layout to work left to right because our design does not currently support devices using this mode From 54cc81dddf09240750483b9dc877d0d0956ce58a Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 16:50:38 -1000 Subject: [PATCH 2/7] Make sure that we still call OpenApp if a user has this mode enabled --- src/libs/Navigation/AppNavigator/AuthScreens.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index c2fe7d3475e0..da7229f9c154 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -122,7 +122,9 @@ class AuthScreens extends React.Component { // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). - if (SessionUtils.didUserLogInDuringSession()) { + // Note: There is an experimental Onyx mode that will allow the user to avoid persisting some data entirely - if we have this mode enabled then + // always call OpenApp when the app starts since these users will not be able to rehydrate data they didn't save (outside of memory). + if (Onyx.hasMemoryOnlyKeys() || SessionUtils.didUserLogInDuringSession()) { App.openApp(); } else { App.reconnectApp(); From d4f0fc6c6c5a6b1e2c89d27ea39cf02ed77b6ec6 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 17:19:34 -1000 Subject: [PATCH 3/7] Track state in Onyx instead of the lib --- src/ONYXKEYS.js | 3 +++ .../Navigation/AppNavigator/AuthScreens.js | 7 ++++--- src/setup/index.js | 20 ++++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 823ad7028a94..c3c76ce4e5d3 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -230,4 +230,7 @@ export default { // Report ID of the last report the user viewed as anonymous user LAST_OPENED_PUBLIC_ROOM_ID: 'lastOpenedPublicRoomID', + + // Experimental memory only Onyx mode flag + IS_USING_MEMORY_ONLY_KEYS: 'isUsingMemoryOnlyKeys', }; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index da7229f9c154..7d04c9981277 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -122,9 +122,7 @@ class AuthScreens extends React.Component { // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). - // Note: There is an experimental Onyx mode that will allow the user to avoid persisting some data entirely - if we have this mode enabled then - // always call OpenApp when the app starts since these users will not be able to rehydrate data they didn't save (outside of memory). - if (Onyx.hasMemoryOnlyKeys() || SessionUtils.didUserLogInDuringSession()) { + if (this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession()) { App.openApp(); } else { App.reconnectApp(); @@ -310,5 +308,8 @@ export default compose( lastOpenedPublicRoomID: { key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, }, + isUsingMemoryOnlyKeys: { + key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, + } }), )(AuthScreens); diff --git a/src/setup/index.js b/src/setup/index.js index 221feeb4ed37..5b079b0e0ea7 100644 --- a/src/setup/index.js +++ b/src/setup/index.js @@ -43,11 +43,21 @@ export default function () { }); // When enabled we will skip persisting to disk any server-side downloaded objects (e.g. workspaces, chats, etc) that can hog up a user's resources. - window.enableMemoryOnlyKeys = () => Onyx.setMemoryOnlyKeys([ - ONYXKEYS.COLLECTION.REPORT, - ONYXKEYS.COLLECTION.POLICY, - ONYXKEYS.PERSONAL_DETAILS_LIST, - ]); + window.enableMemoryOnlyKeys = () => { + // eslint-disable-next-line rulesdir/prefer-actions-set-data + Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); + Onyx.setMemoryOnlyKeys([ + ONYXKEYS.COLLECTION.REPORT, + ONYXKEYS.COLLECTION.POLICY, + ONYXKEYS.PERSONAL_DETAILS_LIST, + ]); + }; + + window.disableMemoryOnlyKeys = () => { + // eslint-disable-next-line rulesdir/prefer-actions-set-data + Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); + Onyx.setMemoryOnlyKeys([]); + } Device.setDeviceID(); From d01eb237116a8832cf95337932474f394e5cc99e Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 17:30:16 -1000 Subject: [PATCH 4/7] fix style --- src/libs/Navigation/AppNavigator/AuthScreens.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 7d04c9981277..0b1abe63f0ed 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -91,10 +91,14 @@ const propTypes = { /** The report ID of the last opened public room as anonymous user */ lastOpenedPublicRoomID: PropTypes.string, + /** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */ + isUsingMemoryOnlyKeys: PropTypes.bool, + ...windowDimensionsPropTypes, }; const defaultProps = { + isUsingMemoryOnlyKeys: false, session: { email: null, }, From 61b079ca435c754d60c007637220f3ab037a84ca Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 17:36:32 -1000 Subject: [PATCH 5/7] Try to explain this weird situation a bit better --- src/libs/Navigation/AppNavigator/AuthScreens.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 0b1abe63f0ed..336e04c42033 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -126,6 +126,9 @@ class AuthScreens extends React.Component { // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). + // Note: If a Guide has enabled the memory only key mode then we do want to run OpenApp as their app will not be rehydrated with + // the correct state on refresh. They are explicitly opting out of storing data they would need (i.e. reports_) to take advantage of + // the optimizations performed during ReconnectApp. if (this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession()) { App.openApp(); } else { From 12607ca8f67be96bd985acb8eecb8a4a02818fca Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 17:42:08 -1000 Subject: [PATCH 6/7] prettier --- src/libs/Navigation/AppNavigator/AuthScreens.js | 2 +- src/setup/index.js | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 336e04c42033..6c5ca155f6b7 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -317,6 +317,6 @@ export default compose( }, isUsingMemoryOnlyKeys: { key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, - } + }, }), )(AuthScreens); diff --git a/src/setup/index.js b/src/setup/index.js index 5b079b0e0ea7..dee506302e81 100644 --- a/src/setup/index.js +++ b/src/setup/index.js @@ -46,18 +46,14 @@ export default function () { window.enableMemoryOnlyKeys = () => { // eslint-disable-next-line rulesdir/prefer-actions-set-data Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); - Onyx.setMemoryOnlyKeys([ - ONYXKEYS.COLLECTION.REPORT, - ONYXKEYS.COLLECTION.POLICY, - ONYXKEYS.PERSONAL_DETAILS_LIST, - ]); + Onyx.setMemoryOnlyKeys([ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]); }; window.disableMemoryOnlyKeys = () => { // eslint-disable-next-line rulesdir/prefer-actions-set-data Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); Onyx.setMemoryOnlyKeys([]); - } + }; Device.setDeviceID(); From f8e8610e776c9531c4e58c683682f0e828cf76e6 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 11 Jul 2023 17:54:09 -1000 Subject: [PATCH 7/7] Bump Onyx --- package-lock.json | 15 +++++++-------- package.json | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8fe8a0accd0a..a58d7c308826 100644 --- a/package-lock.json +++ b/package-lock.json @@ -77,7 +77,7 @@ "react-native-key-command": "^1.0.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "1.0.43", + "react-native-onyx": "1.0.50", "react-native-pdf": "^6.6.2", "react-native-performance": "^4.0.0", "react-native-permissions": "^3.0.1", @@ -36787,9 +36787,9 @@ } }, "node_modules/react-native-onyx": { - "version": "1.0.43", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-1.0.43.tgz", - "integrity": "sha512-NwS1SxZJWhk/7FUAAE9HrnupQR1yrSAheuhggdeA3+oFLn9X6UJM7n7w9DodFqCQbUIUy9biKtYk29sChfk9hQ==", + "version": "1.0.50", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-1.0.50.tgz", + "integrity": "sha512-tBqJRUBb2M/giIgqf2V0kw1jMr2iAW64CpgtWJbETv1ihOitP6+YAJpqoPIB0SGSFByfgTYY4k/KSVZBgcynMg==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", @@ -36801,7 +36801,6 @@ "npm": "8.11.0" }, "peerDependencies": { - "expensify-common": ">=1", "localforage": "^1.10.0", "localforage-removeitems": "^1.4.0", "react": ">=18.1.0", @@ -68550,9 +68549,9 @@ } }, "react-native-onyx": { - "version": "1.0.43", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-1.0.43.tgz", - "integrity": "sha512-NwS1SxZJWhk/7FUAAE9HrnupQR1yrSAheuhggdeA3+oFLn9X6UJM7n7w9DodFqCQbUIUy9biKtYk29sChfk9hQ==", + "version": "1.0.50", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-1.0.50.tgz", + "integrity": "sha512-tBqJRUBb2M/giIgqf2V0kw1jMr2iAW64CpgtWJbETv1ihOitP6+YAJpqoPIB0SGSFByfgTYY4k/KSVZBgcynMg==", "requires": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index 92086a9f2173..77495586e16e 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ "react-native-key-command": "^1.0.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "1.0.43", + "react-native-onyx": "1.0.50", "react-native-pdf": "^6.6.2", "react-native-performance": "^4.0.0", "react-native-permissions": "^3.0.1",