Fix JoinAttrs not joining attributes in nested groups - #335
Open
milanobrtlik wants to merge 1 commit into
Open
Conversation
JoinAttrs unwrapped g.Group only one level deep, so an attribute nested deeper was never merged. It fell through to the result verbatim, and renderChild, which recurses into groups at any depth, then emitted it as a second attribute of the same name. Browsers keep the first occurrence, so the value was silently dropped. Two-level groups arise from the documented composition pattern: a component that forwards g.Group(children) into JoinAttrs, called by another that does the same. g.Map also returns a Group. The existing group test missed this because it forwards an element rather than an attribute. Unwrap recursively in processNode instead, mirroring renderChild, so JoinAttrs sees exactly what will be rendered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JoinAttrsunwrapsg.Grouponly one level deep, so an attribute nested deeper is nevermerged. It falls through to the result verbatim, and
renderChild, which recurses into groupsat any depth, then emits it as a second attribute of the same name. Browsers keep the first
occurrence, so the value is silently dropped.
Reproduction
Against
main@ d1fd82b:renders
instead of
<div class="party gold hat"></div>. With three levels it degrades further —<div class="a" class="b" class="c d"></div>.Why it comes up
Two-level groups arise from the composition pattern the docs already show: a component that
forwards
g.Group(children)intoJoinAttrs, called by another component that does the same.g.Mapalso returns aGroup, so mapping over data into aJoinAttrscall hits it too. Theexisting group test missed this because it forwards an element rather than an attribute, and
elements are appended to
resulteither way.Fix
Unwrap recursively in
processNode, mirroring whatrenderChilddoes, soJoinAttrsseesexactly what will be rendered. Element order is preserved: non-attribute children stay in place
and the joined attribute lands at the position of the first match, same as before.
Four test cases added — two-level, three-level, nested components, and element order inside
nested groups. Existing tests unchanged, coverage stays at 100%.
The doc comment is updated to say groups are transparent, since the previous wording
("Attributes on non-direct descendants are ignored") no longer describes the behaviour.