Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Don't unmount components on Turbolinks navigation #1135

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

calleluks
Copy link
Contributor

As discussed in #1028, unmounting components on turbolinks:before-render prevents Turbolinks from restoring the scroll position when navigating back to pages with tall React components. This happens because Turbolinks tries to restore the scroll position before firing the turbolinks:load event. Since components were unmounted prior to this, the page might be much shorter than it will be after mounting components causing scroll position restoration to fail.

We've been running this in production for a week now and haven't noticed any issues caused by not unmounting components.

[As discussed in reactjs#1028](reactjs#1028 (comment)), unmounting components on `turbolinks:before-render` prevents Turbolinks from restoring the scroll position when navigating back to pages with tall React components. This happens because Turbolinks tries to restore the scroll position before firing the `turbolinks:load` event. Since components were unmounted prior to this, the page might be much shorter than it will be after mounting components causing scroll position restoration to fail.

We've been running this in production for a week now and haven't noticed any issues caused by not unmounting components.
@henrik
Copy link

henrik commented Jan 26, 2022

@BookOfGreg Hi! Would it be possible to get a new react_ujs release incorporating this fix?

Or at least to get it into react_ujs/dist?

We'd love to use it via https://www.npmjs.com/package/react_ujs.

@henrik
Copy link

henrik commented Apr 1, 2022

@BookOfGreg Hi! Sorry to bother you – just wanted to check again if I could encourage either a new release or to get this change into dist?

@henrik
Copy link

henrik commented Oct 3, 2022

Updated to 2.6.2 and it seems to work. Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants