Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@daun
Copy link
Member

@daun daun commented Jul 23, 2024

Most routing libraries currently store the scroll position in the history state and manually restore it from there.

Advantages

  • Programmatically read and manipulate the stored position
  • Control over the exact point in time when to restore the scroll position
  • No artificial separation between animated and non-animated (history) visits

Prior art

Description

  • Remember scroll position in history state
  • Restore scroll position from history state
  • Completely disable browser scroll restoration
  • Create two hooks: scroll:store when saving position, scroll:restore when restoring position
    • Makes it extendable to support arbitrary scroll containers (to be managed by Scroll Plugin)
  • Currently uses debounced scroll function to update position when scrolling stops

To-do

  • Restore scroll position on reload (maybe a Scroll Plugin feature?)
  • Implement proper tests
  • Check if this breaks anything and needs to move into v5

Checks

  • The PR is submitted to the master branch
  • The code was linted before pushing (npm run lint)
  • All tests are passing (npm run test)
  • New or updated tests are included
  • The documentation was updated as required

@github-actions
Copy link

github-actions bot commented Jul 23, 2024

Size Change: +894 B (+3.82%)

Total Size: 24.3 kB

Filename Size Change
dist/Swup.modern.js 7.42 kB +321 B (+4.52%) 🔍
dist/Swup.module.js 8.32 kB +297 B (+3.7%)
dist/Swup.umd.js 8.54 kB +276 B (+3.34%)

compressed-size-action

@github-actions
Copy link

github-actions bot commented Jul 23, 2024

Playwright test results

passed  318 passed

Details

report  Open report ↗︎
stats  318 tests across 22 suites
duration  16 minutes, 31 seconds
commit  21bffc7

@daun
Copy link
Member Author

daun commented Jul 25, 2024

Note to self: make scroll handler passive.

@hirasso
Copy link
Member

hirasso commented Jul 25, 2024

Another note: Check if this breaks scroll position restoration if using resolveUrl.

@daun
Copy link
Member Author

daun commented Jul 25, 2024

@hirasso Right! We'll probably need to check this together on a call, the resolve-url logic is still a bit mysterious to me 🙃

@daun daun marked this pull request as ready for review August 13, 2024 21:13
@daun
Copy link
Member Author

daun commented Aug 13, 2024

@hirasso I think this one is ready for review :)

Could you check in one of your projects using resolveUrl if this makes any difference in behavior?

@daun daun requested a review from a team August 13, 2024 21:14
@daun
Copy link
Member Author

daun commented Sep 25, 2024

Closing in favor of implementing this in the Scroll Plugin for advanced use cases.

@daun
Copy link
Member Author

daun commented Sep 25, 2024

Tracked in #84

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.

3 participants