-
-
Notifications
You must be signed in to change notification settings - Fork 574
add default_format method to RailsTemplate for Turbo compatibility #1144
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
Conversation
Thanks! |
basically revert haml/haml#1144
I think this change should be rolled back for the following reasons:
NB: "default_format" is quite underdocumented and seems confusingly named - when you define it you prevent the actual default fallback format (which is empty) from being used ( see |
@timdiggins haml has historically always supported If restoring support for '#content_type` is causing problems in some scenarios (I'm not at all clear on the js scenario you mention), then it must always have been problematic, surely? Whilst DHH may 8000 assert that inclusion of .html in view templates is required, it actually never has been a requirement, but simply common practice. |
Can either of you work on a pull request? As long as it passes tests, I'm open to merging one. |
Long response - hope it's helpful. @k0kubun I'm not sure what the pull request would be - I'm proposing reverting this change, but there are diverse points of view, so I guess we need to agree what the solution should be before working on code. @lazylester I wasn't aware of the previous use of default_format in haml (pre haml 5 I'm guessing, but I haven't found a def default_format in v3 or v4). In any case the re-use of default_format for template resolution purposes was effectively only started in rails 6 I believe (with this commit: rails/rails#35404) so those earlier uses wouldn't have impacted anyone. [3] And my point about this not being appropriate in haml, as it's only rails-related, is probably irrelevant as haml already contains a lot of rails-targeted code. Here's my understanding of the situation. The work that default_format does is to change the way that templates are resolved (discovered by their name in the filesystem), by rails. Confusingly, the (response) format is determined by rails based on the request, and is not (AFAICT) adjusted by the "default_format" that the templating system defines (the work of default_format in the templating system does not seem to be documented anywhere in rails sadly , despite it being used by many templating plugins like haml). This response format could be any defined mime-type's symbol (html, js, json, csv... and/or a custom defined one). The rails template resolver looks for a template matching the For partials and layouts, if the exact match doesn't exist, that's where default_format kicks in. Without a So haml defines their The answer is for everyone using formats which are not html with haml, to make sure to define layout It could be that the examples I've given here are edge cases and not important. But the options are:
But i think all of this discussion is mostly about rails and how it behaves. Hence my feeling that this code belongs in rails or (as a monkey patch) in an app. [1] the rule for layouts is -- no match, then skip the layout, whereas for partials, it's no match, then error. |
good research @timdiggins. I think there's a third option, going forwards, which is to deprecate the use of |
@lazylester unless I misunderstood, your third option seems to refer to how rails should work, not how haml works? Using the template default_format is a novelty in Haml 5 / 6, so "deprecating it" doesn't make sense I think (why introduce something in a patch release and then deprecate it). I think the monkey patch approach would still work for people using Turbo-Rails (just only with RailsTemplate and without the Plugin pathc) and wouldn't cause any issues with existing Haml users who aren't using turbo (or not yet, or not exclusively). Hence why I'm suggesting reverting this. Thoughts Les, or have I got the wrong end of the stick? |
The monkey patch works just fine. The problem I'm addressing, and the one I experienced, is that my app broke when I upgraded to the hamlit version of haml, because a feature of haml had been dropped. So I had to spend some time troubleshooting the internals of rails turbo to figure out why. Since it appears to me to be a pretty benign feature to restore, it seemed like an easy way to reduce the migration pain for other developers. All your forensic work is interesting, but it doesn't address the problem that I, and evidently others too (from the rails issue discussion) have encountered. |
Ah, ok, yes, I wasn't very clear! My suggestion is to revert this commit, but also as part of that PR noting the requirement for turbo-rails compatibility in either the documentation or in the CHANGLEOG for Haml 6 breaking changes something like the following:
@lazylester What do you think? Would you agree to this change? If so, I'm happy to contribute the PR if you don't want to. But I wouldn't want to contribute the reversion PR without your agreement. |
documenting the problem is good, but not as good as a deprecation notice. But I'm still not understanding why inclusion of the |
Thank you both, @timdiggins and @lazylester, for your thoughtful discussion on this issue.
Let me get this straight. Here's the
Neither of these defines Since this is a fairly new feature, I believe reverting it is also fixes #1152 and #1154, and this was not consistent with the recommendation by DHH himself, I'll revert this as @timdiggins proposed, in a minor release as a semi-breaking bugfix. To mitigate the impact for Turbo users, I'll cut a teeny release before that which only prints a deprecation warning in |
as discussed in 'issues'