Skip to content

fix: useSWRImmutable should disable revalidation on focus#4232

Open
buyuan-dev wants to merge 1 commit intovercel:mainfrom
buyuan-dev:fix/issue-4225
Open

fix: useSWRImmutable should disable revalidation on focus#4232
buyuan-dev wants to merge 1 commit intovercel:mainfrom
buyuan-dev:fix/issue-4225

Conversation

@buyuan-dev
Copy link

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:

evalidateOnFocusn- evalidateIfStalen-
evalidateOnReconnectn- efreshIntervaln

Testing

  • All existing tests pass
  • Manual testing shows no revalidation on focus

Fixes #4225

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.
@codesandbox-ci
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected fetcher call on focus when using useSWRImmutable

1 participant