Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate behavior for slotted content when no template is present #5174

Merged
merged 9 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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