Phoenix_live_view: Scroll restoration for live_redirect

Created on 17 May 2020  路  2Comments  路  Source: phoenixframework/phoenix_live_view

Previous discussion: https://elixirforum.com/t/how-to-restore-scroll-position-in-live-view-app/31548

Environment

  • Elixir version (elixir -v): 1.10.3
  • Phoenix version (mix deps): 1.5.1
  • Phoenix LiveView version (mix deps): 0.12.1
  • NodeJS version (node -v): v14.2.0
  • NPM version (npm -v): 6.14.4
  • Operating system: macos
  • Browsers you attempted to reproduce this bug on (the more the merrier): safari, chrome
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: no

Actual behavior

Going back on link restores the position, but going back on live_redirect doesn鈥檛.

Repro: https://github.com/syfgkjasdkn/scroll-position-live-view
Recording: https://www.dropbox.com/s/hkl11k3l1b8favc/scroll-demo.mp4?dl=0

Expected behavior

Scroll position is restored for live_redirect the same way as it is restored for link.

enhancement

Most helpful comment

Its appears part of the problem is that on redirect we scroll to the top https://github.com/phoenixframework/phoenix_live_view/blob/6185fad4080dd87abc327dd7b060960c99ecd490/assets/js/phoenix_live_view.js#L988 one possible fix is we could store the scroll position in the pushState meta and if it exists in popstate scroll to it?

All 2 comments

Its appears part of the problem is that on redirect we scroll to the top https://github.com/phoenixframework/phoenix_live_view/blob/6185fad4080dd87abc327dd7b060960c99ecd490/assets/js/phoenix_live_view.js#L988 one possible fix is we could store the scroll position in the pushState meta and if it exists in popstate scroll to it?

This was closed with the 0.14.5 release. Thanks!

Was this page helpful?
0 / 5 - 0 ratings