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

Opt out of restoring placeholders for a promoted TF navigation #181

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

julianrubisch
Copy link
Contributor

@julianrubisch julianrubisch commented Jun 27, 2024

Bug Fix

Description

When navigating a part of the page using Turbo Frames, in case of promoting to a normal page visit, the placeholders would be replaced but never resolve again.

The reason for this is that the turbo:before-cache event fires on a regular visit, so placeholders will be restored in order to be put into the Turbo cache afterwards. Contrary to a regular page visit, though, the whole page body will not be replaced, so the placeholders remain unresolved.

This would have been an easy fix if the turbo:before-cache event would have exposed an event.detail pointing to something usable, like the targeted Turbo Frame. Since it does not, however, I have come up with the following solution:

  1. in a callback to the turbo:before-fetch-request event, the requested Turbo Frame ID is stored in the sessionStorage
  2. the restorePlaceholders callback triggered by turbo:before-cache will return early if such an identifier is present, then delete it

This could potentially lead to some race conditions, but since this should be tab-isolated, I think it's pretty safe.

Reproduction repository here: https://github.com/julianrubisch/futurism_turbo_frame_placehoder

Copy link

@hopsoft hopsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question... but LGTM. 🚀

javascript/elements/index.js Show resolved Hide resolved
@julianrubisch julianrubisch merged commit 6d9e180 into master Jul 8, 2024
11 checks passed
@julianrubisch julianrubisch deleted the fix-turbo-frames-advance-navigation branch July 8, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants