-
-
Notifications
You must be signed in to change notification settings - Fork 963
Delegated events in a Suspense cause resources to refetch on mount (SSR) #2454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you interact with part of the page before it hydrates that we can't trust that it will hydrate properly so remainder of the page is client rendered, which can cause resources to refetch as their sources could be impacted. The id we use for resources is stable not based on the value so we have no way of differentiating if the resource would need to be refetched or if it could use the previously serialized values. |
I see, sorry for the confusion then. In my case, I'm using a toast library called |
so you are concerned about the fetch on the client side when you trigger the event but have you noticed that you are getting double fetch on the server? |
Yeah it's tricky with mouse events. Especially since they are coming from the library and you don't have control over them. Could you mount the toast component after hydration? Like make it visible via a condition set in @mizulu it is more that the event has nothing to do with the data fetching. It fetches once on the server and then it is supposed to use that on the client instead of fetching again (ie first time on the client). Currently it fetches in both places. |
Yeah, that I understood, but is it expected that the server double fetch ? I see the 1st message as soon a request is made |
in regard to the original issue, shouldn't a triggered event, while hydrating cause a refetch only |
I have just tried this approach and realized that it doesn't quite work as I've overlooked other Besides this personal issue with my app, this behavior is very unintuitive, it was a nightmare to figure out why my app sometimes reran all queries and sometimes didn't. Maybe at least add some kind of warning to indicate that these delegated events can cause resources to refetch?
Yes, mizulu, I have noticed this and it is also quite interesting why this happens. However, as I use Tanstack Query, requests get deduped automatically, so I'm not really concerned about it as much. |
@Mrcavas 👍 if solid had a hook for before hydration and restore it when hydration is completed I believe the hydration completion can be detected with this promise it's could have been a fairly simple workaround in the interim, but I don't know how easy it is to patch the code into the workflow perhaps solid can think of better way to handle this |
Right now what I ended up doing is just: // entry-client.tsx
import { sharedConfig } from "solid-js"
function hookDoneFor(obj: any) {
Object.defineProperty(obj, "done", {
get: () => false,
set: () => {},
})
}
hookDoneFor(sharedConfig)
hookDoneFor(window._$HY) As @mizulu suggested, using |
@Mrcavas
then there shouldn't be a gap where the event can be handled. let see if there is more official recommend ways to deal with this. |
I am using https://github.com/solid-component/solid-hot-toast for Toast and adding
|
Describe the bug
When an element with a delegated event handler is present in a Suspense context, firing these events before mount causes all resources to be reran on mount
Your Example Website or App
https://github.com/Mrcavas/solid-delegated-events-bug
Steps to Reproduce the Bug or Issue
Expected behavior
Firing these events shouldn't refetch all resources
Screenshots or Videos
2025-03-21.23-48-14.mp4
Platform
Additional context
I looked around in sources and found that in solid-js/web, eventHandler sets
sharedConfig.done
and_$HY.done
totrue
:Commenting this line out seems to fix refetches, but I don't know what other consequences this change might cause.
The text was updated successfully, but these errors were encountered: