How to efficiently handle data fetching and state updates in Svelte 5 forms using the stale-while-revalidate approach too #15026
Unanswered
frederikhors
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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 don't know how to reproduce it on the playground, as soon as I find out I'll create it
Beta Was this translation helpful? Give feedback.
All reactions