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

chore: simplify style dedupe config #5271

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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"
}
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
18 changes: 11 additions & 7 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,26 @@ 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;
}
}
}

export async function serverSideRenderComponent(
tagName: string,
Component: ComponentWithGenerateMarkup,
props: Properties = {},
styleDedupePrefix = '',
styleDedupeIsEnabled = false,
styleDedupe: string | boolean = false,
mode: CompilationMode = DEFAULT_SSR_MODE
): Promise<string> {
if (typeof tagName !== 'string') {
Expand All @@ -222,7 +226,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
Loading