Skip to content

Commit

Permalink
hydrate initial page before starting router (#654)
Browse files Browse the repository at this point in the history
* hydrate initial page before starting router - fixes #652

* changeset
  • Loading branch information
Rich Harris authored Mar 25, 2021
1 parent 9576137 commit d5071c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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

1 comment on commit d5071c5

@vercel
Copy link

@vercel vercel bot commented on d5071c5 Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.