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): do not render class attribute when dynamic value is null, empty or undefined #4960

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Nov 26, 2024

Details

Fixes two expected failures:

'attribute-class/unstyled/dynamic/index.js'
'attribute-class/with-scoped-styles-only-in-parent/dynamic/index.js'

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🔬 Yes, it does include an observable change.

The class attribute will not be rendered when the dynamic value is null, empty or undefined

GUS work item

@cardoso cardoso requested a review from a team as a code owner November 26, 2024 19:43
Comment on lines -14 to -17
import { DEFAULT_SSR_MODE } from '@lwc/shared';
import { DEFAULT_SSR_MODE, type CompilationMode } from '@lwc/shared';
import { expectedFailures } from './utils/expected-failures';
import type { FeatureFlagName } from '@lwc/features/dist/types';
import type { CompilationMode } from '../index';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this in #4933

Comment on lines -40 to +50
if (combinedScopeToken && attrName === 'class') {
attrValue += ' ' + combinedScopeToken;
hasClassAttribute = true;

if (attrName === 'class') {
if (attrValue === '') {
// If the class attribute is empty, we don't render it.
continue;
}

if (combinedScopeToken) {
attrValue += ' ' + combinedScopeToken;
hasClassAttribute = true;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't normally like to use continue, but some refactoring would be needed to avoid it here.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find! Thanks! 🧸

@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson nolanlawson merged commit 348130f into salesforce:master Nov 26, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants