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
Haml 6 attribute behavior change breaks a lot of existing code in sometimes subtle ways #1148
Comments
Released v6.2.2 that allows you to add custom attributes to |
Thank you for your fast response and thank you for providing an official way to mark attributes as boolean. We did that via a monkey patch so far: Haml::AttributeBuilder.class_eval do
remove_const(:BOOLEAN_ATTRIBUTES).tap do |boolean_attributes|
const_set(:BOOLEAN_ATTRIBUTES, [*boolean_attributes, *additional_boolean_attributes].freeze)
end
end However, this does not fully solve the problem. If there are 100+ different JS components - each attaching to its own custom attribute - I'd have to find all of them and add them to this list. This would be cumbersome, but a one-time task. That's doable. However, I'd also have to keep this list updated whenever I add or remove new JS components. This would be highly susceptible to human error. I know that I'm asking for an additional if-clause in I'm thinking of something like this: def compile_common!(temple, key, values)
if LEGACY_BEHAVIOUR
compile_boolean!(temple, key, values)
else
temple << [:html, :attr, key, [:fescape, @escape_attrs, values.last]]
end
end I haven't checked, whether that breaks anything else and if that even fixes all our edge cases. Treat this as a draft.
|
No, because this is a trade-off we deliberately made for performance in Haml 6.
Hamlit has run the tests of Haml 5 even before it gets merged into Haml, and it has skipped deliberately failed tests. This behavior would be one of them.
It varies. No impact, as slow as Haml 5, or slower than Haml 5, depending on the benchmark. I'd like to suggest a couple of alternatives.
The benefit of these two ideas is that it doesn't interfere with the performance of other places. Your |
Well, if the Thanks for the workaround suggestions. We already considered those and will definitely use them for all new projects. Can't undo decisions of the past, though. |
There are still a couple of problems:
All in all, I don't think it's worth the extra maintenance effort when the "workaround" is more performant than the proposed solution for your application and the sole purpose of Haml 6 was to improve performance. Right now, the only benefit of upgrading Haml to 6 is performance improvements, and you're not gonna get that if you use
I personally recommend the migration with (2) if (1) seems too hard. You can craft a gsub call that matches |
The additional maintenance to keep the legacy behavior working is a very good point. We will do the workaround on our side. Thank you for your patience. Highly appreciated! |
I use many custom attributes to attach JS behavior to HTML elements. Sometimes I want to deactivate this JS behavior dynamically and use
%div(my-custom-attribute-with-attached-js-behavior=false)
. In Haml 5 this didn't render the attribute. In Haml 6 it does and thereby suddenly activates the JS.It would be nice if there would be a setting to get back the old behavior or at least remedy the necessity to modify ALL of the JS hooks. And out of curiosity: what were the reasons for this behavior change?
My general thoughts about attribute handling:
true
orfalse
true
,false
ornil
, I most definitely don't want these values to be cast to a string.What is your opinion on this proposal?
The text was updated successfully, but these errors were encountered: