Skip to content

feat: support string styles through cssText and the style attribute - #110

Merged
dreyfus92 merged 3 commits into
mainfrom
feat/string-styles
Dec 1, 2026
Merged

dreyfus92 merged 3 commits into
mainfrom
feat/string-styles

Conversation

@dreyfus92

@dreyfus92 dreyfus92 commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

preact, vue and solid set string styles with style.cssText, svelte's custom renderer and plain dom code use setAttribute('style', ...), and vue and solid clear styles by removing the attribute. none of that did anything before, so string styles were silently dropped.

this adds cssText (read and write) to the style declaration, plus a small attribute changed hook, like the spec's attribute change steps, that sends style attribute changes to it. writing element.style changes back into the attribute is left for a follow up.

it's the first step toward svelte support, but useful on its own. also selects 8 upstream cssom subtests that pass now.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

commit: dd6a2af

@cowboyd
cowboyd self-requested a review November 30, 2026 16:16
Comment thread packages/ui/src/dom.ts
Comment on lines +478 to +489
function attributeChanged(attr: Attr, value: string | null): void {
const element = attr.ownerElement;
if (element === null || attr.namespaceURI !== null) {
return;
}
switch (attr.localName) {
case 'style':
element.style.cssText = value ?? '';
break;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't have them yet, but would this be a good case to use MutationObserver when we support them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i don't think so, MutationObserver delivers records async, so right after setAttribute('style', ...) reading el.style.color would still give you the old value until the observer runs. the spec keeps them in sync inside the attribute change steps, and MO records get queued from that same algorithm. so once we add MO, this is where we'd queue the record, alongside the switch rather than replacing it

Comment thread packages/ui/wpt.config.ts
'uppercase value',
'overwriting with invalid value',
'use rgb',
// Other cases use unsupported properties, shorthands, or computed styles.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would it take to unlock these other test cases such as shorthands? Would it help to use a more formal CSS parser?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like we'd need a proper inline style parser ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i don't think the parser is the blocker here, those cases skip because we don't support the properties yet (font-size, font-weight, margin) or getComputedStyle. a real parser only matters once a value can contain ; or :, like strings or url(), and none of ours can today. for shorthands, padding is probably the one worth doing first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As long as you see the path forward, sounds good!

Comment thread packages/ui/wpt.config.ts Outdated
"Inline style declaration without whitespace between '!' and 'important'.",
"Style set dynamically via cssText without whitespace between '!' and 'important'.",
"Style set dynamically via cssText with whitespace between '!' and 'important'.",
// The remaining case uses the unsupported background-color property.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should add a note to support the background color property.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good call, tty ops already take a bg so it should mostly be wiring.

@natemoo-re natemoo-re left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree with your responses here! onward!

@dreyfus92
dreyfus92 merged commit a4d35dc into main Dec 1, 2026
9 checks passed
@dreyfus92
dreyfus92 deleted the feat/string-styles branch December 1, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants