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

Turbo is ignored on any navigation that uses a dot in the URL #480

Closed
andrewjtait opened this issue Nov 26, 2021 · 3 comments
Closed

Turbo is ignored on any navigation that uses a dot in the URL #480

andrewjtait opened this issue Nov 26, 2021 · 3 comments

Comments

@andrewjtait
Copy link

As of v7.1.0 form submissions do not use Turbo if the route includes a dot within its dynamic segment (https://guides.rubyonrails.org/routing.html#dynamic-segments)

For example, a form executing a POST to /domains/example.com

It looks as though the bug has been introduced as part of #437, which introduces an additional check for locationIsVisitable in this code:

turbo/src/core/session.ts

Lines 202 to 208 in aa9724d

willSubmitForm(form: HTMLFormElement, submitter?: HTMLElement): boolean {
const action = getAction(form, submitter)
return this.elementDriveEnabled(form)
&& (!submitter || this.elementDriveEnabled(submitter))
&& locationIsVisitable(expandURL(action), this.snapshot.rootLocation)
}

which is defined here:

turbo/src/core/url.ts

Lines 35 to 37 in 18c93e9

export function locationIsVisitable(location: URL, rootLocation: URL) {
return isPrefixedBy(location, rootLocation) && isHTML(location)
}

and checks the extension on the URL:

turbo/src/core/url.ts

Lines 26 to 28 in 18c93e9

export function isHTML(url: URL) {
return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml))$/)
}

@andrewjtait
Copy link
Author

andrewjtait commented Nov 26, 2021

Actually, it seems like this is an issue on any navigation to a URL using a dot, not just form submissions. I'll update the issue title to reflect this.

@andrewjtait andrewjtait changed the title Turbo is ignored on form submissions that use a dot in the URL Turbo is ignored any navigation that uses a dot in the URL Nov 26, 2021
@andrewjtait andrewjtait changed the title Turbo is ignored any navigation that uses a dot in the URL Turbo is ignored on any navigation that uses a dot in the URL Nov 26, 2021
@tleish
Copy link
Contributor

tleish commented Nov 26, 2021

@andrewjtait — see #385 discussion

@andrewjtait
Copy link
Author

@tleish ah, perfect - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants