-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix: use Proxy to track usage of client-side load event.route
#10576
fix: use Proxy to track usage of client-side load event.route
#10576
Conversation
🦋 Changeset detectedLatest commit: 92328ee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Would #6294 be a more permanent solution? |
Oh nice, that would definitely be a great solution. Can we help expedite this? Otherwise I'd appreciate it if we could get this small fix in first to unblock our users and then work on a more general solution (still happy to help out with that!). Thanks :) |
I asked in the maintainer discord and I think we may focus more on solving this with load hooks / opting out of load invalidation tracking. Currently, this workaround would lead to a breaking change, and again when removing it. |
Out of curioisity, how is this PR a breaking change? |
Whoops, I misunderstood the discord chat. Only removing it would lead to a breaking change. |
event.route
event.route
Is there any chance that this will get merged in? The current behaviour is a major blocker for us and for our customers. |
… functions (#9071) This patch fixes a data invalidation issue that appeared on the client side when auto-instrumenting or manually wrapping universal `load` functions. Because our `wrapLoadWithSentry` function accessed `event.route.id`, the data returned from `load` would be invalidated on a route change. As reported in #8818 , this caused prefetched, actually still valid data to be invalidated during the navigation to the page, causing another `load` invocation. To avoid this invalidation, we change the way how we read the route.id, to first use `Object.getOwnPropertyDescriptor` which doesn't trigger the proxy that listens to accesses. This, however, will only work for `@sveltejs/kit>=1.24.0` which includes a [change](sveltejs/kit#10576) to the Kit-internal proxy. For older versions of kit, we continue to directly read from `event.route.id`, which will still cause invalidations. Not ideal but IMO the best we can do without loosing data. closes #8818
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Referenced issues:
handleLoad
hook on client and server hooks #9542 (comment)Background
Our Sentry SvelteKit SDK exposes
wrap(Server)LoadWithSentry
functions that users can manually or with the help of our VIte plugin, automatically wrap around theirload
functions. In these functions we access the load event'sroute.id
value to create a span that tracks the duration of aload
function and what happens inside it (e.g. fetch calls).This is currently problematic because SvelteKit internally tracks accesses to
route.id
by setting a getter (client side) or a Proxy (server side for server only loads). If users themselves don't useroute
but only our wrapper does, they get confused why their loaded data is invalidated on route changes. It's important to note that Sentry doesn't change any behaviour based onroute.id
, we just need to access it to get the name of the current route, nothing more.PR Description
This PR changes the client-side
uses.route
tracking mechanism to use aProxy
instead of directly using a getter. This allows us in Sentry'swrap(Server)LoadWithSentry
functions to useObject.getOwnPropertyDescriptor
to accessevent.route.id
without triggering theuses.route
change. We already did this successfully for the server load wrapper and we'd like to do the same for the client side of universalload
functions. This allows us to record a high-fidelity load span (useful for SvelteKit/our users).I believe correct client-side invalidation based on
route
is already tested but I'm happy to add more tests if reviewers request it.Would be awesome if we could get this merged in! 🙏