Fix prefetch for links with data-turbo-frame=_self#1500
Open
4lllex wants to merge 1 commit intohotwired:mainfrom
Open
Fix prefetch for links with data-turbo-frame=_self#15004lllex wants to merge 1 commit intohotwired:mainfrom
4lllex wants to merge 1 commit intohotwired:mainfrom
Conversation
Prefetching a link `<a href="/" data-turbo-frame="_self"></a>` sends a request with a header `Turbo-Frame: _self`. This is incorrect as `_self` should be resolved to the current frame's id. This change resolves `_self` to the current turbo frame id before setting the header. When outside of a turbo frame the header is not set. Fixes hotwired#1349
be4bad1 to
c5147b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Links with
data-turbo-frame="_self"cause incorrect header to be set for prefetch requests:Turbo-Frame: _self. Unlike normal navigation,_selfis not resolved to the current turbo-frame id.When a link is outside of a turbo-frame, a
Turbo-Frame: _selfheader is still sent, which can lead to incorrect server responses. In rails, server is renderingturbo_rails/framelayout which causes a page reload upon navigation.Example:
This change resolves
_selfto the closest turbo-frame before setting the header and avoids sending the header when no frame is present. Tests cover both cases.Fixes #1349.