fix: ignore third-party monkeypatches in pushState/replaceState warning #15267
+8
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When third-party libraries like Sentry SDK monkeypatch
history.pushStateandhistory.replaceState, they insert additional stack frames. The dev-mode warning that checks if these methods are called from outside SvelteKit relies on stack trace inspection, but the extra frames from monkeypatching libraries cause false positives — the warning fires even for SvelteKit's own internal calls.This PR filters out stack frames originating from
node_modulesbefore checking the call origin, so that monkeypatching libraries (Sentry, analytics tools, etc.) no longer trigger the false positive warning.Before
Any library in
node_modulesthat wrapshistory.pushState/replaceState(like@sentry/svelte) would cause the following false warning on every SvelteKit navigation:After
Stack frames from
node_modulesare filtered out before the origin check, so SvelteKit correctly identifies its own internal calls regardless of how many third-party wrappers are in the call chain.How it works
The stack trace for SvelteKit's internal
pushStatecall with Sentry looks like:After
slice(2), the first frame is Sentry's — notclient.js— triggering the false warning. By filteringnode_modulesframes, the first remaining frame is correctly identified asclient.js.Closes #12177
Test plan