You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Up to Turbo v7.1.0, when setting Turbo.session.drive = false, links within a <turbo-frame> would not be hijacked and instead allow the default browser behavior of a full page navigation to happen.
In Turbo v7.2.2 and above this behavior changed. Now Turbo.session.drive is ignored within <turbo-frame> elements and links always get hijacked regardless of the value of that setting.
I couldn't find anything in the changelog about this change in behavior, and my expectation is that disabling Turbo.session.drive should make link-hijacking opt-in only, regardless of whether those links are in or outside a Turbo Frame.
This is also important for my use case, as I maintain a project that uses Turbo Frames to load content, but doesn't use Turbo Drive for the most part. This change in behavior means if I upgrade to Turbo 7.2.x I'd have to remember to set target="_top" on every Turbo Frame in the project, instead of disabling Drive by default and opting in only when needed.
Here's a test demonstrating the issue:
<!-- index.html --><!DOCTYPE html><html><head><metacharset="utf-8"><title>Turbo Drive test</title><scripttype="module">// Test loaderdocument.addEventListener('DOMContentLoaded',()=>{document.getElementById('test-select').addEventListener('change',(e)=>{document.head.append(document.getElementById(e.currentTarget.value).content.querySelector('script').cloneNode(true))document.getElementById('test-setup').style.display=nulle.currentTarget.setAttribute('disabled',true)});});</script><style>
:root { font-family: sans-serif }
turbo-frame {
display: block;
border: 1px solid red;
}
</style></head><body><selectid="test-select"><optionvalue="">-- Select a test --</option><optionvalue="test-1">Turbo 7.1.0; Drive enabled</option><optionvalue="test-2">Turbo 7.1.0; Drive disabled</option><optionvalue="test-3">Turbo 7.2.4; Drive enabled</option><optionvalue="test-4">Turbo 7.2.4; Drive disabled</option></select><mainid="test-setup" style="display: none"><p>Outside <tt>turbo-frame</tt>—this should only remain here after clicking below link when <tt>Turbo.session.drive</tt> is enabled</p><p><tt>Turbo.session.drive</tt> is <spanid="turbo-drive-value"></span></p><turbo-frameid="frame"><p>Inside <tt>turbo-frame</tt></p><p><ahref="/payload.html" data-turbo-target="_self">click me</a></p></turbo-frame></main><templateid="test-1"><scripttype="module">import*asTurbofrom"https://cdn.skypack.dev/@hotwired/turbo@7.1.0"Turbo.session.drive=truedocument.getElementById('turbo-drive-value').innerHTML='enabled'</script></template><templateid="test-2"><scripttype="module">import*asTurbofrom"https://cdn.skypack.dev/@hotwired/turbo@7.1.0"Turbo.session.drive=falsedocument.getElementById('turbo-drive-value').innerHTML='disabled'</script></template><templateid="test-3"><scripttype="module">import*asTurbofrom"https://cdn.skypack.dev/@hotwired/turbo@7.2.4"Turbo.session.drive=truedocument.getElementById('turbo-drive-value').innerHTML='enabled'</script></template><templateid="test-4"><scripttype="module">import*asTurbofrom"https://cdn.skypack.dev/@hotwired/turbo@7.2.4"Turbo.session.drive=falsedocument.getElementById('turbo-drive-value').innerHTML='disabled'</script></template></body></html>
Select a Turbo version and Turbo.session.drive value from the dropdown
Click the link
Expected behavior: when Drive is disabled clicking the link should cause a full page navigation.
Result: Turbo 7.1.0 complies with expected behavior; Turbo 7.2.4 ignores the disabled Drive setting.
The text was updated successfully, but these errors were encountered:
pilaf
changed the title
Disabled Turbo.session.drive ignored in turbo frames v7.2.x
Disabled Turbo.session.drive ignored in Turbo Frames v7.2.x
Dec 21, 2022
pilaf
changed the title
Disabled Turbo.session.drive ignored in Turbo Frames v7.2.xTurbo.session.drive ignored in Turbo Frames v7.2.x
Dec 21, 2022
…ttons) using data-turbo=false on them individually. Turbo.session.drive = false; in app/javascript/appication.js seemed to not disable Turbo on links/buttons(forms) inside a Turbo Frame (hotwired/turbo#826)
Up to Turbo v7.1.0, when setting
Turbo.session.drive = false
, links within a<turbo-frame>
would not be hijacked and instead allow the default browser behavior of a full page navigation to happen.In Turbo v7.2.2 and above this behavior changed. Now
Turbo.session.drive
is ignored within<turbo-frame>
elements and links always get hijacked regardless of the value of that setting.I couldn't find anything in the changelog about this change in behavior, and my expectation is that disabling
Turbo.session.drive
should make link-hijacking opt-in only, regardless of whether those links are in or outside a Turbo Frame.This is also important for my use case, as I maintain a project that uses Turbo Frames to load content, but doesn't use Turbo Drive for the most part. This change in behavior means if I upgrade to Turbo 7.2.x I'd have to remember to set
target="_top"
on every Turbo Frame in the project, instead of disabling Drive by default and opting in only when needed.Here's a test demonstrating the issue:
To run the test:
$ ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'
Turbo.session.drive
value from the dropdownExpected behavior: when Drive is disabled clicking the link should cause a full page navigation.
Result: Turbo 7.1.0 complies with expected behavior; Turbo 7.2.4 ignores the disabled Drive setting.
The text was updated successfully, but these errors were encountered: