Skip to content

Commit 5b0b148

Browse files
authored
fix(ssr): avoid reserved keyword collision (#5108)
1 parent dc9f7d3 commit 5b0b148

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

packages/@lwc/engine-server/src/__tests__/fixtures/reserved-keywords/error.txt

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<x-cmp>
2+
<template shadowrootmode="open">
3+
<h1>
4+
hello
5+
</h1>
6+
</template>
7+
</x-cmp>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const tagName = 'x-cmp';
2+
export { default } from 'x/cmp';
3+
export * from 'x/cmp';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<h1>hello</h1>
3+
</template>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { LightningElement } from 'lwc';
2+
3+
const privateFields = undefined;
4+
const publicFields = undefined;
5+
const stylesheetScopeToken = undefined;
6+
const hasScopedStylesheets = undefined;
7+
const defaultScopedStylesheets = undefined;
8+
9+
export default class extends LightningElement {
10+
connectedCallback() {
11+
// just use the variables to avoid them being tree-shaken
12+
Object.assign(
13+
{},
14+
{
15+
privateFields,
16+
publicFields,
17+
stylesheetScopeToken,
18+
hasScopedStylesheets,
19+
defaultScopedStylesheets,
20+
}
21+
);
22+
}
23+
}

packages/@lwc/ssr-compiler/src/compile-js/generate-markup.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import type { Program, Statement, IfStatement } from 'estree';
1515
import type { ComponentMetaState } from './types';
1616

1717
const bGenerateMarkup = esTemplate`
18-
const publicFields = new Set(${/*public fields*/ is.arrayExpression});
19-
const privateFields = new Set(${/*private fields*/ is.arrayExpression});
18+
// These variables may mix with component-authored variables, so should be reasonably unique
19+
const __lwcPublicFields__ = new Set(${/*public fields*/ is.arrayExpression});
20+
const __lwcPrivateFields__ = new Set(${/*private fields*/ is.arrayExpression});
2021
2122
async function* generateMarkup(
2223
tagName,
@@ -38,7 +39,12 @@ const bGenerateMarkup = esTemplate`
3839
__establishContextfulRelationship(contextfulParent, instance);
3940
${/*connect wire*/ is.statement}
4041
41-
instance[__SYMBOL__SET_INTERNALS](props, attrs, publicFields, privateFields);
42+
instance[__SYMBOL__SET_INTERNALS](
43+
props,
44+
attrs,
45+
__lwcPublicFields__,
46+
__lwcPrivateFields__,
47+
);
4248
instance.isConnected = true;
4349
if (instance.connectedCallback) {
4450
__mutationTracker.enable(instance);

0 commit comments

Comments
 (0)