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", 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 c2fe7d3475e0..6c5ca155f6b7 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, }, @@ -122,7 +126,10 @@ 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: 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 { App.reconnectApp(); @@ -308,5 +315,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 92a84d45a571..dee506302e81 100644 --- a/src/setup/index.js +++ b/src/setup/index.js @@ -42,6 +42,19 @@ 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 = () => { + // 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(); // Force app layout to work left to right because our design does not currently support devices using this mode