Skip to content

Commit 2af380f

Browse files
committed
fix(prerender): fix slot relocation and inline styles
1 parent dcd49c0 commit 2af380f

File tree

6 files changed

+18
-31
lines changed

6 files changed

+18
-31
lines changed

src/compiler/output-targets/dist-hydrate-script/hydrate-build-conditionals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getBuildFeatures } from '../../app-core/app-data';
44
export const getHydrateBuildConditionals = (cmps: d.ComponentCompilerMeta[]) => {
55
const build = getBuildFeatures(cmps) as d.BuildConditionals;
66

7+
build.slotRelocation = true;
78
build.lazyLoad = true;
89
build.hydrateServerSide = true;
910
build.cssVarShim = false;

src/compiler/transformers/add-static-style.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import ts from 'typescript';
1111
* static get style() { return "styles"; }
1212
* }
1313
*/
14-
export const addStaticStyleGetterWithinClass = (classMembers: ts.ClassElement[], cmp: d.ComponentCompilerMeta) => {
15-
const styleLiteral = getStyleLiteral(cmp);
14+
export const addStaticStyleGetterWithinClass = (classMembers: ts.ClassElement[], cmp: d.ComponentCompilerMeta, commentOriginalSelector: boolean) => {
15+
const styleLiteral = getStyleLiteral(cmp, commentOriginalSelector);
1616
if (styleLiteral) {
1717
classMembers.push(createStaticGetter('style', styleLiteral));
1818
}
@@ -23,35 +23,35 @@ export const addStaticStyleGetterWithinClass = (classMembers: ts.ClassElement[],
2323
* const MyComponent = class {}
2424
* MyComponent.style = "styles";
2525
*/
26-
export const addStaticStylePropertyToClass = (styleStatements: ts.Statement[], cmp: d.ComponentCompilerMeta) => {
27-
const styleLiteral = getStyleLiteral(cmp);
26+
export const addStaticStylePropertyToClass = (styleStatements: ts.Statement[], cmp: d.ComponentCompilerMeta, commentOriginalSelector: boolean) => {
27+
const styleLiteral = getStyleLiteral(cmp, commentOriginalSelector);
2828
if (styleLiteral) {
2929
const statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier(cmp.componentClassName), 'style'), styleLiteral));
3030
styleStatements.push(statement);
3131
}
3232
};
3333

34-
const getStyleLiteral = (cmp: d.ComponentCompilerMeta) => {
34+
const getStyleLiteral = (cmp: d.ComponentCompilerMeta, commentOriginalSelector: boolean) => {
3535
if (Array.isArray(cmp.styles) && cmp.styles.length > 0) {
3636
if (cmp.styles.length > 1 || (cmp.styles.length === 1 && cmp.styles[0].modeName !== DEFAULT_STYLE_MODE)) {
3737
// multiple style modes
38-
return getMultipleModeStyle(cmp, cmp.styles);
38+
return getMultipleModeStyle(cmp, cmp.styles, commentOriginalSelector);
3939
} else {
4040
// single style
41-
return getSingleStyle(cmp, cmp.styles[0]);
41+
return getSingleStyle(cmp, cmp.styles[0], commentOriginalSelector);
4242
}
4343
}
4444
return null;
4545
};
4646

47-
const getMultipleModeStyle = (cmp: d.ComponentCompilerMeta, styles: d.StyleCompiler[]) => {
47+
const getMultipleModeStyle = (cmp: d.ComponentCompilerMeta, styles: d.StyleCompiler[], commentOriginalSelector: boolean) => {
4848
const styleModes: ts.ObjectLiteralElementLike[] = [];
4949

5050
styles.forEach(style => {
5151
if (typeof style.styleStr === 'string') {
5252
// inline the style string
5353
// static get style() { return { ios: "string" }; }
54-
const styleLiteral = createStyleLiteral(cmp, style);
54+
const styleLiteral = createStyleLiteral(cmp, style, commentOriginalSelector);
5555
const propStr = createPropertyAssignment(style.modeName, styleLiteral);
5656
styleModes.push(propStr);
5757
} else if (typeof style.styleIdentifier === 'string') {
@@ -79,11 +79,11 @@ const createPropertyAssignment = (mode: string, initializer: ts.Expression) => {
7979
return node;
8080
};
8181

82-
const getSingleStyle = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler) => {
82+
const getSingleStyle = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler, commentOriginalSelector: boolean) => {
8383
if (typeof style.styleStr === 'string') {
8484
// inline the style string
8585
// static get style() { return "string"; }
86-
return createStyleLiteral(cmp, style);
86+
return createStyleLiteral(cmp, style, commentOriginalSelector);
8787
}
8888

8989
if (typeof style.styleIdentifier === 'string') {
@@ -103,11 +103,11 @@ const getSingleStyle = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler) =>
103103
return null;
104104
};
105105

106-
const createStyleLiteral = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler) => {
107-
if (cmp.encapsulation === 'scoped') {
106+
const createStyleLiteral = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler, commentOriginalSelector: boolean) => {
107+
if (cmp.encapsulation === 'scoped' || (commentOriginalSelector && cmp.encapsulation === 'shadow')) {
108108
// scope the css first
109109
const scopeId = getScopeId(cmp.tagName, style.modeName);
110-
return ts.createStringLiteral(scopeCss(style.styleStr, scopeId, false));
110+
return ts.createStringLiteral(scopeCss(style.styleStr, scopeId, commentOriginalSelector));
111111
}
112112

113113
return ts.createStringLiteral(style.styleStr);

src/compiler/transformers/component-hydrate/hydrate-runtime-cmp-meta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const addHydrateRuntimeCmpMeta = (classMembers: ts.ClassElement[], cmp: d
1919
cmpMeta.$flags$ |= CMP_FLAGS.needsShadowDomShim;
2020
}
2121
const staticMember = createStaticGetter('cmpMeta', convertValueToLiteral(cmpMeta));
22-
addStaticStyleGetterWithinClass(classMembers, cmp);
22+
const commentOriginalSelector = cmp.encapsulation === 'shadow';
23+
addStaticStyleGetterWithinClass(classMembers, cmp, commentOriginalSelector);
2324

2425
classMembers.push(staticMember);
2526
};

src/compiler/transformers/component-lazy/lazy-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const updateLazyComponentMembers = (
3434
transformHostData(classMembers, moduleFile);
3535

3636
if (transformOpts.style === 'static') {
37-
addStaticStylePropertyToClass(styleStatements, cmp);
37+
addStaticStylePropertyToClass(styleStatements, cmp, false);
3838
}
3939

4040
return classMembers;

src/compiler/transformers/static-to-meta/styles.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export const parseStaticStyles = (compilerCtx: d.CompilerCtx, tagName: string, c
2121
styleId: null,
2222
styleStr: parsedStyle,
2323
styleIdentifier: null,
24-
compiledStyleText: null,
25-
compiledStyleTextScoped: null,
26-
compiledStyleTextScopedCommented: null,
2724
externalStyles: [],
2825
});
2926
compilerCtx.styleModeNames.add(DEFAULT_STYLE_MODE);
@@ -40,9 +37,6 @@ export const parseStaticStyles = (compilerCtx: d.CompilerCtx, tagName: string, c
4037
styleId: null,
4138
styleStr: parsedStyleMode,
4239
styleIdentifier: null,
43-
compiledStyleText: null,
44-
compiledStyleTextScoped: null,
45-
compiledStyleTextScopedCommented: null,
4640
externalStyles: [],
4741
});
4842
} else {
@@ -73,9 +67,6 @@ export const parseStaticStyles = (compilerCtx: d.CompilerCtx, tagName: string, c
7367
styleId: null,
7468
styleStr: null,
7569
styleIdentifier: null,
76-
compiledStyleText: null,
77-
compiledStyleTextScoped: null,
78-
compiledStyleTextScopedCommented: null,
7970
externalStyles: externalStyles,
8071
};
8172

@@ -96,9 +87,6 @@ const parseStyleIdentifier = (parsedStyle: ConvertIdentifier, modeName: string)
9687
styleId: null,
9788
styleStr: null,
9889
styleIdentifier: parsedStyle.__escapedText,
99-
compiledStyleText: null,
100-
compiledStyleTextScoped: null,
101-
compiledStyleTextScopedCommented: null,
10290
externalStyles: [],
10391
};
10492
return style;

src/declarations/stencil-private.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,9 +1922,6 @@ export interface StyleCompiler {
19221922
styleStr: string;
19231923
styleIdentifier: string;
19241924
externalStyles: ExternalStyleCompiler[];
1925-
compiledStyleText: string;
1926-
compiledStyleTextScoped: string;
1927-
compiledStyleTextScopedCommented: string;
19281925
}
19291926

19301927
export interface ExternalStyleCompiler {

0 commit comments

Comments
 (0)