fix(ssr-runtime): coerce className to string for non-string values#5766
Open
nikhil6393 wants to merge 1 commit into
Open
fix(ssr-runtime): coerce className to string for non-string values#5766nikhil6393 wants to merge 1 commit into
nikhil6393 wants to merge 1 commit into
Conversation
…alesforce#5093) In browsers, setting element.className to a non-string value (e.g. undefined, null, 0, false) coerces it to the string representation via String(). The SSR runtime was storing the raw value without coercion, diverging from browser behaviour. This fix adds String() coercion inside the className setter in LightningElement so that the SSR runtime matches browser semantics. Fixes salesforce#5093
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5093
In browsers, setting
element.classNameto a non-string value (e.g.undefined,null,0,false) coerces it to its string representation. The SSR v2 runtime (@lwc/ssr-runtime) was storing the raw value without coercion, diverging from browser behaviour.Root cause: The
classNamesetter inLightningElement(SSR v2) storednewValdirectly into#props.classand#attrs.classwithout callingString().Fix
Add
String()coercion inside theclassNamesetter inpackages/@lwc/ssr-runtime/src/lightning-element.ts:Tests
Added unit tests in
packages/@lwc/ssr-runtime/src/__tests__/lightning-element.spec.tscovering:undefined->"undefined"null->"null"0->"0"false->"false"toString()