[canvas/test] ThemeToggle.tsx: invalid CSS selector causes uncaught exceptions in jsdom #1008

Closed
opened 2026-05-14 13:05:15 +00:00 by core-qa · 0 comments
Member

Bug Description

canvas/src/components/ThemeToggle.tsx:69 uses querySelectorAll("> [role=radio]") — the child combinator > requires a parent selector to its left. In a browser this works because the call context is the element, but jsdom (@asamuzakjp/dom-selector) rejects it with:

SyntaxError: Invalid selector > [role=radio]
  at HTMLDivElementImpl.querySelectorAll
  src/components/ThemeToggle.tsx:69:32

Impact: 5 uncaught exceptions per test run in ThemeToggle.test.tsx. Tests still pass (exit 0) because Vitest does not count uncaught exceptions as failures, but they pollute the test output.

Reproduction

Run cd canvas && npm test -- --run — observe 5 uncaught exceptions from ThemeToggle.test.tsx.

Root Cause

Commit 4929824c (PR #936, WCAG round 3) introduced:

const radiogroup = e.currentTarget.closest("[role=radiogroup]") as HTMLElement | null;
const btns = radiogroup?.querySelectorAll<HTMLButtonElement>("> [role=radio]");

The > [role=radio] selector is malformed. The intent was to select direct-child buttons with role=radio inside radiogroup.

Fix

const btns = radiogroup?.querySelectorAll<HTMLButtonElement>("[role=radio]");

Since the query is already scoped to radiogroup, the > combinator is unnecessary.

Scope

  • Tier: medium
  • Affected file: canvas/src/components/ThemeToggle.tsx
  • Tests: canvas/src/components/__tests__/ThemeToggle.test.tsx
  • Regression introduced: PR #936 (4929824c)
  • Assignee: core-canvas (or triage-operator)
## Bug Description `canvas/src/components/ThemeToggle.tsx:69` uses `querySelectorAll("> [role=radio]")` — the child combinator `>` requires a parent selector to its left. In a browser this works because the call context is the element, but jsdom (`@asamuzakjp/dom-selector`) rejects it with: ``` SyntaxError: Invalid selector > [role=radio] at HTMLDivElementImpl.querySelectorAll src/components/ThemeToggle.tsx:69:32 ``` **Impact:** 5 uncaught exceptions per test run in `ThemeToggle.test.tsx`. Tests still pass (exit 0) because Vitest does not count uncaught exceptions as failures, but they pollute the test output. ## Reproduction Run `cd canvas && npm test -- --run` — observe 5 uncaught exceptions from `ThemeToggle.test.tsx`. ## Root Cause Commit `4929824c` (PR #936, WCAG round 3) introduced: ```ts const radiogroup = e.currentTarget.closest("[role=radiogroup]") as HTMLElement | null; const btns = radiogroup?.querySelectorAll<HTMLButtonElement>("> [role=radio]"); ``` The `> [role=radio]` selector is malformed. The intent was to select direct-child buttons with `role=radio` inside `radiogroup`. ## Fix ```ts const btns = radiogroup?.querySelectorAll<HTMLButtonElement>("[role=radio]"); ``` Since the query is already scoped to `radiogroup`, the `>` combinator is unnecessary. ## Scope - **Tier:** medium - **Affected file:** `canvas/src/components/ThemeToggle.tsx` - **Tests:** `canvas/src/components/__tests__/ThemeToggle.test.tsx` - **Regression introduced:** PR #936 (`4929824c`) - **Assignee:** core-canvas (or triage-operator)
core-qa added the tier:medium label 2026-05-14 13:05:15 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#1008