Skip to content

Commit

Permalink
fix(ssr): avoid reserved keyword collision (#5108)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Jan 8, 2025
1 parent dc9f7d3 commit 5b0b148
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<x-cmp>
<template shadowrootmode="open">
<h1>
hello
</h1>
</template>
</x-cmp>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-cmp';
export { default } from 'x/cmp';
export * from 'x/cmp';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>hello</h1>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LightningElement } from 'lwc';

const privateFields = undefined;
const publicFields = undefined;
const stylesheetScopeToken = undefined;
const hasScopedStylesheets = undefined;
const defaultScopedStylesheets = undefined;

export default class extends LightningElement {
connectedCallback() {
// just use the variables to avoid them being tree-shaken
Object.assign(
{},
{
privateFields,
publicFields,
stylesheetScopeToken,
hasScopedStylesheets,
defaultScopedStylesheets,
}
);
}
}
12 changes: 9 additions & 3 deletions packages/@lwc/ssr-compiler/src/compile-js/generate-markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import type { Program, Statement, IfStatement } from 'estree';
import type { ComponentMetaState } from './types';

const bGenerateMarkup = esTemplate`
const publicFields = new Set(${/*public fields*/ is.arrayExpression});
const privateFields = new Set(${/*private fields*/ is.arrayExpression});
// These variables may mix with component-authored variables, so should be reasonably unique
const __lwcPublicFields__ = new Set(${/*public fields*/ is.arrayExpression});
const __lwcPrivateFields__ = new Set(${/*private fields*/ is.arrayExpression});
async function* generateMarkup(
tagName,
Expand All @@ -38,7 +39,12 @@ const bGenerateMarkup = esTemplate`
__establishContextfulRelationship(contextfulParent, instance);
${/*connect wire*/ is.statement}
instance[__SYMBOL__SET_INTERNALS](props, attrs, publicFields, privateFields);
instance[__SYMBOL__SET_INTERNALS](
props,
attrs,
__lwcPublicFields__,
__lwcPrivateFields__,
);
instance.isConnected = true;
if (instance.connectedCallback) {
__mutationTracker.enable(instance);
Expand Down

0 comments on commit 5b0b148

Please sign in to comment.