Skip to content

fix(dom-renderer): use setAttribute for kebab-case data keys#44

Merged
chiefcll merged 1 commit into
mainfrom
fix/dataset-kebab-case-setattribute
Jul 17, 2026
Merged

fix(dom-renderer): use setAttribute for kebab-case data keys#44
chiefcll merged 1 commit into
mainfrom
fix/dataset-kebab-case-setattribute

Conversation

@chiefcll

Copy link
Copy Markdown
Contributor

What

updateNodeData in the DOM renderer wrote data props via node.div.dataset[key]. Switched to node.div.setAttribute('data-' + key, ...).

Why

dataset[key] (DOMStringMap) requires the key to already be camelCase. The spec mandates a SyntaxError when the property name contains a hyphen followed by an ASCII lowercase letter, so writing a kebab-case key like section-id crashes updateNodeData in every conformant browser — not WebOS-specific (reproduced in a regular desktop browser and in jsdom).

Our data props are passed as kebab-case, data-attribute-style keys, so setAttribute('data-' + key, ...) is the correct path. It's also consistent with the removeAttribute('data-' + key) branch right above it.

Bonus fix

The set/remove branches were already inconsistent for camelCase keys (e.g. the internal testId):

  • old set: dataset['testId'] → wrote data-test-id
  • remove: removeAttribute('data-testId') → lowercased to data-testidnever matched, so removal silently no-op'd

Routing both through the literal 'data-' + key makes set and remove round-trip correctly.

Reviewer note

For camelCase keys the resulting attribute name changes from the auto-kebab'd data-test-id to the lowercased literal data-testid. In practice the only internal camelCase key is testId, and data-testid is the conventional testing attribute (matches @testing-library's default). Flag if any consumer queries [data-test-id] specifically.

Testing

  • npm run build — succeeds
  • npm test — 136/136 passing

🤖 Generated with Claude Code

dataset[key] requires the key to already be camelCase; DOMStringMap
throws a SyntaxError for hyphenated property names (e.g. "section-id").
Data props are passed as kebab-case keys, so writing them via dataset
crashes updateNodeData in every conformant browser.

Use setAttribute('data-' + key, ...) instead, consistent with the
removeAttribute branch above it. This also fixes a latent set/remove
asymmetry for camelCase keys, where the set path wrote data-test-id
while the remove path targeted data-testid and silently no-op'd.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chiefcll
chiefcll merged commit dc924e8 into main Jul 17, 2026
1 check passed
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.

1 participant