How to efficiently handle data fetching and state updates in Svelte 5 forms using the stale-while-revalidate approach too #8540
Unanswered
frederikhors
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I thought the createQuery would not react to Also, for your question, is there potential to use the 'initialData' property to use cached/stale data as the starting point? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have these files. This is real code from a real project.
If I go to
/players/new
in Svelte Kit I get a form. But before creating a form I need to get some data.In the example below I'm creating a new
formPlayer
but I needdefaultCoachId
andteam?.coachId
:I can get them both from browser cache (if any) and from server using the "stale-while-revalidate" approach:
But this needs to be handled. Right now the code below does not handle it because the response that the server returns is not used in
Form.svelte
:and this is really bad because sometimes the in memory or the browser cache does not already contain the data or contains stale data.
Can you suggest a way to handle this efficiently with Svelte 5?
Should I use an
$effect
like:I think this is ugly and I get a warning too for both
defaultCoachId
andteam
:I think this is a real use case, can you advise me the best way to solve it?
Complete code
I opened sveltejs/svelte#15026 but this is useful here too.
Beta Was this translation helpful? Give feedback.
All reactions