Skip to content

Fix prefetch for links with data-turbo-frame=_self#1500

Open
4lllex wants to merge 1 commit intohotwired:mainfrom
4lllex:fix-prefetch-turbo-frame-self
Open

Fix prefetch for links with data-turbo-frame=_self#1500
4lllex wants to merge 1 commit intohotwired:mainfrom
4lllex:fix-prefetch-turbo-frame-self

Conversation

@4lllex
Copy link
Copy Markdown

@4lllex 4lllex commented Feb 8, 2026

Links with data-turbo-frame="_self" cause incorrect header to be set for prefetch requests: Turbo-Frame: _self. Unlike normal navigation, _self is not resolved to the current turbo-frame id.

When a link is outside of a turbo-frame, a Turbo-Frame: _self header is still sent, which can lead to incorrect server responses. In rails, server is rendering turbo_rails/frame layout which causes a page reload upon navigation.

Example:

<turbo-frame id="frame" target="_top">
  <!-- header is incorrect -->
  <a data-turbo-frame="_self" href="/test">_self in frame</a> 
</turbo-frame>

<!-- header is incorrect, page reload in rails -->
<a data-turbo-frame="_self" href="/test">_self out of frame</a>

This change resolves _self to the closest turbo-frame before setting the header and avoids sending the header when no frame is present. Tests cover both cases.

Fixes #1349.

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
@4lllex 4lllex force-pushed the fix-prefetch-turbo-frame-self branch from be4bad1 to c5147b7 Compare March 12, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Prefetch doesn't handle links with data-turbo-frame="_self"

1 participant