Skip to content

Commit a4a7afe

Browse files
fix: addressed review comments, added explanations
1 parent d2047ad commit a4a7afe

File tree

1 file changed

+8
-3
lines changed
  • packages/@lwc/ssr-compiler/src/compile-template/transformers

1 file changed

+8
-3
lines changed

packages/@lwc/ssr-compiler/src/compile-template/transformers/slot.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const bConditionalSlot = esTemplateWithYield`
2828
const slotName = ${/* slotName */ is.expression};
2929
const lightGenerators = lightSlottedContent?.[slotName ?? ""];
3030
const scopedGenerators = scopedSlottedContent?.[slotName ?? ""];
31-
const mismatchedSlots = (isScopedSlot && lightGenerators) || (!isScopedSlot && scopedGenerators);
31+
const mismatchedSlots = isScopedSlot ? lightGenerators : scopedGenerators;
3232
const generators = isScopedSlot ? scopedGenerators : lightGenerators;
3333
3434
// start bookend HTML comment for light DOM slot vfragment
@@ -44,13 +44,18 @@ const bConditionalSlot = esTemplateWithYield`
4444
if (generators) {
4545
for (let i = 0; i < generators.length; i++) {
4646
yield* generators[i](contextfulParent, ${/* scoped slot data */ isNullableOf(is.expression)});
47-
// Bookends after all but last scoped slot data
47+
// Scoped slotted data is separated by bookends. Final bookends are added outside of the loop below.
4848
if (isScopedSlot && i < generators.length - 1) {
4949
yield '<!---->';
5050
yield '<!---->';
5151
}
5252
}
53-
// If there were mismatched slots, do not fallback to the default
53+
/*
54+
If there were mismatched slots, do not fallback to the default. This is required for parity with
55+
engine-core which resets children to an empty array when there are children (mismatched or not).
56+
Because the child nodes are reset, the default slotted content is not rendered in the mismatched slot case.
57+
See https://github.com/salesforce/lwc/blob/master/packages/%40lwc/engine-core/src/framework/api.ts#L238
58+
*/
5459
} else if (!mismatchedSlots) {
5560
// If we're in this else block, then the generator _must_ have yielded
5661
// something. It's impossible for a slottedContent["foo"] to exist

0 commit comments

Comments
 (0)