Skip to content

Commit

Permalink
fix: use fallbackTmpl for all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jhefferman-sfdc committed Jan 31, 2025
1 parent b460d35 commit b5868f1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ const bYieldFromChildGenerator = esTemplateWithYield`
Slotted content is inserted here.
Note that the slotted content will be stored in variables named
`shadowSlottedContent`/`lightSlottedContentMap / scopedSlottedContentMap` which are used below
when the child's generateMarkup function is invoked.
when the child's generateMarkup function is invoked.
*/
is.statement
}
const scopeToken = hasScopedStylesheets ? stylesheetScopeToken : undefined;
const generateMarkup = ${/* Component */ is.identifier}[__SYMBOL__GENERATE_MARKUP];
const tagName = ${/* tag name */ is.literal};
if (!generateMarkup) {
yield* __unimplementedTmpl(${/* tag name */ is.literal}, instance, shadowSlottedContent, ${/* Component */ 3});
yield \`<\${tagName}>\`;
yield* __fallbackTmpl(shadowSlottedContent, lightSlottedContentMap, scopedSlottedContentMap, ${/* Component */ 3}, instance)
yield \`</\${tagName}>\`;
} else {
yield* generateMarkup(
${/* tag name */ 4},
tagName,
childProps,
childAttrs,
shadowSlottedContent,
Expand All @@ -63,7 +67,7 @@ export const Component: Transformer<IrComponent> = function Component(node, cxt)
cxt.import({ default: childComponentLocalName }, importPath);
cxt.import({
SYMBOL__GENERATE_MARKUP: '__SYMBOL__GENERATE_MARKUP',
unimplementedTmpl: '__unimplementedTmpl',
fallbackTmpl: '__fallbackTmpl',
});
const childTagName = node.name;

Expand Down
3 changes: 0 additions & 3 deletions packages/@lwc/ssr-compiler/src/transmogrify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const visitors: Visitors = {
//
// - renderAttrs vs renderAttrsNoYield
// - fallbackTmpl vs fallbackTmplNoYield
// - unimplementedTmpl vs unimplementedTmplNoYield
//
// If this becomes too burdensome to maintain, we can officially deprecate the generator-based approach
// and switch the @lwc/ssr-runtime implementation wholesale over to the no-generator paradigm.
Expand All @@ -137,8 +136,6 @@ const visitors: Visitors = {
node.imported.name = 'fallbackTmplNoYield';
} else if (node.imported.name === 'renderAttrs') {
node.imported.name = 'renderAttrsNoYield';
} else if (node.imported.name === 'unimplementedTmpl') {
node.imported.name = 'unimplementedTmplNoYield';
}
},
};
Expand Down
2 changes: 0 additions & 2 deletions packages/@lwc/ssr-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export {
serverSideRenderComponent,
// renderComponent is an alias for serverSideRenderComponent
serverSideRenderComponent as renderComponent,
unimplementedTmpl,
unimplementedTmplNoYield,
} from './render';
export { normalizeTextContent, renderTextContent } from './render-text-content';
export { hasScopedStaticStylesheets, renderStylesheets } from './styles';
Expand Down
43 changes: 0 additions & 43 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,49 +131,6 @@ export function fallbackTmplNoYield(
}
}

/**
* If a component is incorrectly implemented, and is missing a `generateMarkup` function,
* then use this template as a fallback so the world doesn't explode.
* @example export { Cmp as default }
*/
export function* unimplementedTmpl(
tagName: string,
instance: LightningElement,
shadowSlottedContent: AsyncGeneratorFunction,
Cmp?: LightningElementConstructor
) {
yield `<${tagName}>`;
if (Cmp?.renderMode !== 'light') {
yield '<template shadowrootmode="open"></template>';
if (shadowSlottedContent) {
yield shadowSlottedContent(instance);
}
}
yield `</${tagName}>`;
}

/**
* If a component is incorrectly implemented, and is missing a `generateMarkup` function,
* then use this template as a fallback so the world doesn't explode.
* @example export { Cmp as default }
*/
export function unimplementedTmplNoYield(
emit: (segment: string) => void,
tagName: string,
instance: LightningElement,
shadowSlottedContent: AsyncGeneratorFunction,
Cmp?: LightningElementConstructor
) {
emit(`<${tagName}>`);
if (Cmp?.renderMode !== 'light') {
emit('<template shadowrootmode="open"></template>');
if (shadowSlottedContent) {
shadowSlottedContent(emit, instance);
}
}
emit(`</${tagName}>`);
}

export type GenerateMarkupFn = (
tagName: string,
props: Properties | null,
Expand Down

0 comments on commit b5868f1

Please sign in to comment.