-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Svelte Kit fetch requests are repeated again during client hydration #8174
Comments
Hi @janvotava thanks for writing in! Can you share a little more about what is happening, ideally a minimal reproduction where we can clearly see that the SDK is causing this? Based on my understanding of SvelteKit's We're patching SvelteKit's |
Hello @Lms24, thanks for a reply! I have a sample app that fetches a endpoint with a random number. On the client side with loads patched by Sentry And with Basically it skips reusing that Thanks a lot. |
Thanks for the additional information and clarification. Just to confirm, this request is made from a universal
So the question now is, how can we solve this? I see two potential solutions:
I'll need to think about this a bit more but feel free to suggest other options if you have an idea ;) |
I created a reproduction: https://github.com/Lms24/gh-js-8174 This shows the erroneous behavour by default and how disabeling |
One thing to add to this issue: While it is clearly not intended that we cause this cache miss and we should do something about it (we will), the current behaviour of the SDK does not break applications. The reason is that universal load functions need to be built in a way that they can run on both, client and server. |
I opened sveltejs/kit#10009 which would solve this in a clean way. I want to give the Svelte folks a few days to look at this. Maybe we can get it in in which case I'd be more than happy to remove our custom kit fetch instrumentation. Otherwise, we'll have to resort to the brittle cache detection logic in the SDK. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
It seems like Svelte folks aren't too keen on merging my fix so we'll probably need to handle this SDK-side. Will take this on in the near to mid future. |
…mentation (#8391) As outlined in #8174 (comment), our current SvelteKit fetch instrumentation breaks SvelteKit's request caching mechanism. This is problematic as `fetch` requests from universal `load` functions were made again on the client side during hydration although the response was already cached from the initial server-side request. The reason for the cache miss is that in the instrumentation we add our tracing headers to the requests, which lead to a different cache key than the one produced on the server side. This fix vendors in code from [the SvelteKit repo](https://github.com/sveltejs/kit) so that we can perform the same cache lookup in our instrumentation. If the lookup was successful (--> cache hit), we won't attach any headers or create breadcrumbs to 1. let Kit's fetch return the cached response and 2. not add spans for a fetch request that didn't even happen.
hey @Lms24. I've noticed a similar issue with the whole client-side this changed sveltekit's default behaviour in a similar way. for example, we instantiate cache objects inside the load function, and sentry's wrapper effectively breaks caches. let me know if you want me to create a separate ticket for this. |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/sveltekit
SDK Version
7.52.1
Framework Version
1.5.0
Link to Sentry event
No response
SDK Setup
No response
Steps to Reproduce
Expected Result
No request made on the client side.
Actual Result
There is duplicate requests after the client hydration.
The text was updated successfully, but these errors were encountered: