Skip to content

Commit

Permalink
skip hydrate if ssr: false (#12050)
Browse files Browse the repository at this point in the history
* skip hydrate if ssr: false

* changeset
  • Loading branch information
Rich-Harris committed Mar 28, 2024
1 parent f685af9 commit f1a2133
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-otters-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only hydrate when page is server-rendered
9 changes: 5 additions & 4 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,9 @@ async function _preload_code(pathname) {
/**
* @param {import('./types.js').NavigationFinished} result
* @param {HTMLElement} target
* @param {boolean} hydrate
*/
function initialize(result, target) {
function initialize(result, target, hydrate) {
if (DEV && result.state.error && document.querySelector('vite-error-overlay')) return;

current = result.state;
Expand All @@ -433,7 +434,7 @@ function initialize(result, target) {
root = new app.root({
target,
props: { ...result.props, stores, components },
hydrate: true
hydrate
});

restore_snapshot(current_navigation_index);
Expand Down Expand Up @@ -1406,7 +1407,7 @@ async function navigate({
root.$set(navigation_result.props);
has_navigated = true;
} else {
initialize(navigation_result, target);
initialize(navigation_result, target, false);
}

const { activeElement } = document;
Expand Down Expand Up @@ -2382,7 +2383,7 @@ async function _hydrate(
result.props.page.state = {};
}

initialize(result, target);
initialize(result, target, true);
}

/**
Expand Down

0 comments on commit f1a2133

Please sign in to comment.