Skip to content

Commit

Permalink
fix: better error message when calling push/replaceState before route…
Browse files Browse the repository at this point in the history
…r is initialized (#11968)

closes #11466
  • Loading branch information
PatrickG authored Sep 27, 2024
1 parent b74d796 commit e9ed772
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-ravens-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: better error message when calling push/replaceState before router is initialized
8 changes: 8 additions & 0 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,10 @@ export function pushState(url, state) {
}

if (DEV) {
if (!started) {
throw new Error('Cannot call pushState(...) before router is initialized');
}

try {
// use `devalue.stringify` as a convenient way to ensure we exclude values that can't be properly rehydrated, such as custom class instances
devalue.stringify(state);
Expand Down Expand Up @@ -1893,6 +1897,10 @@ export function replaceState(url, state) {
}

if (DEV) {
if (!started) {
throw new Error('Cannot call replaceState(...) before router is initialized');
}

try {
// use `devalue.stringify` as a convenient way to ensure we exclude values that can't be properly rehydrated, such as custom class instances
devalue.stringify(state);
Expand Down

0 comments on commit e9ed772

Please sign in to comment.