Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make providing fallback data for useSWRSubscription more intuitive #4094

Open
NeutronicMC opened this issue Feb 15, 2025 · 0 comments
Open

Comments

@NeutronicMC
Copy link

NeutronicMC commented Feb 15, 2025

Bug report

Description / Observed Behavior

I was trying to provide fallback data to the useSWRSubscription hook, but no matter what I tried it would not use it. After looking through the source code, I realized that there is a constant SUBSCRIPTION_PREFIX that is prepended to any key provided. This isn't documented or clear to users of the library, and makes fallback data appear to not be available at all at first glance.

Expected Behavior

Make it clear in the documentation how normal SWR keys and subscription SWR keys are differentiated, and maybe provide a more ergonomic/future proof method of providing data to subscriptions. If useSWRSubscription is still experimental like the codebase comments say, it might be good to include this in the documentation as well.

Repro Steps / Code Example

useSWRSubscription<string>(
    "example",
    () => () => null,
    {
      fallback: {
        $sub$example: "this data is used",
        example: "this data is not used",
      },
    },
  );

Additional Context

SWR v2.3.2, Next.js v15.2.0-canary.56

For those of you in search of a quick fix:
Append $sub$ to the beginning of each fallback key that needs to be accessed by a SWR subscription.

@NeutronicMC NeutronicMC changed the title Make providing fallback data for useSWRSubscription more intuitive Make providing fallback data for useSWRSubscription more intuitive Feb 15, 2025
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

No branches or pull requests

1 participant