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

hydrate initial page before starting router #654

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/sharp-pigs-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Hydrate initial page before starting router
5 changes: 4 additions & 1 deletion packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down