Skip to content

Commit

Permalink
fix(ssr): fix rendering of class with scope token (#5072)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Jan 8, 2025
1 parent f29ff6e commit fb5ef00
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,18 @@
</x-grandchild>
</template>
</x-child>
<x-child class="lwc-5h3d35cke7v-host" data-lwc-host-scope-token="lwc-5h3d35cke7v-host">
<template shadowrootmode="open">
<style class="lwc-5h3d35cke7v" type="text/css">
:host {background: blue;}
</style>
<div class="&quot;'<&amp; lwc-5h3d35cke7v">
</div>
<x-grandchild class="&quot;'<&amp; lwc-5h3d35cke7v">
<template shadowrootmode="open">
</template>
</x-grandchild>
</template>
</x-child>
</template>
</x-parent>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<x-child dynamic={isUppercase}></x-child>
<x-child dynamic={isTabs}></x-child>
<x-child dynamic={isNewlines}></x-child>
<x-child dynamic={hasEscapableCharacters}></x-child>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export default class extends LightningElement {
isUppercase = 'FOO BaR';
isTabs = '\tfoo\t';
isNewlines = '\nfoo\n';
// Skipping `>` because it messes up `formatHTML()`, and the important thing is checking
// that we are calling `htmlEscape()` in attribute mode, so checking `<` is sufficient.
hasEscapableCharacters = `"'<&`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// We should slowly drive down these test failures or at least document where we expect the failures
// TODO [#4815]: enable all SSR v2 tests
export const expectedFailures = new Set([
'attribute-class/with-scoped-styles-only-in-child/dynamic/index.js',
'attribute-class/with-scoped-styles/dynamic/index.js',
'attribute-global-html/as-component-prop/undeclared/index.js',
'attribute-global-html/as-component-prop/without-@api/index.js',
'exports/component-as-default/index.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ const bYieldClassDynamicValue = esTemplateWithYield`
const attrValue = normalizeClass(${/* attribute value expression */ is.expression});
const shouldRenderScopeToken = hasScopedStylesheets || hasScopedStaticStylesheets(Cmp);
// Concatenate the scope token with the class attribute value as necessary.
// If either is missing, render the other alone.
let combinedValue = shouldRenderScopeToken ? stylesheetScopeToken : '';
if (attrValue) {
const prefix = shouldRenderScopeToken ? stylesheetScopeToken + ' ' : '';
yield \` class="\${prefix}\${htmlEscape(String(attrValue), true)}"\`;
if (combinedValue) {
combinedValue += ' ';
}
combinedValue += htmlEscape(String(attrValue), true);
}
if (combinedValue) {
yield \` class="\${combinedValue}"\`;
}
}
`<EsBlockStatement>;
Expand Down

0 comments on commit fb5ef00

Please sign in to comment.