Skip to content

fix: Ensure useSWRImmutable overrides global refreshInterval#4208

Merged
shuding merged 3 commits intovercel:mainfrom
CODEAbhinav-art:fix/issue-4207-immutable-refresh
Jan 19, 2026
Merged

fix: Ensure useSWRImmutable overrides global refreshInterval#4208
shuding merged 3 commits intovercel:mainfrom
CODEAbhinav-art:fix/issue-4207-immutable-refresh

Conversation

@CODEAbhinav-art
Copy link
Copy Markdown
Contributor

Description

Fixes #4207

The Bug:
Previously, useSWRImmutable did not explicitly disable refreshInterval. If a user set a global refreshInterval in SWRConfig, the immutable hook would inherit this configuration and revalidate repeatedly, violating the "immutable" behavior.

The Fix:
I updated the immutable middleware to explicitly enforce refreshInterval = 0. This ensures that even if a global polling interval is set, useSWRImmutable will correctly ignore it.

Verification

I added a reproduction test case in test/issue-4207.test.tsx.

  • Before Fix: The test fails (fetches repeat despite useSWRImmutable).
  • After Fix: The test passes (fetches only once).

Ran full test suite (pnpm test) to ensure no regressions.

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jan 9, 2026

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.

@shuding
Copy link
Copy Markdown
Member

shuding commented Jan 10, 2026

Makes sense but could you remove the comment and put the test inside the immutable test suite? Thanks.

@CODEAbhinav-art
Copy link
Copy Markdown
Contributor Author

@shuding Thanks for the review!

Removed the inline comments in the source code.

Moved the reproduction test case into the main suite (test/use-swr-immutable.test.tsx).

Deleted the standalone test file.

Verified all tests pass locally.

Ready for re-evaluation!

@shuding shuding changed the title fix: ensure useSWRImmutable overrides global refreshInterval fix: Ensure useSWRImmutable overrides global refreshInterval Jan 19, 2026
@shuding shuding merged commit de1dc5a into vercel:main Jan 19, 2026
6 checks passed
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.

When using useSWRImmutable, there were multiple repeated requests to the interface during the global configuration of refreshIntervall

2 participants