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

Simplify hash change click handler #3975

Merged
merged 6 commits into from
Feb 17, 2022
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-olives-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Update page store without rerunning load when hash changes
12 changes: 12 additions & 0 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ export class Renderer {
this.autoscroll = true;
this.updating = false;

if (navigation_result.props.page) {
this.page = navigation_result.props.page;
}

if (!this.router) return;

const leaf_node = navigation_result.state.branch[navigation_result.state.branch.length - 1];
Expand Down Expand Up @@ -432,13 +436,21 @@ export class Renderer {
return this.invalidating;
}

/** @param {URL} url */
update_page_store(url) {
this.stores.page.set({ ...this.page, url });
this.stores.page.notify();
}

/** @param {import('./types').NavigationResult} result */
_init(result) {
this.current = result.state;

const style = document.querySelector('style[data-svelte]');
if (style) style.remove();

this.page = result.props.page;

this.root = new this.Root({
target: this.target,
props: {
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,8 @@ export class Router {
this.hash_navigating = true;

this.#update_scroll_positions();
this.renderer.update_page_store(new URL(url.href));

const info = this.parse(url);
if (info) {
return this.renderer.update(info, [], false);
}
return;
}

Expand Down