Skip to content
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: prevent false positive history.pushState warnings #11858

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-kangaroos-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: prevent false positive `history.pushState` and `history.replaceState` warnings
4 changes: 3 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const snapshots = storage.get(SNAPSHOT_KEY) ?? {};
if (DEV && BROWSER) {
let warned = false;

const current_module_url = import.meta.url.split('?')[0]; // remove query params that vite adds to the URL when it is loaded from node_modules

const warn = () => {
if (warned) return;

Expand All @@ -76,7 +78,7 @@ if (DEV && BROWSER) {
if (!stack) return;
if (!stack[0].includes('https:') && !stack[0].includes('http:')) stack = stack.slice(1); // Chrome includes the error message in the stack
stack = stack.slice(2); // remove `warn` and the place where `warn` was called
if (stack[0].includes(import.meta.url)) return;
if (stack[0]?.includes(current_module_url)) return;
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved

warned = true;

Expand Down