LF-5103: Frontload data that is currently loaded on demand #4007
+32
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
useGoogleMapsLoaderinApp.jsxto ensure maps can render offline without requiring an initial online visit to the map pagee.responsein finances saga (I believe this was the cause of infinite loading on the transactions page)fieldWorkFailureandfieldWorkLoadingreducers to avoid resettingfieldWorkTypesto[], which was preventing field work types from being available offlinefetchAllSagafor offline task creation and read-only views:keepUnusedDataFor: 7 daysrefetchOnMountOrArgChange: 60 secondsRTK Query Cache Configuration
Why change the defaults?
With RTK Query's default settings, cached data expires 60 seconds after the component using it unmounts. For example, if you visit the animals page, go offline, navigate away, and return after 60 seconds, the cached data will be gone and you won't see any data while offline. To support offline functionality, we need to adjust the cache configuration.
New Configuration
keepUnusedDataFor: 7 days (docs)refetchOnMountOrArgChange: 60 seconds (docs)Impact
Example scenario: You visit the animals page, stay for an hour, navigate away, then immediately return.
This configuration is applied globally at the API level rather than per-endpoint. This approach:
Note:
With
refetchOnReconnect: true(docs) , queries should automatically refetch when going back online, but I wasn't able to test this successfully. Claude says there are known bugs with this feature in our@reduxjs/toolkitversion, which might be the cause. (The newer version have breaking changes. I created a ticket for the upgrade)The app should work fine without this feature due to the cache configuration, but I'm documenting this for future reference in case we need automatic refetching on reconnection.
Jira link: https://lite-farm.atlassian.net/browse/LF-5103
Type of change
How Has This Been Tested?
Checklist:
pnpm i18nto help with this)