You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the script, visit http://localhost:4567, then scroll down and check any box. It will scroll back up which is unexpected because i'm rendering a turbo stream. Even an empty response Turbo.renderStreamMessage("") would trigger a scroll to the top.
Investigation
After further debugging it appears it happens when there are duplicated IDs in the page, more specifically when the element triggering the event is the one being duplicated.
While it ain't really a bug, it definitely is a breaking change that could potentially bring head aches to some people who aren't aware they have duplicated IDs. Here was our line of code in Rails:
james-em
changed the title
[Breaking changes] Turbo 8: Scroll position is lost on render
[Breaking changes] Turbo 8: Scroll position is lost on render when an ID is duplicated in the page
Apr 8, 2024
The issue is introduced when upgrading from Turbo 7.3.0 to Turbo 8. Every beta has this breaking change as well.
Originally flagged here: hotwired/turbo-rails#575 (comment)
Reproductible exemple
https://pastebin.com/ui0zzDZr
Run the script, visit http://localhost:4567, then scroll down and check any box. It will scroll back up which is unexpected because i'm rendering a turbo stream. Even an empty response
Turbo.renderStreamMessage("")
would trigger a scroll to the top.Investigation
After further debugging it appears it happens when there are duplicated IDs in the page, more specifically when the element triggering the event is the one being duplicated.
While it ain't really a bug, it definitely is a breaking change that could potentially bring head aches to some people who aren't aware they have duplicated IDs. Here was our line of code in Rails:
All the checkboxes had "process" for an ID
The text was updated successfully, but these errors were encountered: