Skip to content

useSWRImmutable ignores hook-level refreshInterval since 2.4.0 (regression of #4208) #4322

Description

@lukasvice

Bug report

Description / Observed Behavior

Since v2.4.0, useSWRImmutable ignores a refreshInterval passed directly to the hook, not just one inherited from a global <SWRConfig>.

#4208 ("fix: Ensure useSWRImmutable overrides global refreshInterval") added this line to the immutable middleware:

config.refreshInterval = 0

However, middleware runs after the hook-level options have been merged with the context config.

At that point the middleware cannot distinguish a globally configured refreshInterval from one passed as hook options, so it silently disables both. Polling that worked on ≤ 2.3.x stops with no error or warning after upgrading.

Expected Behavior

A refreshInterval passed directly to useSWRImmutable(key, fetcher, { refreshInterval }) should still be honored — only a refreshInterval inherited from a parent <SWRConfig> (the case #4208 was about) should be ignored.

If ignoring the hook-level option is intentional, it would be worth documenting as a breaking change, since it silently changes runtime behavior in a minor release.

Repro Steps / Code Example

import useSWRImmutable from 'swr/immutable'

function Status() {
  // On swr 2.3.6: fetches every second.
  // On swr >= 2.4.0: fetches exactly once, refreshInterval is discarded.
  const { data } = useSWRImmutable('/api/status', fetcher, {
    refreshInterval: 1000,
  })

  return <span>{data?.status}</span>
}

No global <SWRConfig> is involved.

https://codesandbox.io/p/sandbox/thqfwl

Additional Context

SWR version: 2.5.0 (regression introduced in 2.4.0 via #4208; 2.3.6 behaves as expected).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions