Skip to content

Commit

Permalink
Simplify hash change click handler (#3975)
Browse files Browse the repository at this point in the history
* first try

* second try

* try 3

* try 4

* encapsulate page store update logic inside renderer

* changeset

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
PH4NTOMiki and Rich-Harris authored Feb 17, 2022
1 parent 2125685 commit 922eadf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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

0 comments on commit 922eadf

Please sign in to comment.