Skip to content

Unexpected revalidateIfStale = false initial load behavior on key change #2930

@sheern

Description

@sheern

Bug report

Description / Observed Behavior

In my usage of the useSWRImmutable hook, my component has a dynamic key as state. Upon an update to this key, I expected an immediate isLoading == true (assuming that the key is brand new) as there's no cached data associated with it. Instead, there's a split second where isLoading is false before loading as normal. I've narrowed this down to the revalidateIfStale option.

Expected Behavior

When revalidateIfStale is false, the first time a key is encountered should immediately set isLoading to true as there's no stale data.

Repro Steps / Code Example

Here's a CodeSandbox of the issue. You can see the unexpected state logged in the console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions