-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
When a resource is created outside of the <Suspense> boundary that wraps its data access, the first such resource will not have related onCleanup functions triggered on the server (only the first resource created this way).
Kind of nuanced, and there seems to be some other strange but related behavior at play here as well. Easier to show with some examples.
Here's our resource helper - it just creates and returns a new resource, and registers an onCleanup function:
A DataComp component that does not include it's own suspense boundary:
A DataCompWithInnerSuspense component that DOES wrap access to the resource data in its own suspense boundary:
Scenarios
Render a single DataCompWithInnerSuspense
<DataCompWithInnerSuspense name="DataCompWithInnerSuspense-1" />Resulting server logs
Note no onCleanup.
call:DataCompWithInnerSuspense-1
call:DataCompWithInnerSuspense-1.resourceRender more than one DataCompWithInnerSuspense
<DataCompWithInnerSuspense name="DataCompWithInnerSuspense-1" />
<DataCompWithInnerSuspense name="DataCompWithInnerSuspense-2" />Resulting server logs
Note the second comp did have it's onCleanup triggered.
call:DataCompWithInnerSuspense-1
call:DataCompWithInnerSuspense-1.resource
call:DataCompWithInnerSuspense-2
call:DataCompWithInnerSuspense-2.resource
onCleanup:DataCompWithInnerSuspense-2.resource
onCleanup:DataCompWithInnerSuspense-2Render DataComp + one or more DataCompWithInnerSuspense
<Suspense>
<DataComp name="DataComp-1" />
</Suspense>
<DataCompWithInnerSuspense name="DataCompWithInnerSuspense-1" />Resulting server logs
In this case onCleanup IS called for DataCompWithInnerSuspense-1.
Note however that there might be some other weirdness, not sure why the the DataComp logs are triggered again at the end (last 4 lines).
call:DataComp-1
call:DataComp-1.resource
call:DataCompWithInnerSuspense-1
call:DataCompWithInnerSuspense-1.resource
onCleanup:DataComp-1.resource
onCleanup:DataComp-1
onCleanup:DataCompWithInnerSuspense-1.resource
onCleanup:DataCompWithInnerSuspense-1
call:DataComp-1
call:DataComp-1.resource
onCleanup:DataComp-1.resource
onCleanup:DataComp-1Your Example Website or App
Steps to Reproduce the Bug or Issue
- Clone https://github.com/marbemac/solid-oncleanup-ssr-bug.
pnpm installpnpm dev- Load http://127.0.0.1:3001
- Adjust the components rendered to mess around with the various scenarios described in this issue (https://github.com/marbemac/solid-oncleanup-ssr-bug/blob/main/src/routes/index.tsx#L11-L18)
- Reload the page, view server-side logs in terminal
Expected behavior
onCleanup is called consistently.
Screenshots or Videos
No response
Platform
- OS: na
- Browser: na
- Version: 1.6.12
Additional context
Originally ran into this behavior while trying to debug an issue in @tanstack/solid-query. onCleanup is used there to unsubscribe various observables, and the fact that it is not called consistently when on the server is causing problems.