Skip to content

Commit

Permalink
fix: duplicate behavior for slotted content when no template is prese…
Browse files Browse the repository at this point in the history
…nt (#5174)

* fix: add dangling slot definition

* fix: scoped slot case, nested cases

* fix: review comments

* fix: additional test

* fix: default slotted content

* fix: render shadow slotted content for no template case

* fix: update types

* fix: instance naming
  • Loading branch information
jhefferman-sfdc authored Jan 30, 2025
1 parent d4872a2 commit 4334dc2
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<x-outer>
<x-inner>
</x-inner>
</x-outer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-outer';
export { default } from 'x/outer';
export * from 'x/outer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template lwc:render-mode="light">
<x-inner>
I am default slot
<div slot="foo">I am the foo slot</div>
</x-inner>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<x-outer>
<template shadowrootmode="open">
<x-inner>
<template shadowrootmode="open">
</template>
I am default slot
<div slot="foo">
I am the foo slot
</div>
</x-inner>
</template>
</x-outer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-outer';
export { default } from 'x/outer';
export * from 'x/outer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<x-inner>
I am default slot
<div slot="foo">I am the foo slot</div>
</x-inner>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {}
18 changes: 12 additions & 6 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,33 @@ export function renderAttrsNoYield(
}

export function* fallbackTmpl(
_shadowSlottedContent: unknown,
shadowSlottedContent: AsyncGeneratorFunction,
_lightSlottedContent: unknown,
_scopedSlottedContent: unknown,
Cmp: LightningElementConstructor,
_instance: unknown
instance: unknown
) {
if (Cmp.renderMode !== 'light') {
yield '<template shadowrootmode="open"></template>';
yield `<template shadowrootmode="open"></template>`;
if (shadowSlottedContent) {
yield shadowSlottedContent(instance);
}
}
}

export function fallbackTmplNoYield(
emit: (segment: string) => void,
_shadowSlottedContent: unknown,
shadowSlottedContent: AsyncGeneratorFunction,
_lightSlottedContent: unknown,
_scopedSlottedContent: unknown,
Cmp: LightningElementConstructor,
_instance: unknown
instance: unknown
) {
if (Cmp.renderMode !== 'light') {
emit('<template shadowrootmode="open"></template>');
emit(`<template shadowrootmode="open"></template>`);
if (shadowSlottedContent) {
shadowSlottedContent(emit, instance);
}
}
}

Expand Down

0 comments on commit 4334dc2

Please sign in to comment.