createResource refetch causes full page refresh
I'm using SolidStart, dabbling for the first time with data fetching using Solid, apologies in advance for any simple misunderstandings.
I've got an API route giving me a list of projects which I've put into a resource in the following manner:
The fetching function itself is as follows
When manually triggering
refetchProjects()
in an onClick
the entire page flashes white in what seems like a full page reload. Any ideas as to what I'm doing wrong? Are resources the wrong solution?6 Replies
Try wrapping that part of the component tree in a
Suspense
When the resource gets refetched, it triggers the closest suspense boundary, which is probably high up your component tree. When it gets retriggered, it tries to render the fallback - removing the DOM nodes below it, which are then rerendered when the resource resolvesMakes sense! Should I wrap the entire component, the part which triggers the refetch or the part which depends on the resource?
You should only need to wrap the part where the resource is accessed in the JSX
And you can add a custom fallback for it, if you wanted to display a loading spinner
That worked like a charm, thank you!
Awesome :)
Once you've sorted out the Suspense boundary you can also wrap refetchProject in startTransition is you wanted to avoid the fallback and use a more softer inline clue for reloading via isPending - useTransition will hand you both isPending accessor and start Transition