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

uswSWRImmutable Fails To Do Initial Fetch If There's Fallback Data #3061

Closed
JordanHoffman opened this issue Dec 27, 2024 · 1 comment
Closed

Comments

@JordanHoffman
Copy link

Bug report

Description / Observed Behavior

My goal is to have some state which does an initial fetch, and then I'll manually control refetches from that point on. I'd also like to give it an initial value (in this case an empty array) rather the it be undefined, so I combined useSWRImmutable with a fallback option in hopes of achieving this. Unfortunately it failed to fetch entirely, and it seems it was pointed out in another thread that fallback data is treated as stale data and therefore prevents revalidation... But it doesn't seem right to even prevent an initial fetch. I just feel like that kinda defeats the purpose of anything if that's what happens in this scenario.

Expected Behavior

I expected there to still be an initial fetch.

Repro Steps / Code Example

Here's some code that had the fallback data. It triggered no initial fetch.
image

The moment I removed it, I can do an initial fetch, but lose out on default data. Perhaps in this scenario I could just put in a default value for data... but I feel like that's not proper and could lead to confusion if future values actually expected to be undefined.

image

Additional Context

SWR version: 2.3.0

@JordanHoffman
Copy link
Author

JordanHoffman commented Jan 2, 2025

I'm choosing to close this issue. I realize that there are scenarios where I actually WOULD like useSWRImmutable to never even do an initial fetch. So I think the way it is right now gives the most flexibility and is preferable:

  • If I want the initial fetch, I'll just have a default value for the data.
  • If I dont want an initial fetch but still want a default value, then I'll use the fallback data.

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