-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Proposal: config to disable/customize attribute inheritance #1520
Comments
This came up in the discord too. The basic proposal is to add an attribute that either lets you disable inheritance globally, or specify which attributes are inherited by default:
|
The main issue I face is that I found it counter-intuitive that moving a piece of html around does change it's behaviour, it makes refactoring a lot harder for no good reason. I think the current behaviour breaks the Locality of Behaviour the author advocate for so much. For instance I cannot just work with fragments, which are typically separated pieces of code that live on their own, I often need to know more, e.g. their surrounding, in order to understand the fragment behaviour. IMHO increases the likelihood of introducing undesired bugs, i.e. somebody excluding some parameters in the parent without knowing it will affect fragments living elsewhere. Inheritance must be an explicit exercise, e.g. we should have hx-inherit. An example in the attached screenshot: Description:
Lesson learned, should not leave the containers/placeholders around because the default inheritance can break stuff in a non trivial way. |
Closing this as since this issue was opened, |
Even though inheritance allows writing more concise code in typical cases, I'd strongly consider turning it off in my projects.
I find it difficult to reason about code because of inheritance when there are nested elements which have different
hx-
attributes and it all behaves in unexpected way. It's extra non-trivial because not all attributes are inherited (for example,hx-post
), so I have to check the documentation for that additionally.I've tried
hx-disinherit="*"
but it seems to have an effect only on immediate children. I.e. I can't set it inbody
to get what I want.Idea: add an extension or a new attribute to disable inheritance in all the children of the element, their children, etc. For example, it could be an attribute
hx-recursive-disinherit="*"
.And then I'd likely want to keep inheritance of, say,
hx-ext="morph"
. So the new toggle should also support more fine-grained configuration, e.g. something likehx-recursive-disinherit="not hx-ext, not hx-some-other-inherited-attr, hx-some-attr-which-should-be-disinherited"
.The text was updated successfully, but these errors were encountered: