Repository navigation
Description
Context
Found during the #3855 test-health push (batch e3855-ui-react-04). Assigning a saved document.documentElement.dataset.theme back with dataset.theme = saved when the saved value was undefined writes the literal string "undefined" instead of removing the attribute. #2021 records the same fault for connection-replay.layout.tsx with a native Chromium observation ({before:null,after:"undefined"}). The ui-react-04 batch fixed seven instances in its own shard (review-dialogs, renderer-dispatch, tool-permission, search-results, supporting-files, sent-attachments, saved-transcription).
A grep at d19aec478 on that batch branch (dataset.theme = <saved value> with no undefined guard) finds these instances outside that shard:
afterEach,packages/ui-react/tests/browser/diagrams-renderer.layout.tsx:16afterEachcallback list,packages/ui-react/tests/browser/diagrams-callouts.layout.tsx:40afterEach,packages/ui-react/tests/browser/diagrams-node-link.layout.tsx:12afterEach,packages/ui-react/tests/browser/diagrams-frame.layout.tsx:22afterEach,packages/ui-react/tests/browser/mermaid-content-renderer.layout.tsx:32finally,packages/ui-react/tests/browser/error-boundaries.layout.tsx:225ctx.onTestFinished,packages/ui-react/tests/browser/dictation-notice.pointer.tsx:133ctx.onTestFinished,packages/ui-react/tests/browser/overlay-stacking.pointer.tsx:479
The guarded form already used across the suite is if (saved === undefined) delete document.documentElement.dataset.theme; else document.documentElement.dataset.theme = saved;.
Related: #2021 (the same fault in connection-replay.layout.tsx, kept there).
Scope
Restore an absent theme attribute as absent in the eight cleanups listed above, and in these four that triage found at 91e54be37 with the same unguarded restore of a saved dataset.theme (outside ui-react-04's seven, and not fixed on epic/3855-test-health when triaged):
afterEach,packages/ui-react/tests/browser/code-fences.layout.tsx:16afterEach,packages/ui-react/tests/browser/code-fences-plain.layout.tsx:15afterEach,packages/ui-react/tests/browser/inline-graph.layout.tsx:17afterEach,packages/ui-react/tests/browser/draft-indicator.offline.tsx:65
If another #3855 batch fixes one of these first, leave it. Test code only.
Out of scope
connection-replay.layout.tsx. ui-react: replay suffix cleanup creates a literal undefined theme attribute #2021 owns it.diagrams-renderer.layout.tsx:110, which assigns a literal theme on purpose.- Any change to what these tests assert, to their theme matrices, or to product theme behaviour.
Acceptance criteria
- Each listed cleanup leaves
document.documentElement.hasAttribute("data-theme")false when the attribute was absent before the case, and restores the exact value when one was present. - A grep for unguarded
dataset.theme = <saved value>assignments underpackages/ui-react/testsandpackages/ui-kit/testsreturns only ui-react: replay suffix cleanup creates a literal undefined theme attribute #2021's file (if it is still open) and the seven ui-react-04 sites, until test(ui-react): test-health batch e3855-ui-react-04 #3919 reachesmainthrough Epic: every test file audited once by a test-health push #3855. - Every touched file passes in its pinned browser project.
Verification
bun scripts/test-health.ts measure <file> --runs 2 for each touched file, or the file's bun run test:layout / bun run test:browser project. One native check that the attribute is absent after a case that started without it.
Contract impact
None. Test isolation only.
Triage 2026-11-10 (main 91e54be37): verified the eight cited sites against main (the dictation-notice restore moved to :133); added four more unguarded restores found by the same grep, so the grep criterion can actually pass; state-room.layout.tsx:49 restores previousTheme ?? "dark" on purpose and is not in scope.
Activity
[-]ui-react: eight browser fixtures restore an absent theme as the literal "undefined"[/-][+]ui-react: twelve browser fixtures restore an absent theme as the literal "undefined"[/+]