fix(compiler-core,runtime-core): preserve slots order on slots instance property#14449
fix(compiler-core,runtime-core): preserve slots order on slots instance property#14449andreww2012 wants to merge 2 commits intovuejs:mainfrom
slots instance property#14449Conversation
📝 WalkthroughWalkthroughThe compiler collects static slot names' template order and emits it to generated render code; the runtime's Changes
Sequence Diagram(s)sequenceDiagram
participant Compiler as Compiler (vSlot transform)
participant Generated as Generated render fn
participant Runtime as runtime.createSlots
participant Component as componentSlots.updateSlots
Compiler->>Generated: emit CREATE_SLOTS(dynamicSlots, needsStable, order?)
Generated->>Runtime: call createSlots(..., dynamicSlots, order?)
Runtime->>Runtime: populate slots object\nif order provided -> delete & reinsert keys per order
Runtime->>Component: return reordered slots object
Component->>Component: clear non-internal keys (compiled/dynamic path)\nreassign new keys preserving insertion order
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
93b464b to
8bc4d14
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/runtime-core/__tests__/componentSlots.spec.ts`:
- Line 501: Remove the leftover debug console.log call that prints
instance.slots from the test; locate the stray statement
"console.log('instance.slots:', instance.slots)" in the componentSlots.spec test
and delete it so tests don’t emit debug output (no other changes to assertions
or setup needed).
8bc4d14 to
c168916
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/compiler-core/src/transforms/vSlot.ts`:
- Around line 390-393: Add unit tests to createSlots.spec.ts that exercise the
createSlots runtime reorder behavior via the createSlots function: (1) a test
with duplicate slot names (simulate v-if/v-else branches) ensuring re-adding the
same slot name is a no-op; (2) a test for mutually exclusive slots where only
the active branch is present and reorder still works; (3) a test where order =
[] and only implicit/default slots exist to verify no changes occur; and (4) a
test where some keys (like '_' or implicit default) are not included in the
order array to confirm they are left untouched. Reference createSlots and the
order parameter in each test and assert the final slots object shape/iteration
order matches expected outcomes.
🧹 Nitpick comments (1)
packages/compiler-core/src/transforms/vSlot.ts (1)
374-394: Consider guarding onslotOrder.lengthinstead ofslotsProperties.length.The current condition (
slotsProperties.length > 0) can be true whileslotOrderis empty — e.g., when the only static slot is the implicit default (added at lines 331/348 but never pushed toslotOrder), or when all explicit template slots have dynamic names. In that scenario an empty[]literal is emitted in the compiled output and forwarded tocreateSlots, adding unnecessary bytes and a no-op runtime path.
slotOrder.length > 0directly expresses the intent ("pass the order array only when there are ordered names") and avoids the empty-array edge case.Suggested change
// `#14425` // Pass slot names to preserve the template ordering - if (slotsProperties.length > 0) { + if (slotOrder.length > 0) { createSlotsArgs.push( createArrayExpression( slotOrder.map(name => createSimpleExpression(name, true)), ), ) }
Fixes #14425
This change ensures the insertion order of slot names on
slotsinstance property matches the slots order in the template. Previously, all dynamic slots were assigned toslotsobject after all non-dynamic slots.Summary by CodeRabbit
Bug Fixes
Tests