Turbo: In-page anchors and hashchange events can cause full page visits or otherwise behave unexpectedly

Created on 21 January 2024, 5 months ago
Updated 25 February 2024, 4 months ago

Problem/Motivation

We use in-page anchors on Omnipedia for a number of crucial UI interactions, especially on mobile, to enable various things to work even if JavaScript doesn't execute (e.g. the sidebar menu shows itself via CSS when #menu is present in the window location) by use of the :target selector. Turbo exhibits some unexpected behaviour compared to default browser behaviours; notably:

  1. hashchange events are triggered twice during restoration visits.
  2. Turbo will do a full page load during a restoration visit if navigating via back/forward when just the hash has changed.
  3. :target doesn't begin to match if hash added by a Turbo click.

Steps to reproduce

See above.

Proposed resolution

It looks like pull request #1125: Improve handling of anchor links and hashchange events fixes items 1 and 2 so we can either wait for that to be merged or patch Turbo ourselves; item 3 - :target not matching - seems like it might be difficult or impossible for them to implement cleanly as browsers don't expose a way to affect this directly, but it is possible to hack it in by programmatically clicking a link that Turbo isn't attached to, ugly though that might be.

Links

Remaining tasks

Unclear.

User interface changes

Stuff begins to work as expected.

API changes

None?

Data model changes

None.

πŸ› Bug report
Status

Postponed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024