-
Notifications
You must be signed in to change notification settings - Fork 96
LF-5103: Frontload data that is currently loaded on demand #4007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LF-5103: Frontload data that is currently loaded on demand #4007
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh WOW, it's such a delight to see such effective changes in 32 lines!! 😋😍
I love the new cache settings; much better default without the data getting any more stale 👌
Add null check for e.response in finances saga (I believe this was the cause of infinite loading on the transactions page)
❤️
| }, | ||
| fieldWorkFailure: (state, action) => { | ||
| state.loading = true; | ||
| state.fieldWorkTypes = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something, or shouldn't this whole slice be named for types, like fieldWorkTypesSlice, fieldWorkTypesFailure? 😅
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)