Comments (12)
Unfortunately I don't have a replication at the moment, but the error might have to do with the fact that onMount
is called in the constructor? If useSWR
is reactively called behind a $:
in the dependent fetching scenario, then it would be rerun later in the component lifecycle after the mount has already happened.
from sswr.
A lot of people seem to be getting this as well. Will investigate.
from sswr.
@ConsoleTVs was this ever fixed? i feel like i'm seeing the error and before i dig deeper wanted to check if maybe its still outstanding issue
from sswr.
It might be. I am in the process of updating the underlying library of both, sswr and vswr. Althought this seems to be related to svelte itself, this library is around 70 LOC specific svelte code. It should not be hard to spot either if you want to help!
Also, could somebody post a replication code on codesandox?
from sswr.
i might have some time today to dig into this. though im in the early stages of learning svelte, most of my framework knowledge is react, 🤷 doesnt hurt to try
from sswr.
dropped in
beforeUpdate(() => {
console.log('key', key, this.resolveKey(key), options);
this.use<D, E>(key, onData, onError, {
loadInitialCache: true,
...options,
})
});
and moved onData and on Error to be outside of on mount. The good news is that the fetching is now fixed. the problem is we are creating waaay to many subscriptions... so just need to find the underlying refetch for this.use that i can use on the existing subscription
from sswr.
ok removed my changes and replace onMount with beforeUpdate and added an if condition to check if the subscription has been created. @ekzhang was right the onMount is happening too early
beforeUpdate(() => {
// Handlers that will be executed when data changes.
// Subscribe and use the SWR fetch using the given key.
if (!unsubscribe)
unsubscribe = this.use<D, E>(key, onData, onError, {
loadInitialCache: true,
...options,
}).unsubscribe
})
I'll create a PR for the above change but I'm not a huge fan of it since it seems hacky. Going to also do some extra testing as well to make sure it doesn't have some weird side effects
from sswr.
Still doesn't work ... 😢
from sswr.
@eytanProxi can you manually test this branch? If it works I can merge it: #33
from sswr.
@ConsoleTVs : I tried the fix but the bug is still here.
Should we move to TurboQuery
?
from sswr.
I have no idea how to fix that. You can give turbo query a shot, it is basically using Promises. Should be easy to create a small adapter. I am pushing turbo query beyond with vue and specially solidjs as a replacement for this...
from sswr.
@ConsoleTVs are you referring to https://github.com/StudioLambda/TurboQuery?
from sswr.
Related Issues (20)
- `data` is `undefined` using reactive query HOT 8
- Expose a method to get the cache? HOT 20
- Do we really need `isValid`? HOT 7
- Support synchronous `fetcher` function HOT 3
- `fetcher` is sometimes ignored and it uses the default `fetch` HOT 1
- If `fetcher` returns `null` the revalidation is ignored HOT 1
- make revalidate() fires immediately? HOT 4
- Add `isValidating` prop HOT 1
- revalidateOnMount missing? HOT 2
- Server side rendering SvelteKit example does not work
- SvelteKit - Named export 'SWR' not found HOT 3
- [HELP] Error: Function called outside component initialization
- Add option for polling interval
- Posible vite4 incompatibility HOT 2
- Multiple SWRs in one component keep resetting each other
- Dependent fetching doesn't revalidate when changing to an already cached value
- Svelte 4 support HOT 2
- Difference to @tanstack/svelte-query HOT 1
- Documentation typo: Global configuration options HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sswr.