perf(web,babel-plugin,compiler): merge adjacent sibling templates - #3342
perf(web,babel-plugin,compiler): merge adjacent sibling templates#3342nickshiro wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 7db338d The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Summary
ref #3055
Merge adjacent fully static DOM elements in a JSX fragment into a single template.
Previously:
created and cloned two independent templates. It now compiles to a single multi-root template:
Implementation
Detect maximal runs of adjacent, fully static DOM roots during fragment lowering.
Combine those roots into one template while explicitly closing every non-void root.
Preserve the external fragment shape by returning the cloned roots as a Node[].
Add bit 4 to the internal template() flag:
Flags remain composable, so 5 represents a multi-root template that requires importNode.
Keep the existing single-root cloning path unchanged and select the cloning strategy when the factory is created rather than branching for every clone.
Implement the same lowering in both the Babel plugin and the native Oxc compiler.
Support both generate: "dom" and generate: "dynamic" when the selected renderer is DOM.
The optimization is deliberately limited to safe static runs. Expressions, components, meaningful text, dynamic attributes, effects, refs, spreads, and wrapped SVG/MathML partials break the group. Hydratable
output is unchanged.
Added coverage for:
How did you test this change?