Skip to content

[css-typed-om-1] How should leading whitespace before var() be normalized in CSSUnparsedValue round-tripping? #13792

@janvarga

Description

@janvarga

There appears to be an interop mismatch between engines when setting a value with two leading spaces before a var() reference via Typed OM.

Consider:

document.body.attributeStyleMap.set(
  'width',
  new CSSUnparsedValue(['  ', new CSSVariableReferenceValue('--A')])
);

console.log('|' + document.body.style.width + '|');
console.log('|' + document.body.attributeStyleMap.get('width') + '|');

Current behavior differs across engines:

  • Chrome

    • style.width -> "| var(--A)|"
    • attributeStyleMap.get('width') -> "| var(--A)|"
  • Safari

    • style.width -> "| var(--A)|"
    • attributeStyleMap.get('width') -> "| var(--A)|"
  • Firefox (in progress)

    • style.width -> "|var(--A)|"
    • attributeStyleMap.get('width') -> "|var(--A)|"

So for the initial string segment ' ' (two spaces), engines currently:

  • preserve it exactly,
  • collapse it to a single space,
  • or remove it entirely.

For comparison, plain CSSOM string assignment:

document.body.style.width = "  var(--A)";
console.log('|' + document.body.style.width + '|');

serializes as:

"|var(--A)|"

in all tested browsers.

It seems browsers should consistently normalize leading whitespace in this case, matching CSSOM string parsing/serialization behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions