Skip to content
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
@@ -1,4 +1,4 @@
{
"entry": "x/parent",
"styleDedupePrefix": "island1"
"styleDedupe": "island1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ async function getSsrCode(moduleCode, testConfig, filename) {
${testConfig};
config = config || {};
${moduleCode};
moduleOutput = LWC.renderComponent('x-${COMPONENT_UNDER_TEST}-${guid++}', Main, config.props || {}, 'sync');`,
moduleOutput = LWC.renderComponent(
'x-${COMPONENT_UNDER_TEST}-${guid++}',
Main,
config.props || {},
false,
'sync'
);`,
{ filename }
);

Expand Down
5 changes: 2 additions & 3 deletions packages/@lwc/ssr-compiler/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface FixtureConfig {
};

/** The string used to uniquely identify one set of dedupe IDs with multiple SSR islands */
styleDedupePrefix?: string;
styleDedupe?: string;
}

vi.mock('@lwc/ssr-runtime', async () => {
Expand Down Expand Up @@ -127,8 +127,7 @@ describe.concurrent('fixtures', () => {
'fixture-test',
module,
config?.props ?? {},
config?.styleDedupePrefix ?? '',
true,
config?.styleDedupe ?? true,
SSR_MODE
)
);
Expand Down
37 changes: 30 additions & 7 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,47 @@ interface ComponentWithGenerateMarkup extends LightningElementConstructor {

export class RenderContext {
styleDedupeIsEnabled: boolean;
stylesheetToId = new WeakMap<Stylesheet, string>();
styleDedupePrefix: string;
stylesheetToId = new WeakMap<Stylesheet, string>();
nextId = 0;

constructor(styleDedupePrefix: string, styleDedupeIsEnabled: boolean) {
this.styleDedupeIsEnabled = styleDedupeIsEnabled;
this.styleDedupePrefix = styleDedupePrefix;
constructor(styleDedupe: string | boolean) {
if (styleDedupe || styleDedupe === '') {
this.styleDedupePrefix = typeof styleDedupe === 'string' ? styleDedupe : '';
this.styleDedupeIsEnabled = true;
} else {
this.styleDedupePrefix = '';
this.styleDedupeIsEnabled = false;
}
}
}

/**
* Create a string representing an LWC component for server-side rendering.
* @param tagName The HTML tag name of the component
* @param Component The `LightningElement` component constructor
* @param props HTML attributes to provide for the root component
* @param styleDedupe Provide a string key or `true` to enable style deduping via the `<lwc-style>`
* helper. The key is used to avoid collisions of global IDs.
* @param mode SSR render mode. Can be 'sync', 'async' or 'asyncYield'. Must match the render mode
* used to compile your component.
* @returns String representation of the component
*/
export async function serverSideRenderComponent(
tagName: string,
Component: ComponentWithGenerateMarkup,
props: Properties = {},
styleDedupePrefix = '',
styleDedupeIsEnabled = false,
styleDedupe: string | boolean = false,
mode: CompilationMode = DEFAULT_SSR_MODE
): Promise<string> {
// TODO [#5309]: Remove this warning after a single release
if (process.env.NODE_ENV !== 'production') {
if (arguments.length === 6 || !['sync', 'async', 'asyncYield'].includes(mode)) {
throw new Error(
"The signature for @lwc/ssr-runtime's `renderComponent` has changed. There is now only one parameter for style dedupe."
);
}
}
if (typeof tagName !== 'string') {
throw new Error(`tagName must be a string, found: ${tagName}`);
}
Expand All @@ -222,7 +245,7 @@ export async function serverSideRenderComponent(
markup += segment;
};

emit.cxt = new RenderContext(styleDedupePrefix, styleDedupeIsEnabled);
emit.cxt = new RenderContext(styleDedupe);

if (!generateMarkup) {
// If a non-component is accidentally provided, render an empty template
Expand Down