-
Notifications
You must be signed in to change notification settings - Fork 437
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
Avoid bubbling form submissions that target a new window/tab #755
Avoid bubbling form submissions that target a new window/tab #755
Conversation
@martinzamuner thank you for proposing this change! When I'd proposed the turbo/src/observers/form_submit_observer.ts Lines 59 to 67 in 732db00
Instead of adding a new method, what do you think about combining Similarly, could you add coverage for the same scenario for turbo/src/observers/link_click_observer.ts Lines 74 to 80 in 732db00
|
src/observers/link_click_observer.ts
Outdated
|
||
return true | ||
function doesNotHaveSpecificTarget(anchor: HTMLAnchorElement): boolean { | ||
return anchor.target != "_self" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to have a special case handler for _self
, could we also add test coverage to guarantee that behavior and guard against regressions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! BTW, I had to remove the check on target
from LinkClickObserver#findLinkFromClickTarget
to avoid a full-page load in the case of [target=_self]
.
@seanpdoyle Sure thing! I've added a special case for There was already a test for this behavior with anchors: https://github.com/hotwired/turbo/blob/main/src/tests/functional/navigation_tests.ts#L208-L213. |
@dhh Thanks for running the tests! There were a couple failures related to anchors inside SVGs behaving kind of weird. Their Aside from that, those same tests were now broken because I added some elements before the SVGs in the fixture, and they were not above the fold anymore. That means that |
Fixed by #835. |
Resolves #754
Avoid bubbling
<form>
element submissions when they target a new window/tab. This occurs when:<form>
declares a target of_blank
<form>
element's submitting<button>
element declares a formtarget of_blank
<form>
element's submitting<input type="submit">
element declares a formtarget of_blank
Based on #389