-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
track scroll position without scroll listener #3938
Conversation
🦋 Changeset detectedLatest commit: f304f0d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
It might be worth investigating if As for |
Based on my reading of that article, I think we do want to use
Before this PR, we were replacing the current state after every |
Nice! I think the explanation from your last comment could go in a code comment because I had the same exact question (#3873 (comment)) on the PR that inspired this one |
I've looked a bit more and those marked as For what it's worth, I just tested locally and it was triggered apparently reliably, although I don't have access to many devices (win, android) and didn't check all use cases (I don't know all the different ways to close/sleep an app on Android, for instance).
I see, that makes sense, then! e: To clarify, it makes sense |
I'll confess I don't totally understand what the difference is — what cases would |
I added an explanatory comment in d538ac6 |
Basically situations where Force-quitting might be rare on a desktop, but it's surprisingly common on battery-restricted devices, though I'm not sure how aggressive devices/os versions are on average. |
Awesome stuff @Rich-Harris definitely supersedes my PR, much cleaner than my PR, actually one of my first commits in that PR was using variable approach(like you are doing in this PR, and Remix is doing almost the same) and only storing the states in
|
Thanks, I made some updates:
Some of the other stuff is deliberate. Resetting Setting |
Supersedes #3936 (which stores scroll state in
history.state
) and (I think) #3873.Instead of calling
replaceState
frequently as a result of scrolling, this updates scroll position when we navigate or leave the page. It does so by storingscroll_positions
in memory and persisting it tosessionStorage
inbeforeunload
(which allows us to recover scroll positions when the page is reloaded without needing to manipulate history).Contra #3936, I think it may be possible to add tests that useAdded a test, which makes me feel much more comfortable about this change.page.reload()
— will investigate.Thanks to @PH4NTOMiki for pointing in the direction of using
sessionStorage
rather thanhistory.state
.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0