-
Notifications
You must be signed in to change notification settings - Fork 432
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
Remove isHTML #519
Remove isHTML #519
Conversation
Thank you for opening this change! In theory, I'm in favor. I'm having some trouble digging through the Git history to get background on why this restriction was introduced. The earliest version of this was introduced in the port to TypeScript. Jumping over to the project's turbolinks/turbolinks predecessor, the method was introduced to Avoid visiting links to non-HTML destinations about 6 years ago. @packagethief I see you're in the |
Hey @seanpdoyle! Yes, it was because we wanted to avoid visiting links to images and other media by default. I agree that the heuristics are somewhat dubious. But I do think it's important that we not try to visit locations that are unlikely to return HTML. For example, it would be extremely unlikely for a path ending in ".jpg" to return an HTML document (but not impossible). Perhaps it would be better to define the exclusions (likely also perilous), or to delegate the decision to the application. |
Some additional context (from 2016!) regarding public, configurable API:
|
@seanpdoyle, you have my memory gears turning now 😄 It seems we concluded that delegating the decision to applications via configuration was the way to go. Past me agrees: |
@seanpdoyle, @packagethief: Thank you very much for the input. I guess it makes perfect sense to have some kind of configurable URL based HTML recognition. It would allow application wide defaults without being forced to annotate all links with I have some initial implementation that moves Cheers |
3094424
to
b8e55f5
Compare
So that’s what I come with. I moved After doing that I couldn’t stop thinking that TLDR: Other changes: I added php extension to list of extensions that resolve as visitable by default. Probably it is as common as html extension and would almost certainly return some kind of HTML content type. I thought that this would be a convenient addition as in issues it already starts to pop out that Turbo doesn’t work with php extensions by default. I think this would bring some peace ✌️. Added tests that bind user defined functions to Added Cheers |
b8e55f5
to
dd2c46e
Compare
As a php developer, I thank you!! |
There must be an opportunity here to leverage the return link.type && link.type != "text/html" This feels more in keeping with the current scope of Turbo, as a progressive enhancement that uses the HTML we already have. It also seems to meet the need of user configuration, but without requiring users to write their own Javascript. |
(Incidentally, on the subject of |
That's idea that could be considered but the problem here is that Turbo can't navigate certain URLs at all. For example now there no is way to visit page with |
If I'm understanding correctly this means that I would need to add a
I don't have any HTML: I have PHP templates. So this would be the opposite of progressive for me: it would require a change to half the files in my codebase. |
If you link to a On GitHub, for example, you often encounter links that end with This may well be a bad idea (and I don’t want to hijack this PR), but I’d personally rather write |
Ah, thanks for explaining further! Now that I understand it, I think I do like the idea, but you're right it's probably outside the scope of this PR |
Is there any way to override isHTML or locationIsVisitable with the current release? Still struggling to get Turbo to work with .php extension. |
I prefer I also prefer exposing the isHTML method to a global level to allow override: Turbo.session.isHTML = () => true; However, you could also provide a simpler on/off solution with a boolean variable. Turbo.session.strictVisitMimeType = true; // default |
Before we fully resolve #519, we can sort out the main hurt from this, which seems to be .php extensions.
Before we fully resolve #519, we can sort out the main hurt from this, which seems to be .php extensions.
Hmmm, I'm not able to run tests locally anymore. Playwright rly dosn't seem to come along nicely with non Ubuntu distros. |
Enabled tests to be run. Needs a rebase. |
@dhh Rebased it, but approval seems to expire after I force push rebased branch. |
Think it needs another rebase. Sorry! |
17a7678
to
da2ca9e
Compare
np, rebeased! Cheers |
Hey @packagethief, any thoughts how we could move forward with this one? Cheers |
Add `Session.isVisitable` method whitch is equivalent of no longer accessible `URL.isHTML`. This allows `Turbo.session.isVisitable` to be overriden by user and makes possible navigation on URL's other than those with trailing slash or HTML extenion.
da2ca9e
to
c7f03e1
Compare
@manuelpuyol: I resolved conflicts but its hard to keep this one up to date. Usually it breaks after a few commits to mian. It seems that it touches the lines that change very often. |
@dhh could you enable the tests in this pr? 🙏 |
I just wanted to say that I arrived here because I am using |
After all of the CFML that I've been writing, it was a bit soul-crushing to finally install Hotwire only to find that it doesn't work with CFML. Or, rather, it doesn't work with `.cfm` extensions. This is by design, though there are talks on the Hotwire side to re-think this constraint: **GitHub Issue**: [Remove isHTML](hotwired/turbo#519) Since non-HTML extensions might serve up _anything_, Hotwire can't know that said URL is for an HTML page. And, therefore, can't know that it has to intercept the link-click/form-submission. As such, I have to change the `.cfm` extensions to `.htm` extensions and then enable SES URL rewriting in the CommandBox server. This will rewrite to `index.cfm` with the `cgi.path_info` value being set to the original URL. That said, since I'm only using the `index.cfm` in this app, I don't even have to worry about it.
What's preventing this PR from being merged now? Is just a rebase that's needed or some more work is required? I'd be happy to help finish this. I landed here, like all the others, by running into the issue because Turbo mysteriously stopped working on some URLs. I have URLs that are referencing external IDs. And the IDs sometimes have a "." in it. If there are still concerns regarding the original motivation behind this feature (preventing Turbo from fetching images) perhaps the check could be inverted from |
Hello,
Before Turbo will make a request it checks URL against regexp. The check passes for URLs without a file extension and those ending with
.htm
,.html
and.xhtml
. On success request is made using Turbo and on failure whole page is replaced.I would like to propose removing
isHTML
function. Results ofisHTML
call are highly dubious and should not be trusted.Example 1: Lets say there is a
download
action that maps to/download
URL path. Response type of it would beapplication/octet-stream
but Turbo will assume that it is HTML.Example 2: For URLs like
https://github.com/hotwired/turbo/blob/main/README.md
where parameter is part of path Turbo will fail to recognize browsable URL.I believe a better approach would be to try to open everything by default and require to explicitly mark unbrowsable links with
data-turbo=”false”
. That would remove a bunch of unobvious URL problems like these mentioned above.Moreover, currently its impossible to force Turbo visit as setting
data-turbo
totrue
triggers default behavior (that callsisHTML
) and normal request instead of Turbo request is made (ifisHTML
will returnfalse
).The change is a breaking one because it requires unbrowsable links to have
data-turbo=”false”
attribute added (not the case currently) but I believe it would result in more predictable less error prone behaviour in general.Also after removing
isHTML
locationIsVisitable
is reduced to return just the value ofisPrefixedBy
and is somewhat obsolete. So I replaced calls tolocationIsVisitable
withisPrefixedBy
.There are some disscussions regarding
isHTML
probems already open: #185, #385, #480.Cheers
🍷