fix: ignore third-party monkeypatches in pushState/replaceState warning#15267
Open
FrankFMY wants to merge 1 commit intosveltejs:mainfrom
Open
fix: ignore third-party monkeypatches in pushState/replaceState warning#15267FrankFMY wants to merge 1 commit intosveltejs:mainfrom
FrankFMY wants to merge 1 commit intosveltejs:mainfrom
Conversation
When third-party libraries like Sentry monkeypatch history.pushState and history.replaceState, they add extra stack frames. This causes the dev-mode warning to incorrectly fire for SvelteKit's own internal calls. Filter out stack frames from node_modules before checking the call origin, so that monkeypatching libraries don't trigger false positives. Closes sveltejs#12177
🦋 Changeset detectedLatest commit: dfb77be 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 |
dummdidumm
approved these changes
Feb 6, 2026
Member
dummdidumm
left a comment
There was a problem hiding this comment.
Fix is good enough for me (I mean I originally proposed it), the possibility that something in node_modules initiated history.push is slim - but wanna get some other maintainer opinions here before merging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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