Skip to content

Commit d8fb3bc

Browse files
committed
fix: recover scroll position on reload of SPAs
1 parent f48cd60 commit d8fb3bc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/kit/src/runtime/client/client.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,25 @@ export async function start(_app, _target, hydrate) {
312312
// if we reload the page, or Cmd-Shift-T back to it,
313313
// recover scroll position
314314
const scroll = scroll_positions[current_history_index];
315-
if (scroll) {
316-
history.scrollRestoration = 'manual';
317-
scrollTo(scroll.x, scroll.y);
318-
}
319315

320316
if (hydrate) {
317+
if (scroll) {
318+
history.scrollRestoration = 'manual';
319+
scrollTo(scroll.x, scroll.y);
320+
}
321+
321322
await _hydrate(target, hydrate);
322323
} else {
323324
await navigate({
324325
type: 'enter',
325326
url: resolve_url(app.hash ? decode_hash(new URL(location.href)) : location.href),
326327
replace_state: true
327328
});
329+
330+
if (scroll) {
331+
history.scrollRestoration = 'manual';
332+
scrollTo(scroll.x, scroll.y);
333+
}
328334
}
329335

330336
_start_router();

0 commit comments

Comments
 (0)