Skip to content

Commit

Permalink
fix(ssr): normalize class in child attrs (#4953)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 26, 2024
1 parent 4fc79b4 commit dbbc15c
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 1 deletion.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<x-parent>
<template shadowrootmode="open">
<x-child class="button__icon">
<template shadowrootmode="open">
</template>
</x-child>
</template>
</x-parent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template></template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<x-child class={computedClassNames}></x-child>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LightningElement } from 'lwc';

export default class CustomButton extends LightningElement {
get computedClassNames() {
return {
button__icon: true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<x-parent>
<template shadowrootmode="open">
<x-child class="button__icon">
<template shadowrootmode="open">
</template>
</x-child>
</template>
</x-parent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template></template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<lwc:component lwc:is={ctor} class={computedClassNames}></lwc:component>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LightningElement } from 'lwc';
import xChild from 'x/child';

export default class CustomButton extends LightningElement {
ctor = xChild;
get computedClassNames() {
return {
button__icon: true
}
}
}
8 changes: 7 additions & 1 deletion packages/@lwc/ssr-compiler/src/compile-template/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ export function getChildAttrsOrProps(

return b.property('init', key, b.literal(type === 'Attribute' ? '' : value.value));
} else if (value.type === 'Identifier' || value.type === 'MemberExpression') {
const propValue = expressionIrToEs(value, cxt);
let propValue = expressionIrToEs(value, cxt);

if (name === 'class') {
cxt.import('normalizeClass');
propValue = b.callExpression(b.identifier('normalizeClass'), [propValue]);
}

return b.property('init', key, propValue);
}
throw new Error(`Unimplemented child attr IR node type: ${value.type}`);
Expand Down

0 comments on commit dbbc15c

Please sign in to comment.