Skip to content

Commit 8eec50f

Browse files
fix(ssr): handle export { Cmp as default } @W-17655297 (#5176)
* fix: allow export { Cmp as default } * test(ssr): update component-as-default to check light and shadow * fix: use fallback if no generateMarkup * fix(ssr): support `export { Cmp as default }` * fix: support slotted content for unimplemented templates * fix: use fallbackTmpl for all cases * Update packages/@lwc/ssr-compiler/src/compile-template/transformers/component/component.ts * Update packages/@lwc/ssr-compiler/src/compile-template/transformers/component/component.ts --------- Co-authored-by: John Hefferman <jhefferman@salesforce.com>
1 parent d78c977 commit 8eec50f

File tree

12 files changed

+77
-27
lines changed

12 files changed

+77
-27
lines changed
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
<x-cmp>
1+
<x-parent>
22
<template shadowrootmode="open">
3+
<x-shadow>
4+
<template shadowrootmode="open">
5+
</template>
6+
</x-shadow>
7+
<x-shadow>
8+
<template shadowrootmode="open">
9+
</template>
10+
<h1>
11+
slotted content
12+
</h1>
13+
</x-shadow>
14+
<x-light>
15+
</x-light>
16+
<x-light>
17+
</x-light>
318
</template>
4-
</x-cmp>
19+
</x-parent>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const tagName = 'x-cmp';
2-
export { default } from 'x/cmp';
3-
export * from 'x/cmp';
1+
export const tagName = 'x-parent';
2+
export { default } from 'x/parent';
3+
export * from 'x/parent';

packages/@lwc/engine-server/src/__tests__/fixtures/exports/component-as-default/modules/x/cmp/cmp.js

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template lwc:render-mode="light">
2+
This template isn't actually used because `export {Component as default}` isn't recognized as an LWC component.
3+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { LightningElement } from 'lwc';
2+
3+
class Light extends LightningElement {
4+
static renderMode = 'light';
5+
}
6+
7+
export { Light as default };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<x-shadow></x-shadow>
3+
<x-shadow><h1>slotted content</h1></x-shadow>
4+
<x-light></x-light>
5+
<x-light><h1>slotted content</h1></x-light>
6+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class Parent extends LightningElement {}

packages/@lwc/engine-server/src/__tests__/fixtures/exports/component-as-default/modules/x/cmp/cmp.html renamed to packages/@lwc/engine-server/src/__tests__/fixtures/exports/component-as-default/modules/x/shadow/shadow.html

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LightningElement } from 'lwc';
2+
3+
class Shadow extends LightningElement {}
4+
5+
export { Shadow as default };

packages/@lwc/ssr-compiler/src/__tests__/utils/expected-failures.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
export const expectedFailures = new Set([
1111
'attribute-global-html/as-component-prop/undeclared/index.js',
1212
'attribute-global-html/as-component-prop/without-@api/index.js',
13-
'exports/component-as-default/index.js',
1413
'known-boolean-attributes/default-def-html-attributes/static-on-component/index.js',
1514
'wire/errors/throws-when-colliding-prop-then-method/index.js',
1615
]);

0 commit comments

Comments
 (0)