You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
NeutronicMC
changed the title
Make providing fallback data for useSWRSubscription more intuitive
Make providing fallback data for useSWRSubscription more intuitive
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
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.The text was updated successfully, but these errors were encountered: