-
Notifications
You must be signed in to change notification settings - Fork 439
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
refactor(store) simplify key value store, add SWR through localStorage #7554
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Sep 27, 2024 2:11 PM (UTC) ✅ All Tests Passed -- expand for details
|
cngonzalez
approved these changes
Sep 27, 2024
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.
LGTM, at least for the initial implementations of this feature!
pedrobonamin
approved these changes
Sep 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
While working on a list view optimization I discovered an re-rendering/re-fetching issue that was caused by the key value store first emitting the default value for sort order, and then fetching it from the server. In cases where a user has set a custom sort order, this would always result in two distinct settings to be returned from
useStructureToolSetting('<someKey>')
, which again would always trigger an extra re-render, and in the case of list views: a re-fetch.This PR refactors the internals of the key value store to facilitate using LocalStorage as a read-through cache for user settings, and opting for a Stale-While-Revalidate (SWR) approach by first returning what's in local storage, and then fetching the latest settings value from the server, updating the local storage in case of a change. In the majority of cases, the localstorage value will match what's stored on the server, and in these cases we wont trigger any re-fetch/rerenders.
What to review
These are for the most part internal changes, and I took the opportuinity to simplify where I felt it made sense. There might be, however a change in behavior in certain cases in that subscribers of user settings keys now immediately will get a cached value instead of the default value. Let me know if you can think of cases where this can be problematic (I couldn't think of any)
Testing
Notes for release
n/a - internal