S
SolidJS3mo ago
krulod

refetch failed resources whenever their sources change?

here's a playground: https://playground.solidjs.com/anonymous/df720f20-833b-420d-af40-f1dc385ceb69 i wrapped the component that imitates data fetching in ErrorBoundary and want the boundary to automatically reset whenever a resource that failed is invalidated
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
4 Replies
Madaxen86
Madaxen863mo ago
How do you intend to invalidate the resource?
krulod
krulodOP3mo ago
by updating its source signal
Madaxen86
Madaxen863mo ago
When it errors and the error boundary renders the fallback. The component which has the error and includes createResource is not present. ErrorBoundarie’s fallback provides a reset function with which you can use to try to redender the children with errors.
<ErrorBoundary
fallback={(err, reset) => <div onClick={reset}>Error: {err.toString()}</div>}
>
<MyComp />
</ErrorBoundary>
<ErrorBoundary
fallback={(err, reset) => <div onClick={reset}>Error: {err.toString()}</div>}
>
<MyComp />
</ErrorBoundary>
So you could add a createEffect in the ErrorBoundary that picks up the source signal and then calls reset. As long as the source signal lives outside of the ErrorBoundary
krulod
krulodOP3mo ago
thanks for your help. to be honest, I'm not pleased with the solution, but couldn't come up with anything better except for wrapping the boundary in a keyed Show which looks less messy, but still requires to manually specify resources that are used inside
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Want results from more Discord servers?
Add your server