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

Conversation

PH4NTOMiki
Copy link
Contributor

@PH4NTOMiki PH4NTOMiki commented Feb 17, 2022

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

Simplifies hash handling initiated by click. as @benmccann pointed out in #3873 (comment) we don't really need to call renderer.update when the only thing needed update is page store, so that's what we are doing here, this is close to the browser default behavior, and since
@Rich-Harris merged pulls #3931 and #3938 we can now do that.

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2022

🦋 Changeset detected

Latest commit: af07e78

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

Rich-Harris commented Feb 17, 2022

Good catch, thanks. I fiddled with the logic a bit as it feels like it should be encapsulated within Renderer, even though it's slightly more verbose — setting up a subscription then immediately discarding it feels wrong when we 'own' the value in question. (Eventually I'd like to get rid of the distinction between Router and Renderer which is more of an encumbrance than anything.)

Technically this is a breaking change since someone could reference url.hash in their load function, but they shouldn't be doing that anyway as it won't work in SSR. I think this is the right move. (This reminds me that we need to add some docs on when load runs.) never mind, it's covered already

@PH4NTOMiki
Copy link
Contributor Author

Yeah, no problem, yeah that makes sense, I didn't want to change to much on my own. but that's definitely better.

@Rich-Harris Rich-Harris merged commit 922eadf into sveltejs:master Feb 17, 2022
@PH4NTOMiki
Copy link
Contributor Author

PH4NTOMiki commented Feb 17, 2022

@Rich-Harris just one more thing, in normal click navigation, first the URL changes, and then store changes, in this hash case, it's the opposite, we can fix that by calling update_page_store inside that hashchange handler(inside if block in it) and probably even that replaceState call

@Rich-Harris
Copy link
Member

that's true. i think it's probably fine — only issue would be if someone was reading window.location when $page.url changes, which would be kinda pointless. if it causes bugs we can fix

@PH4NTOMiki PH4NTOMiki deleted the simplify-hash-click-logic branch March 4, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants