-
Notifications
You must be signed in to change notification settings - Fork 434
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 will not navigate to URLs that have a .
in the pathname
#608
Comments
@packagethief You just looked at this, right? We're doing this to prevent Turbo from trying to load .jpg and .mp4 etc. |
There’s some related discussion here: #519 |
thanks for the context! |
Yes, we discussed beginning in #519 (comment) and the conclusion was that we should introduce API so applications can customize. We just need to decide on what that API should look like. Originally I'd imagined hanging something off the I'm liking the suggestion in #519 (comment), which is that we assume all URLs are turbo-visitable by default, and require applications to annotate the ones that aren't. Turbo will already avoid following links annotated |
Okay. That is a breaking change, though. If suddenly links to a jpg that were working fine before stop working unless you annotate. Maybe we could do both? Build a type list that we'll default to off on (all image + audio + video types). Then everything is default on, and you have to opt out beyond that? |
I don't think it's a breaking change since the idea is to provide a way for users to customize what is visitable or not. The default will be the same, and each app can override it if they want to |
Yeah, we need to be backward compatible, so we can't change the default behavior. I think the simplest thing to do is expose something on |
This is an example of what I consider unwieldy, just to quantify it: This is too onerous for official API. Now that I think more about it, the lack of a good idea for appropriate API is the main reason we didn't add this years ago. So, suggestions appreciated! |
I do like the idea proposed in #519 , where they are exposing a |
I don't think we need new API. We could just extend |
Or even simpler than that. Pass basic object to |
Or alternatively keep extensions in their own separate array attribute. So if certain extension should be turbo-enabled just push it there. And if more flexibility is needed reassign But is it really needed? let components = testing.pathname.split("/").slice(1);
let lastPathComponent = components.slice(-1)[0];
let extension = (lastPathComponent.match(/\.[^.]*$/) || [])[0] || "";
return location.origin === testing.origin && !!extension.match(/^(?:|\.(?:htm|html|xhtml|aspx))$/) can be written as just: let parts = url.pathname.split('/').pop().split('.')
return (parts.length > 1) && ['doc', 'txt'].includes(parts.pop()) With better defaults (addition of php for example) I think it may not be worth the effort and simple function would be more readable. |
I would like to add that it would be nice if Global config is nice and all for PHP folks, etc. but I currently am in the situation that I don't want it globally. Think one route working like GitHubs source browsing. I'm fine with putting turbo=true on all of them but currently it just gets ignored because Turbo doesn't deem it visitable despite me explicitly telling it that it is. Or since I guess it defaults to true maybe a data-turbo-force=true or something so that I can selectively tell Turbo to "trust me on this one". |
@2called-chaos It doesn't. I think that this is a separate bug/issue. Right now its value could be I have similar project where I have to pass file path as a parameter in a Cheers |
Yeah I think the issue is that you can have Turbo Drive default to off and selectively enable it. That would mean willFollowLinkToLocation(link: Element, location: URL) {
return this.elementDriveEnabled(link)
&& locationIsVisitable(location, this.snapshot.rootLocation)
&& this.applicationAllowsFollowingLinkToLocation(link, location)
} would turn to something like this and I would be happy willFollowLinkToLocation(link: Element, location: URL) {
return this.elementDriveEnabled(link)
&& (
link.getAttribute("data-turbo-force") == "true" ||
locationIsVisitable(location, this.snapshot.rootLocation)
)
&& this.applicationAllowsFollowingLinkToLocation(link, location)
} Also how do you overwrite isHTML? I'm too dumb when it comes to es6 module scopes apparently |
Yes, I don't think it will be often used but As for overwriting |
Would love to see #519 land!
I tentatively disagree with this. Selectively enabling when Drive is off is telling Turbo to handle the link/form/container. I can't imagine why you'd expect Turbo to end up not handling where you opted in for any reason, let alone because of a |
Just ran into this same issue when using an FQDN as a param at the end of a path (in a Rails app), eg:
Since a new major version, aka Turbo 8, is coming up, can this logic now be changed in a breaking way? I'd personally prefer dropping However, if that's still too much even for a major release, perhaps the logic could be inverted to become default-allow unless an extension is on the known-unsafe list (containing .jpg, .mp4, etc.)? |
Just a note that Rails will often append |
You can add a In Rails, you can use resources :users, trailing_slash: true You can see more at ActionDispatch::Routing::UrlFor documentation |
We are using a specific URL syntax for describing date periodes, containing dots. We suddenly had Turbo do full page refreshes instead of morphing the page for streaming page refreshes. It took quite some debugging to find this issue. I think Reading all the comments above, I would like to suggest another possible approach:
I think this approach would be backwards compatible with the current situation and solves most edge cases with the current |
I ran into this issue while making a content management system. It was important to us that the url matched the file title, and some of the titles are function calls that contain a ".". My solution was a data attribute on the calling link that stated the href isVisitable. I pass the link element to the locationIsVisitable function, check for the data attribute, and return true if it exists, else I use the original check of isHTML and isPrfixedBy. I am not super familiar with the code base so this might not be a great solution. If anyone is interested I can submit a PR. I am pretty sure this is backwards compatible, and is nice if you only have a couple urls on your site that have this issue. |
@chillenberger in our case that would mean we need to add the I think linking to non-HTML pages is a lot less common overall. In our application we only link to things like PDF, CSV and Excel exports. Having to mark these links with |
turbo/src/core/url.ts
Lines 27 to 29 in 98cdc40
It looks like that this behavior is intended, guessing it prevents Turbo from running when users are downloading a file. The problem is that routes with
.
are valid in Rails routes, so, if you tried to navigate to routes like:Turbo won't even try to navigate to them.
The text was updated successfully, but these errors were encountered: