fix: guard against undefined global state in createCacheHelper#4224
Open
veeceey wants to merge 1 commit intovercel:mainfrom
Open
fix: guard against undefined global state in createCacheHelper#4224veeceey wants to merge 1 commit intovercel:mainfrom
veeceey wants to merge 1 commit intovercel:mainfrom
Conversation
Author
Test resultsAll existing tests pass: Type checks also pass ( |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
SWRGlobalState.get(cache) can return undefined in React Native New Architecture during initial renders before the provider has been initialized. This causes a crash when accessing state[5] or state[6]. Add a null check so the setter becomes a no-op and the subscriber falls back to a no-op function when global state hasn't been set up yet. Closes vercel#2986
4e80948 to
66b6676
Compare
Author
|
hi, just wondering if this could get a look. let me know if anything needs updating! |
This file contains hidden or 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
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.
When using SWR with React Native's New Architecture (bridgeless mode),
SWRGlobalState.get(cache)can returnundefinedduring early renders before the provider has fully initialized. This causes a crash whencreateCacheHelpertries to destructurestate[5]andstate[6]from the undefined value.This adds a simple null guard:
Tested locally - all existing unit and integration tests still pass.
Closes #2986