Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): fix style attribute rendering #5061

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export const expectedFailures = new Set([
'attribute-component-global-html/index.js',
'attribute-global-html/as-component-prop/undeclared/index.js',
'attribute-global-html/as-component-prop/without-@api/index.js',
'attribute-style/basic/index.js',
'attribute-style/dynamic/index.js',
'exports/component-as-default/index.js',
'known-boolean-attributes/default-def-html-attributes/static-on-component/index.js',
'render-dynamic-value/index.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const bYieldDynamicValue = esTemplateWithYield`
attrValue = shouldNormalize ? 0 : attrValue;
}

// Backwards compatibility with historical patchStyleAttribute() behavior:
// https://github.com/salesforce/lwc/blob/59e2c6c/packages/%40lwc/engine-core/src/framework/modules/computed-style-attr.ts#L40
if (attrName === 'style' && (typeof attrValue !== 'string' || attrValue === '')) {
attrValue = undefined;
}

if (attrValue !== undefined && attrValue !== null) {
yield ' ' + attrName;

Expand Down
8 changes: 8 additions & 0 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function renderAttrsPrivate(

for (const attrName of getOwnPropertyNames(attrs)) {
let attrValue = attrs[attrName];

// Backwards compatibility with historical patchStyleAttribute() behavior:
// https://github.com/salesforce/lwc/blob/59e2c6c/packages/%40lwc/engine-core/src/framework/modules/computed-style-attr.ts#L40
if (attrName === 'style' && (!isString(attrValue) || attrValue === '')) {
// If the style attribute is invalid, we don't render it.
continue;
}

if (isNull(attrValue) || isUndefined(attrValue)) {
attrValue = '';
} else if (!isString(attrValue)) {
Expand Down