Skip to content

Commit 8a58ca8

Browse files
authored
Don't unmount components on Turbolinks navigation
[As discussed in #1028](#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.
1 parent c8c57bb commit 8a58ca8

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

react_ujs/src/events/turbolinks.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ module.exports = {
22
// Turbolinks 5+ got rid of named events (?!)
33
setup: function(ujs) {
44
ujs.handleEvent('turbolinks:load', ujs.handleMount);
5-
ujs.handleEvent('turbolinks:before-render', ujs.handleUnmount);
65
},
76

87
teardown: function(ujs) {
98
ujs.removeEvent('turbolinks:load', ujs.handleMount);
10-
ujs.removeEvent('turbolinks:before-render', ujs.handleUnmount);
119
},
1210
}

0 commit comments

Comments
 (0)