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

[DO NOT MERGE] Trigger CI for #5027: fix(ssr): missing bookends for slotted lwc:if not at the top-level #5057

Closed
wants to merge 12 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: use irChildrenToEs in getShadowSlottedContent
cardoso committed Dec 12, 2024
commit 320116da0e5616877956393f3d9e9a1df53164ec
21 changes: 15 additions & 6 deletions packages/@lwc/ssr-compiler/src/compile-template/ir-to-es.ts
Original file line number Diff line number Diff line change
@@ -66,14 +66,23 @@ const transformers: Transformers = {
Lwc: LwcComponent,
};

export function irChildrenToEs(children: IrChildNode[], cxt: TransformerContext): EsStatement[] {
const result = children.flatMap((child, idx) => {
cxt.prevSibling = children[idx - 1];
cxt.nextSibling = children[idx + 1];
return irToEs(child, cxt);
});
export function irChildrenToEs(
children: IrChildNode[],
cxt: TransformerContext,
cb?: (child: IrChildNode) => void
): EsStatement[] {
const result: EsStatement[] = [];

for (let i = 0; i < children.length; i++) {
cxt.prevSibling = children[i - 1];
cxt.nextSibling = children[i + 1];
cb?.(children[i]);
result.push(...irToEs(children[i], cxt));
}

cxt.prevSibling = undefined;
cxt.nextSibling = undefined;

return result;
}

Original file line number Diff line number Diff line change
@@ -79,11 +79,10 @@ const bAddLightContent = esTemplate`

function getShadowSlottedContent(slottableChildren: IrChildNode[], cxt: TransformerContext) {
return optimizeAdjacentYieldStmts(
slottableChildren.flatMap((child) => {
irChildrenToEs(slottableChildren, cxt, (child) => {
if (child.type === 'ExternalComponent') {
cxt.isSlotted = false;
}
return irToEs(child, cxt);
})
);
}