diff --git a/.changeset/sharp-pigs-study.md b/.changeset/sharp-pigs-study.md new file mode 100644 index 000000000000..456493f60794 --- /dev/null +++ b/.changeset/sharp-pigs-study.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Hydrate initial page before starting router diff --git a/packages/kit/src/runtime/client/renderer.js b/packages/kit/src/runtime/client/renderer.js index 7cbb0536bcfc..9b11ca91f2f3 100644 --- a/packages/kit/src/runtime/client/renderer.js +++ b/packages/kit/src/runtime/client/renderer.js @@ -134,7 +134,10 @@ export class Renderer { const hydrated = await this._hydrate(selected); if (hydrated.redirect) { - throw new Error('TODO client-side redirects'); + // this is a real edge case — `load` would need to return + // a redirect but only in the browser + location.href = new URL(hydrated.redirect, location.href).href; + return; } Object.assign(props, hydrated.props); diff --git a/packages/kit/src/runtime/client/start.js b/packages/kit/src/runtime/client/start.js index ca15f5a539ee..3121085b7c44 100644 --- a/packages/kit/src/runtime/client/start.js +++ b/packages/kit/src/runtime/client/start.js @@ -36,8 +36,8 @@ export async function start({ paths, target, session, error, status, nodes, page init({ router, renderer }); set_paths(paths); - router.init(renderer); await renderer.start({ nodes, page }, status, error); + router.init(renderer); dispatchEvent(new CustomEvent('sveltekit:start')); }