Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Breaking changes] Turbo 8: Scroll position is lost on render when an ID is duplicated in the page #1226

Open
james-em opened this issue Mar 19, 2024 · 0 comments

Comments

@james-em
Copy link

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:

- @records.each do |record|
    = check_box_tag :process, record.id, record.processed_at.present?, {data: { action: 'change->process-time#onChange'}

All the checkboxes had "process" for an ID

@james-em 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant