fix: useSWRImmutable should disable revalidation on focus#4232
Open
buyuan-dev wants to merge 1 commit intovercel:mainfrom
Open
fix: useSWRImmutable should disable revalidation on focus#4232buyuan-dev wants to merge 1 commit intovercel:mainfrom
buyuan-dev wants to merge 1 commit intovercel:mainfrom
Conversation
Fixes vercel#4225 useSWRImmutable is documented to disable all automatic revalidation, but revalidateOnFocus was not being set to false by default. Changed the immutable middleware to create a new config object with explicit overrides instead of mutating the config, ensuring: - revalidateOnFocus - revalidateIfStale - revalidateOnReconnect - refreshInterval are all properly disabled.
|
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. |
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.
Summary
Fixes a bug where useSWRImmutable was not properly disabling revalidation on window focus.
Problem
useSWRImmutable is documented to disable all automatic revalidation, but when the window loses and regains focus, the fetcher was being called again.
Root Cause
The immutable middleware was mutating the config object directly, which could be overridden by merged configs.
Fix
Updated the immutable middleware to create a new config object with explicit overrides, ensuring all revalidation flags are properly disabled:
evalidateOnFocus
n- evalidateIfStalen-evalidateOnReconnect
n- efreshIntervalnTesting
Fixes #4225