Skip to content

fix(Tooltip): Text content keeps contrast on the inverted surface - #12410

Draft
cixzhang wants to merge 9 commits into
mainfrom
fix-tooltip-content-contrast
Draft

cixzhang wants to merge 9 commits into
mainfrom
fix-tooltip-content-contrast

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

User impact

An app that puts Text (or another token-colored component) in a Tooltip's content, as the Tooltip docs show, gets an empty-looking tooltip. The text takes the page theme's primary text color, which is the same color as the tooltip's inverted surface, so the contrast is 1:1 in light and dark. Readers who hover or focus the trigger see a blank box. Plain-string content is not affected. After this change, Text content reads on the tooltip surface in every shipped theme in both modes, and plain text looks exactly as before.

Problem and solution fit

  • Why does it fail? The tooltip paints --color-background-inverted and gives its own text --color-background-surface. The supplied content renders straight into that surface with no media context. Text sets its own color from --color-text-primary, and that token still resolves against the page theme, which gives the color of the surface.
  • Why does it harm the task? A tooltip exists to show its words. With Text content, they are invisible, and the docs example is that case.
  • Why does it matter? Content follows the docs, so apps ship blank tooltips without knowing it.

The fix gives the content the tokens of the media side that reads on the painted surface, as Toast's content already gets them. Before the measurement (on the server and in the first frame), the side comes from the theme's resolved inverted surface color, and otherwise from the color mode. The content does not take MediaTheme's own text color: inherited text, a plain string or bare text beside other elements, keeps the tooltip surface's color, so a theme's tooltip color still reaches it. This approach comes from the root cause given in the original report.

Expected behavior and authority

  • component:Tooltip FR1: the content renders on the owned inverted surface. Its Design relationships row states the surface's text color, which inherited text keeps.
  • spec:AST-020 FR1 (WCAG 1.4.3 text contrast) for the content on that surface.
  • architecture:theme-application INV8 (a media surface changes local tokens only) and the MediaTheme docs, which name tooltips as an inverted surface it serves. Toast's content already renders this way.

Smallest restoration

  • theme/MediaTokens.tsx: an internal MediaTokens component (not exported from the package). It sets a media side's tokens without MediaTheme's text color. It has its own module, so the tooltip does not load MediaTheme and its auto mode.
  • hooks/useAutoMediaMode.ts: the shared measurement re-measures when the nearest Theme value changes, instead of reading the resolved tokens. A scheme change also moves the painted backdrop, which the measurement already compares. Toast is unchanged: main's Toast picks its own side before it measures.
  • Tooltip/useTooltip.tsx: string and number content renders as before, with no wrapper. Other content renders inside a small internal TooltipMediaContent (Tooltip/TooltipMediaContent.tsx), which renders MediaTokens:
    • Before a measurement, the side is the one opposite the color mode, as the inverted surface is in every shipped theme.
    • The measurement (Tooltip/tooltipSurfaceSide.tsx) loads after the first paint, measures the painted surface when the tooltip shows, and corrects the side before that frame paints.
    • A MediaTheme inside the content sets its own side for what it holds.
  • The CLI's bundled copies of the Gothic and Matcha themes are regenerated (pnpm bundle:cli-themes).
  • Gothic and Matcha: secondary text on a light media surface is darker (onLight tokens), because their light-mode secondary text falls below 4.5:1 on their tooltip surface (Gothic 2.32:1, Matcha dark 3.46:1). Gothic uses its existing neutral.dark[50] (5.04:1). Matcha uses neutral.light[20] (5.75:1); it is also Matcha's primary text color on a light media surface, because no lighter stop reaches 4.5:1 there.
  • component:Tooltip: the Tooltip text row says that content reads the media side's tokens and inherited text keeps the surface color.
  • No new prop, export, or data attribute.

Evidence

  • Reproduction before the change: <Text type="body"> content measures 1.00:1 to 1.12:1 on main in every theme and mode below.
  • Result after the change: body and secondary Text reach at least 4.80:1, and plain strings keep their exact color and ratio from main.
  • Regression tests: Tooltip.mediaTheme.test.tsx asserts the media side around Text content under dark, light and unresolvable surfaces (four cases fail without the wrapper) and that a caller MediaTheme is kept. TooltipContentContrast.a11y.chromium.spec.ts opens the RichContent story in every shipped theme, light and dark, and requires 4.5:1 for every text run and 3:1 for the icon, measured with motion held still so the entrance fade is over; a second test requires a plain string and bare text beside an element to keep the tooltip surface's color.

Chrome stills (main vs this head)

Headless Chrome 157 on Linux, a production Vite build of Core from source at main (96687ea2fb) and at this head. Each tooltip holds the docs' <Text type="body"> example, a secondary Text, or a plain string. Each ratio is measured in the page: the text's computed color against the tooltip surface's computed background.

Theme main This head
Neutral, light
body 1.12:1, secondary 2.02:1, plain 18.78:1

body 18.78:1, secondary 7.01:1, plain 18.78:1
Neutral, dark
body 1.00:1, secondary 2.68:1, plain 15.13:1

body 18.88:1, secondary 9.29:1, plain 15.13:1
Gothic (dark only)
body 1.00:1, secondary 2.32:1, plain 16.30:1

body 16.30:1, secondary 5.04:1, plain 16.30:1
Matcha, light
body 1.00:1, secondary 1.66:1, plain 9.77:1

body 9.77:1, secondary 4.80:1, plain 9.77:1
Matcha, dark
body 1.00:1, secondary 1.20:1, plain 10.13:1

body 5.75:1, secondary 5.75:1, plain 10.13:1

Plain-string and number content renders as on main: it skips the media wrapper, so the DOM and the pixels are the same. Each pair below is byte-identical (same PNG SHA-1), measured at main (be5d290db9) and this head:

Theme and content main This head
Neutral, light, plain string 18.78:1 18.78:1
Neutral, light, number 42 18.78:1 18.78:1
Neutral, dark, plain string 15.13:1 15.13:1
Neutral, dark, number 42 15.13:1 15.13:1
Gothic (dark only), plain string 16.30:1 16.30:1
Gothic (dark only), number 42 16.30:1 16.30:1
Matcha, light, plain string 9.77:1 9.77:1
Matcha, light, number 42 9.77:1 9.77:1
Matcha, dark, plain string 10.13:1 10.13:1
Matcha, dark, number 42 10.13:1 10.13:1

The Gothic and Matcha change also reaches their other light media surfaces. Secondary Text in a Toast card and in an inverted panel under MediaTheme mode="auto", measured the same way (Matcha light mode puts those surfaces on the dark side, so it is unchanged):

Theme main This head
Gothic (dark only)
Toast 2.32:1, panel 2.32:1

Toast 5.04:1, panel 5.04:1
Matcha, light
Toast 4.80:1, panel 4.80:1

Toast 4.80:1, panel 4.80:1
Matcha, dark
Toast 3.46:1, panel 3.46:1

Toast 5.75:1, panel 5.75:1

Gothic is a dark-only theme, so it has one row.

Scope

Components: Tooltip (useTooltip, and through it every component that renders a tooltip), Toast (shared fallback, no behavior change), the Gothic and Matcha themes

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

First-load size

First-load JavaScript (gzip, bytes) per page that imports one component, measured with scripts/measure-reference-pages.mjs against main at 2535488b:

Entry Change
Button +410
IconButton +415
Link +1,072
Table +1,033
CheckboxList +370
Selector +994
DropdownMenu +988

The remainder is the wrapper, the pre-measurement side and the measurement loader. The color measurement itself is in a separate chunk. (Before this change, reading useTheme() cost about 12 KB on each entry.)

First-show check

A cold first show is the worst case: the tooltip opens before the measurement chunk has arrived. The check serves a build with that chunk removed, then opens a Text tooltip in real Chrome 157 (neutral theme):

Build Dark mode Light mode
Measurement chunk removed 18.88:1 18.78:1
Full build 18.88:1 18.78:1

There is no flash: before the measurement, the side is the one opposite the color mode, and it reads the same as the measured side. A fixed dark side was rejected earlier because it read 1.00:1 in dark mode.

Stills at this head match the reviewed values: neutral light 18.78 and 7.01, neutral dark 18.88 and 9.29, Gothic dark 5.04 (secondary), Matcha light 4.80, and Matcha dark 5.75 (Text body and secondary). Plain strings are unchanged.

Neutral light Neutral dark Gothic dark Matcha light Matcha dark

Testing

  • vitest run over packages/core/src/Tooltip, Toast, theme, hooks, DialogHeroHeader, Pagination, InfoTip and scripts/check-cli-theme-bundle.test.mjs: 115 files, 3,644 tests pass.
  • Core tsc, eslint on the changed files, pnpm check:knowledge, and the Gothic and Matcha palette-ref checks: pass.
  • The chromium contrast spec runs in CI (pr-a11y); the stills above measure the same colors in Chrome.

Overlap checked: #12156, #11966, #11960, #11517, #12276, #11658, #11831, #11819, #11782, #11916, #11452, #11544, #11540, #11536, #11530, #11525, #11518, #11508, #11478, #11476, #11466, #11463, #8675, #8121, #11681, #11246, #10858, #10720 (each edits Toast.tsx, useTooltip.tsx or the Gothic and Matcha themes for a different change; #12156, #11966, #11960, #11517, #12276, #11658, #11831, #11819 and #11782 merge cleanly with this change; #11916 and #11452 conflict in text in useTooltip.tsx, so the second to merge resolves; the rest already conflict with main)

Writing rubric results

R1 narration: none; the added sentence states what the content does.
R2 research: none in the record.
R3 evidence: the record names no test or change.
R4 rejected alternatives: none.
R5 change references: none.
R6 open questions: none.
R7 project status: none.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 19, 2026 5:41pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 19, 2026, 6:11 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded skipped. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

… contrast specs per theme; keep caller MediaTheme
@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 17, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 63e5d50

@astracat-bot astracat-bot Bot left a comment •

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.

Changes requested. The media-side wrapper makes Text tooltip content readable in every shipped theme, from about 1:1 to at least 5.75:1, and an engineering owner approved that direction for this head. Four things still need fixing before it lands.

  • The plain-string text color change and the lost tooltip-target color ship without their record, so restore the component:Tooltip Design relationships amendment (with a theming-map note for text color) and have an engineering owner approve the new head; wrapping only element content would keep plain strings on --color-background-surface and shrink that amendment to element content.
  • Found by CI: wrapping plain strings breaks five existing tests (anchorReadiness.a11y.browser.spec.ts:101, :128 and :273, whose tooltip text now sits in a boxless display: contents div; DialogHeroHeader.test.tsx:161, which now finds the Close button's tooltip as a media surface; and Pagination.test.tsx:2579, where Next turns back into a link about 120 ms late), and wrapping only element content at useTooltip.tsx:1041 makes the two Vitest files and Tooltip.mediaTheme.test.tsx pass.
  • The new TooltipContentContrast.a11y.chromium.spec.ts fails in CI in six of seven themes, because secondary Text is under 4.5:1 at rest in Gothic (2.32:1) and Matcha dark (3.46:1) and because the spec measures during the tooltip's entrance fade, so call holdMotionStill(page) after goto and fix those two themes' secondary text or narrow the secondary case and the "every kind of content reads" claim.
  • useTooltip.tsx:103-121 copies Toast's token-then-mode side fallback (Toast.tsx:428-450), so extend the shared useSurfaceMediaMode to take that fallback and have Toast and Tooltip each make one call.
Claims and files checked

Review mode: same-head; reason: none

Claims:

  • On the base, Text content measures about 1:1 against the tooltip surface in light and dark: verified, 1.00:1 to 1.12:1 in all seven shipped themes.
  • After the change, every kind of content reads on the tooltip surface in both modes: false. Secondary Text measures 2.32:1 in Gothic and 3.46:1 in Matcha dark at rest.
  • Content renders inside a MediaTheme on the side whose text reads best, measured the way Toast measures: verified at useTooltip.tsx:92-123.
  • Before a measurement, the side comes from the resolved inverted-surface token, and otherwise from the color mode: verified at useTooltip.tsx:103-121 and by the unit test with an unreadable surface color.
  • The surface's own text color never turns the media context off: verified; useTooltip.tsx:74-79 passes no ambient color.
  • The wrapper renders only inside the layer and measures only while the tooltip shows: verified at useTooltip.tsx:1045 (isShown={isLayerOpen}).
  • Content that already holds a MediaTheme keeps it and gets no second wrapper: verified for a top-level MediaTheme (useTooltip.tsx:1041, unit test).
  • Every component that renders a tooltip through useTooltip gets the fix: verified; 25 component folders call useTooltip, more than the 20 stated.
  • No new prop, export or data attribute: verified; the built API comparison and CI's API report list no changes.
  • No record change: true, but the shipped behavior contradicts the unamended record (first finding).
  • No change to the surface color, size, padding, layer behavior or docs example: verified.
  • Neutral stills: Text content 1.12:1 and 1.00:1 before, 18.78:1 and 18.88:1 after, and dark plain text from rgb(38, 38, 38) to rgb(17, 17, 17): verified in Chromium at rest.
  • Four new unit tests fail without the wrapper and pass with it, and a fifth checks a caller MediaTheme: verified.
  • The Chromium contrast spec proves 4.5:1 text and 3:1 icons in every shipped theme: false; it fails in CI in six of seven themes (third finding).
  • Typecheck and lint pass: verified; both are green in CI at this head.
  • Changeset: Text content is readable and renders inside a MediaTheme as Toast's content does: verified. Plain-text tooltips can differ slightly from their old color: verified, with larger moves in some themes (Matcha dark 10.13:1 to 5.75:1).

Files:

  • .changeset/tooltip-content-media-theme.md: clear.
  • apps/storybook/stories/Tooltip.stories.tsx: clear. Its secondary case is the one the spec fails on at rest in Gothic and Matcha dark.
  • packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx: clear.
  • packages/core/src/Tooltip/__tests__/TooltipContentContrast.a11y.chromium.spec.ts: fails in CI (third finding).
  • packages/core/src/Tooltip/useTooltip.tsx: wrapping plain strings contradicts the record and breaks five tests (first and second findings); copied Toast fallback (fourth finding); the comment at lines 69-73 gives the wrong reason (non-blocking).

Automated review (maintainer link)

…xt color; Gothic and Matcha secondary text reads on light media

Tooltip content now sits in MediaTokens, an internal MediaTheme form that
sets the media side's tokens and no text color. Text and other
token-colored content read on the surface, and inherited text, plain or
beside other elements, keeps the tooltip target's color as before. Toast
and Tooltip take their side from one shared hook,
useInvertedSurfaceMediaMode, with the token-then-mode fallback. Gothic and
Matcha secondary text on a light media surface is darker, so it reaches
4.5:1 on their tooltips. The record states that inherited text keeps the
surface color.
@cixzhang
cixzhang marked this pull request as draft November 17, 2026 22:03
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 17, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 17, 2026
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 17, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 80b6792

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 17, 2026

@astracat-bot astracat-bot Bot left a comment

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.

Changes requested. The media-side tokens make Text tooltip content readable in every shipped theme (from about 1:1 to at least 4.80:1 at rest) while plain text keeps its color, and an engineering owner approved the record change for this head; three small fixes remain.

  • Wrapping plain strings in MediaTokens still breaks five existing tests (DialogHeroHeader.test.tsx:161, Pagination.test.tsx:2579, and anchorReadiness.a11y.browser.spec.ts:101, :128 and :273), so render string and number content without the wrapper at useTooltip.tsx:1021, which makes all five pass.
  • The new TooltipContentContrast.a11y.chromium.spec.ts fails in all seven shipped themes because it measures during the tooltip's entrance fade, so call holdMotionStill(page) after each page.goto, which makes it pass in every theme.
  • The changeset names only @astryxdesign/core, so also name @astryxdesign/theme-gothic and @astryxdesign/theme-matcha, whose secondary text on light media surfaces changes.
Claims and files checked

Review mode: full; reason: spec-record

Claims:

  • On the base, Text content reads about 1:1 on the tooltip surface: verified, 1.00:1 to 1.12:1 in all seven themes and both modes.
  • After the change, Text content reads in every shipped theme and mode, and plain text looks exactly as before: verified at rest, 4.80:1 or more, with plain-text colors identical in all 14 pairs.
  • Content gets the tokens of the side that reads on the painted surface, as Toast's does, from the measurement, then the resolved surface token, then the color mode: verified (useAutoMediaMode.ts:146-172, useTooltip.tsx:78-103, the unresolvable-surface unit test).
  • Content does not take MediaTheme's text color, so inherited text and a theme's tooltip color still reach it: verified (MediaTheme.tsx:117-137; the probe theme's tooltip color reaches plain text; the bare-text test passes).
  • The wrapper renders only inside the open layer and measures only while the tooltip shows: verified (useTooltip.tsx:1025).
  • Content that already holds a MediaTheme keeps its own: verified for a top-level MediaTheme (useTooltip.tsx:1021, unit test).
  • No new prop, export or data attribute, and the new component and hook stay internal: verified; the built API comparison lists no changes.
  • Toast makes one call to the shared hook and behaves as before: verified; same fallback order, and its tests and text-contrast check pass.
  • Gothic and Matcha secondary text on their light tooltip surfaces fell below 4.5:1 (2.32:1 and 3.46:1) and now reads 5.04:1 and 5.75:1, and no lighter stop reaches 4.5:1: verified (the next lighter stops read 4.29:1 and 4.47:1).
  • The record's Tooltip text row now describes the media tokens and the kept surface color: verified, and approved for this head.
  • The before-and-after stills table: verified; every ratio matches at-rest Chromium measurements.
  • Four new unit tests fail without the wrapper and a fifth keeps a caller MediaTheme: verified on the base (4 fail, 1 passes).
  • The Chromium contrast spec proves 4.5:1 text and 3:1 icons in every shipped theme: false as written; it fails in all seven themes at this head (second finding).
  • The listed Vitest folders, typecheck, lint, the knowledge check and the palette-reference checks pass: verified; two existing Vitest files outside those folders fail (first finding).
  • The overlap list and the origin of the approach describe other work, not this code: context only.
  • Changeset: Text content becomes readable, plain text keeps the tooltip's color, and Gothic and Matcha secondary text reaches 4.5:1 on light inverted surfaces: verified; it releases only Core (third finding).

Files:

  • .changeset/tooltip-content-media-theme.md: names only Core (third finding).
  • apps/storybook/stories/Tooltip.stories.tsx: clear.
  • docs/specs/components/Tooltip/Tooltip.spec.md: clear; owner-approved for this head.
  • packages/core/src/Toast/Toast.tsx: clear.
  • packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx: clear.
  • packages/core/src/Tooltip/__tests__/TooltipContentContrast.a11y.chromium.spec.ts: measures mid-fade (second finding).
  • packages/core/src/Tooltip/useTooltip.tsx: plain-string wrapper (first finding).
  • packages/core/src/hooks/useAutoMediaMode.ts: clear.
  • packages/core/src/theme/MediaTheme.tsx: clear.
  • packages/themes/gothic/src/gothicTheme.ts: clear; needs its release note (third finding).
  • packages/themes/matcha/src/matchaTheme.ts: clear; needs its release note (third finding).

Automated review (maintainer link)

…pper; the contrast spec measures at rest

Plain text reads no tokens, so a string or number tooltip renders the
same DOM as before. The contrast spec holds motion still after each
load, so it measures the settled colors, not the entrance fade. The
changeset names the Gothic and Matcha packages.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 805e5f9

@astracat-bot astracat-bot Bot left a comment

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.

Changes requested. The media-side tokens now make Text tooltip content readable in every shipped theme (from about 1:1 to at least 4.80:1 at rest), plain strings render exactly as before, the five previously broken tests and the new contrast spec pass, and the changeset names both theme packages; one false claim remains.

  • Miss: the description and the comment at useTooltip.tsx:82-85 say a tooltip that never shows pays nothing for TooltipMediaContent, but the tooltip layer is not lazy and mounts the wrapper with the closed tooltip (the never-hovered TallContent story already has a data-astryx-media wrapper inside its closed tooltip), so reword both or render the wrapper only once the layer has opened.

Non-blocking: the comment at matchaTheme.ts:358-359 calls neutral.light[20] the darkest neutral, but it is the lightest stop that reaches 4.5:1 there.

Claims and files checked

Review mode: incremental; reason: none

changed rules (0): none

Claims:

  • On the base, Text tooltip content reads about 1:1 on the surface: verified, 1.00:1 to 1.12:1 in all seven themes and both modes.
  • Plain-string content was readable on the base: verified, 9.77:1 to 18.78:1.
  • After the change, Text content reads in every shipped theme and mode, and plain text looks exactly as before: verified at rest, 4.80:1 or more, with plain-string colors identical and unwrapped in all 14 pairs.
  • The tooltip paints the inverted surface and gives its own text the page surface color: verified (useTooltip.tsx:108-109).
  • Content gets the side that reads on the painted surface, as Toast's does, from the measurement, then the resolved surface token, then the color mode: verified (useAutoMediaMode.ts:146-172, the four media unit tests).
  • Content does not take MediaTheme's text color, so inherited text and a theme's tooltip color still reach it: verified (MediaTheme.tsx:117-137; the probe theme's tooltip color reaches the plain and bare text; the bare-text test passes).
  • The cited Tooltip, accessibility, theming and MediaTheme references say what the description says: verified.
  • MediaTokens and the new hook stay internal: verified; no package entry reaches them.
  • Toast and Tooltip each call the shared hook once, and Toast behaves as before: verified (Toast.tsx:424, useTooltip.tsx:97; same fallback order).
  • String and number content renders with no wrapper, other content gets the media wrapper, and content that holds a MediaTheme keeps its own: verified (useTooltip.tsx:1021-1031, unit test).
  • The wrapper renders only after the tooltip first shows, so a tooltip that never shows pays nothing: false (finding above); it does measure only while the tooltip shows.
  • Gothic and Matcha secondary text on their light tooltip surfaces fell below 4.5:1 and now reads 5.04:1 and 5.75:1, with no lighter passing stop: verified (the next lighter stops read 4.29:1 and 4.47:1).
  • The record's Tooltip text row describes the media tokens and the kept surface color: verified, and approved for this head.
  • No new prop, export or data attribute: verified; the built API comparison lists no change.
  • The before-and-after stills: verified; every ratio matches at-rest Chromium measurements.
  • Plain-string and number content renders as on the base: verified in Chromium for strings and in code for numbers.
  • The theme change reaches other light media surfaces with the listed Toast and panel ratios: verified from the built theme CSS and the same color pairs measured on the tooltip surface.
  • Four unit tests fail without the wrapper and a fifth keeps a caller MediaTheme: verified on the base (4 fail, 1 passes).
  • The Chromium contrast spec measures at rest in every shipped theme and also checks bare-text color: verified; 14 of 14 pass.
  • The listed Vitest folders pass (16 files, 358 tests), with typecheck, lint, the knowledge check and the palette checks: verified.
  • The contrast spec runs in the pull request accessibility job: verified that the job's routing selects it; CI has not run on this head.
  • The scope checklist (one defect, no tag-along, no hidden API, no internal context): verified.
  • The overlap list and the origin of the approach: context only.
  • Changeset: Text content becomes readable, plain and bare text keep the tooltip's color, Gothic and Matcha light-media secondary text reaches 4.5:1, and core, theme-gothic and theme-matcha are named: verified.

Files:

  • .changeset/tooltip-content-media-theme.md: clear
  • apps/storybook/stories/Tooltip.stories.tsx: clear
  • docs/specs/components/Tooltip/Tooltip.spec.md: clear
  • packages/core/src/Toast/Toast.tsx: clear
  • packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx: clear
  • packages/core/src/Tooltip/__tests__/TooltipContentContrast.a11y.chromium.spec.ts: clear
  • packages/core/src/Tooltip/useTooltip.tsx: finding (comment at 82-85)
  • packages/core/src/hooks/useAutoMediaMode.ts: clear
  • packages/core/src/theme/MediaTheme.tsx: clear
  • packages/themes/gothic/src/gothicTheme.ts: clear
  • packages/themes/matcha/src/matchaTheme.ts: non-blocking comment suggestion

Automated review (maintainer link)

The wrapper renders with the tooltip content, also while the tooltip is
closed, and measures only while it shows. The Matcha comment names the
lightest neutral stop that reaches 4.5:1.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f9d7d99

@astracat-bot astracat-bot Bot left a comment •

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.

Approved pending CI: the CI run on this head stopped because CI was full before its tests ran, so re-run all jobs and let the required checks finish. Tooltip content built from Text now reads on the tooltip surface in every shipped theme and mode (from about 1:1 to at least 4.80:1 at rest), and plain strings render exactly as before.

No blocking findings; nothing for the author to change.

Claims and files checked

Review mode: same-head; reason: none

changed rules (0): none

Claims:

  • On the base, Text tooltip content reads about 1:1 on the surface: verified, 1.00:1 to 1.12:1 in all seven themes and both modes.
  • Plain-string content was readable on the base and is not affected: verified, 9.77:1 to 18.78:1, with the same colors on the head.
  • After the change, Text content reads in every shipped theme and mode, and plain text looks exactly as before: verified at rest, 4.80:1 or more, with plain-string colors identical and unwrapped in all 14 pairs.
  • The tooltip paints the inverted surface and gives its own text the page surface color: verified (useTooltip.tsx:107-108).
  • Content gets the side that reads on the painted surface, as Toast's does, from the measurement, then the resolved surface token, then the color mode: verified (useAutoMediaMode.ts:146-172, the four media unit tests).
  • Content does not take MediaTheme's text color, so inherited text and a theme's tooltip color still reach it: verified (MediaTheme.tsx:123-137; bare text beside an element keeps the tooltip's color).
  • The cited Tooltip, accessibility, theming and MediaTheme references say what the description says: verified; the MediaTheme docs name tooltips as an inverted surface it serves.
  • MediaTokens and the new hook stay internal: verified; no package entry reaches them.
  • Toast and Tooltip each call the shared hook once, and Toast behaves as before: verified (Toast.tsx:424, useTooltip.tsx:95; same fallback order).
  • String and number content renders with no wrapper, other content gets the media wrapper, and content that holds a MediaTheme keeps its own: verified (useTooltip.tsx:1020-1030, unit test).
  • The wrapper renders with the tooltip content while the tooltip is closed and measures only while it shows: verified (the never-hovered TallContent tooltip holds it; the measurement is gated on the open layer).
  • Gothic and Matcha secondary text on their light tooltip surfaces fell below 4.5:1 and now reads 5.04:1 and 5.75:1, with no lighter passing Matcha stop: verified; Matcha's stop is also its primary text on light media surfaces.
  • The record's Tooltip text row describes the media tokens and the kept surface color: verified, and approved for this head.
  • No new prop, export or data attribute: verified; the built API comparison and CI's API report list no change.
  • The before-and-after stills: verified; every ratio matches at-rest Chromium measurements.
  • Plain-string and number content renders as on the base: verified in Chromium for strings and in code for numbers.
  • The theme change reaches other light media surfaces with the listed Toast and panel ratios: verified from the built theme CSS and the same color pairs.
  • Four unit tests fail without the wrapper and a fifth keeps a caller MediaTheme: verified on the base (4 fail, 1 passes).
  • The Chromium contrast spec measures at rest in every shipped theme and also checks bare-text color: verified; 14 of 14 pass on code identical to this head apart from two comments.
  • The listed Vitest folders pass (16 files, 358 tests), with typecheck, lint, the knowledge check and the palette checks: verified; CI's lint job also passes on this head.
  • The contrast spec runs in the pull request accessibility job: verified that the job's routing selects it; that job has not run on this head yet.
  • The scope checklist (one defect, no tag-along, no hidden API, no internal context): verified.
  • The overlap list, the build used for the stills and the origin of the approach: context only.
  • Changeset: Text content becomes readable, plain and bare text keep the tooltip's color, Gothic and Matcha light-media secondary text reaches 4.5:1, and core, theme-gothic and theme-matcha are named: verified.

Files:

  • .changeset/tooltip-content-media-theme.md: clear
  • apps/storybook/stories/Tooltip.stories.tsx: clear
  • docs/specs/components/Tooltip/Tooltip.spec.md: clear
  • packages/core/src/Toast/Toast.tsx: clear
  • packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx: clear
  • packages/core/src/Tooltip/__tests__/TooltipContentContrast.a11y.chromium.spec.ts: clear
  • packages/core/src/Tooltip/useTooltip.tsx: clear
  • packages/core/src/hooks/useAutoMediaMode.ts: clear
  • packages/core/src/theme/MediaTheme.tsx: clear
  • packages/themes/gothic/src/gothicTheme.ts: clear
  • packages/themes/matcha/src/matchaTheme.ts: clear

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 18, 2026 13:53
@cixzhang
cixzhang marked this pull request as draft November 18, 2026 15:21
@cixzhang
cixzhang marked this pull request as ready for review November 18, 2026 15:21

@astracat-bot astracat-bot Bot left a comment

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.

Approval now waits on an engineering owner deciding the first-load cost of this fix. The fix itself works: Text content in a Tooltip reads at 4.80:1 or more in every shipped theme and mode, and plain strings render as before.

  • Miss: useTooltip now imports MediaTheme and useInvertedSurfaceMediaMode, and their useTheme() call brings in the theme token resolver, so every page that imports Button, IconButton, Link, Table, CheckboxList, Selector or DropdownMenu loads about 10 KB more gzip JavaScript at first load (+11.9 to +12.2 KB on each of the four reference pages in pnpm size:pages), which earlier approvals of this head did not report.

An engineering owner answers in a comment on this pull request, choosing one: accept the cost and update the INV1 gap figures in docs/architecture/component-import-boundaries.md, or keep the tooltip content's media-side code out of the eager import, for example by loading it after first paint as DEC-4 describes; the author may answer if they are an engineering owner. Separately, pr-interaction-webkit failed because a starved runner disrupted a Toast touch test, so re-run it.

Claims and files checked

Review mode: same-head; reason: none

changed rules (0): none

Claims:

  • On the base, Text content in a tooltip reads about 1:1 on the surface: verified, 1.00:1 to 1.12:1 in all seven themes and both modes.
  • Plain-string content was readable on the base and is not affected: verified, with the same element and color on the head.
  • After the change, Text content reads in every shipped theme and mode, and plain text looks the same: verified, 4.80:1 or more; the Chromium contrast spec passes in CI on this head.
  • The tooltip paints the inverted surface and gives its own text the page surface color: verified in the tooltip's styles.
  • The content's side comes from the measurement, then the resolved surface token, then the color mode, as Toast's does: verified in the shared hook and the four media unit tests.
  • The content does not take MediaTheme's text color, so a theme's tooltip color still reaches plain and bare text: verified; the bare-text check passes in every theme in CI.
  • The cited Tooltip, accessibility, theming and MediaTheme references say what the description says: verified.
  • The new wrapper and hook stay internal, and there is no new prop, export or data attribute: verified; no package entry reaches them.
  • Toast and Tooltip each call the shared hook once, and Toast behaves as before: verified; the calls are the same and in the same order.
  • String and number content renders with no wrapper, and content that holds a MediaTheme keeps its own: verified in the code and a unit test.
  • The wrapper renders with the closed tooltip and measures only while the tooltip shows: verified.
  • Gothic and Matcha light-media secondary text went from 2.32:1 and 3.46:1 to 5.04:1 and 5.75:1, and Matcha's stop is also its primary text there: verified.
  • The record's Tooltip text row describes the media tokens and the kept surface color: verified, and approved by an engineering owner for this head.
  • The before-and-after stills and their ratios: verified against at-rest Chromium measurements.
  • The theme change reaches other light media surfaces with the listed Toast and panel ratios: verified.
  • Four unit tests fail without the wrapper, and a fifth keeps a caller MediaTheme: verified on the base Tooltip.
  • The listed unit tests, typecheck, lint and the knowledge and palette checks pass: verified; CI's typecheck, UI unit tests and lint pass on this head.
  • The contrast spec runs in the accessibility job: verified; it ran and passed on this head.
  • The scope checklist (one defect, no tagalong, no hidden API, no internal context): verified. The first-load cost is a separate open decision.
  • The overlap list, the build used for the stills and the origin of the approach: context only.
  • Changeset: the fix and the Gothic and Matcha stops are described, and core, theme-gothic and theme-matcha are named: verified.

Files:

  • .changeset/tooltip-content-media-theme.md: clear
  • apps/storybook/stories/Tooltip.stories.tsx: clear
  • docs/specs/components/Tooltip/Tooltip.spec.md: clear (row approved for this head)
  • packages/core/src/Toast/Toast.tsx: clear
  • packages/core/src/Tooltip/Tooltip.mediaTheme.test.tsx: clear
  • packages/core/src/Tooltip/__tests__/TooltipContentContrast.a11y.chromium.spec.ts: clear
  • packages/core/src/Tooltip/useTooltip.tsx: owner decision on the first-load cost of its new imports
  • packages/core/src/hooks/useAutoMediaMode.ts: part of that cost (its useTheme() calls)
  • packages/core/src/theme/MediaTheme.tsx: clear
  • packages/themes/gothic/src/gothicTheme.ts: clear
  • packages/themes/matcha/src/matchaTheme.ts: clear

Automated review (maintainer link)

…not 12 KB

The tooltip content media context read useTheme(), whose token resolver
pulled the theme generator into every page that renders a tooltip. Now:
- the media side measurement keys on the nearest Theme value, not the
  resolved tokens, and loads after the first paint;
- before a measurement, the side is the one opposite the color mode, as
  the inverted surface is in every shipped theme;
- MediaTokens has its own module, so the wrapper does not pull in
  MediaTheme and its auto mode.
The CLI theme bundle is regenerated for the Gothic and Matcha changes.
@cixzhang
cixzhang marked this pull request as draft November 18, 2026 20:37
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 22494e5

main reworked Toast's media side (it now picks the side for a light and a
dark page before it measures), so Toast.tsx takes main's file. This
branch's useInvertedSurfaceMediaMode, which only Toast used, is dropped;
the measurement still keys on the nearest Theme value.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec fc6ef3b

@astracat-bot astracat-bot Bot left a comment •

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.

Changes requested. Tooltip content built from Text now reads on the tooltip surface once its side is measured (4.80:1 or more in Neutral, Gothic and Matcha, light and dark), and plain strings render as before; the blocking findings below remain.

  • TooltipMediaContent.tsx:76-81 picks the pre-measurement side from the raw Theme mode prop, so under the default mode="system" in a dark scheme, and in Gothic (whose tooltip surface is light in both modes), Text content paints at 1.00:1 until the measurement chunk arrives; take the side from the theme's resolved inverted surface by the measurement's rule, as Toast does.
  • useAutoMediaMode.ts:146 keys the shared measurement on the Theme context instead of useTheme(), so under a mode="system" Theme MediaTheme mode="auto" no longer re-measures when the reader's color scheme changes and keeps the old side; key it on the resolved scheme as well, for example by exporting the light useResolvedScheme from theme/useTheme.ts.
  • theme/MediaTokens.tsx is a new internal module imported from Tooltip/ that no record defines: move it into Tooltip/, or record its usage, why it is needed and why MediaTheme is not enough for an owner decision.
  • The layout Effect at tooltipSurfaceSide.tsx:50-52 only copies the measured side into the parent's state; report it from the measurement's own layout Effect through a callback instead.
  • The module-load Effect at TooltipMediaContent.tsx:59-75 repeats the two in Text/TruncationTooltip.tsx (:79-95, :312-328); share one hook beside createModuleLoader.
  • The description says the pre-measurement side comes from the theme's resolved surface (it comes from the mode prop), that the inverted surface is opposite the color mode in every shipped theme (not in Gothic), that a scheme change re-measures (it does not under a system Theme), that four unit cases fail without the wrapper (three do), and that a cold first show has no flash (it reads 1.00:1 in the two cases above).

Non-blocking: record Gothic's new light-media secondary stop (neutral.dark[50], 5.04:1 on its tooltip) in gothic.spec.md beside the accent line.

Claims and files checked

Review mode: same-head; reason: none

  • Claim: Text content in a tooltip reads at 4.5:1 or more: verified once measured (4.80:1 or more in Neutral, Gothic and Matcha, light and dark); false before the measurement under a dark system scheme and in Gothic.
  • Claim: plain strings and numbers render as before: verified (useTooltip.tsx:979-981; the same ratio as the base in every pair).
  • Claim: inherited and bare text keep the tooltip surface color: verified (MediaTokens.tsx:36-42 sets no color; bare text matches the plain string in every pair).
  • Claim: before the measurement the side comes from the theme's resolved surface color: false (TooltipMediaContent.tsx:76-81 reads the mode prop).
  • Claim: the side opposite the color mode matches the inverted surface in every shipped theme: false for Gothic.
  • Claim: a scheme change re-measures through the painted backdrop: false under a system Theme (useAutoMediaMode.ts:146).
  • Claim: Toast is unchanged: verified (the pull request does not edit Toast, which still calls useTheme() itself).
  • Claim: the wrapper has its own module so the tooltip does not load MediaTheme: verified (TooltipMediaContent.tsx:23).
  • Claim: the measurement loads after the first paint and corrects the side before the shown frame paints: verified once loaded (layout Effects).
  • Claim: a MediaTheme inside the content keeps its own side: verified (its own marker is the nearest to the text).
  • Claim: the CLI theme copies are regenerated: verified, byte-identical to the package sources.
  • Claim: Gothic and Matcha light-media secondary text reaches 5.04:1 and 5.75:1: verified in Chromium.
  • Claim: Matcha's new secondary stop is also its light-media primary text: verified (--color-on-light).
  • Claim: the Tooltip record's Tooltip text row states the new behavior: verified; an engineering owner approved this head.
  • Claim: no new prop, export or data attribute: verified (no entry point reaches the new modules; data-astryx-media already exists).
  • Claim: Text content measures 1.00:1 to 1.12:1 on the base: verified in Chromium.
  • Claim: four new unit cases fail without the wrapper: false; three do, since the MediaTheme case brings its own marker.
  • Claim: the Chromium contrast spec covers every shipped theme: not run in CI at this head (draft); its assertions hold in Chromium for Neutral, Gothic and Matcha.
  • Claim: the before and after stills: verified for Neutral, Gothic and Matcha.
  • Claim: Gothic and Matcha Toast cards and panels improve the same way: consistent with the shared token; not measured separately.
  • Claim: per-component first-load deltas of 370 to 1,072 bytes: not re-measured per component.
  • Claim: a cold first show has no flash: false under a dark system scheme and in Gothic.
  • Claim: the listed unit suites pass: verified for the Tooltip, Toast, MediaTheme, media-measurement and truncation-tooltip suites (15 files, 312 tests at this head); the DialogHeroHeader, Pagination, InfoTip and CLI theme-bundle suites were not re-run.
  • Changeset: names Core, Gothic and Matcha as patches and describes the fix: verified, apart from the pre-measurement cases.
  • Files: TooltipMediaContent.tsx (findings), tooltipSurfaceSide.tsx (finding), useTooltip.tsx (clear), useAutoMediaMode.ts (finding), MediaTokens.tsx (finding), gothicTheme.ts and its CLI copy (owner-approved; comment suggestion), matchaTheme.ts and its CLI copy (clear), Tooltip.mediaTheme.test.tsx (clear), TooltipContentContrast.a11y.chromium.spec.ts (clear), Tooltip.stories.tsx (clear), Tooltip.spec.md (clear, owner-approved), the changeset (clear).

Automated review (maintainer link)

Comment on lines +143 to +146
// The nearest Theme's value is a stable reference unless its theme or mode
// changes. A change of the page's scheme moves the painted backdrop, which
// the key below also holds.
const themeKey = use(ThemeContext);

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.

Under a mode="system" Theme this context value is the raw prop, memoized on theme and mode (Theme.tsx:481-484), so it does not change when the reader switches scheme. The base's useTheme() call was also this hook's subscription to the scheme (useResolvedScheme), so now nothing re-renders MediaTheme mode="auto" and it keeps the old side: an inverted panel's text goes white on white (1.00:1), where the base re-measures. Key the measurement on the resolved scheme as well, for example by exporting useResolvedScheme from theme/useTheme.ts, which does not bring in resolveThemeTokens.

Comment on lines +76 to +81
const mode =
measured === 'dark' || measured === 'light'
? measured
: theme?.mode === 'dark'
? 'light'
: 'dark';

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.

theme?.mode is the Theme's raw prop, 'system' by default, so a dark system scheme gets the dark side on the white dark-mode surface: Text is white on white (1.00:1) until the measurement arrives. Gothic's surface is #e8f1f6 in both modes, so under system or light the same side paints Text in the surface's color (1.00:1). Take the side from the theme's resolved inverted surface by the measurement's rule, as Toast does with invertedSideIn (Toast.tsx:433-437).

* tokens, such as `Text`, take the side's values, and inherited text keeps
* the color of the surface around it.
*/
export function MediaTokens({

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.

This is a new internal module that Tooltip/TooltipMediaContent.tsx imports from another folder, and no current record names it (architecture:knowledge-contracts DEC-22). Move it into Tooltip/, where it is private, or record its usage, why it is needed, and why MediaTheme (which differs only by setting color) is not enough, for an owner decision.

Comment on lines +49 to +52
// Syncs the measured side with the content's media context.
useIsomorphicLayoutEffect(() => {
onSide(side);
}, [side, onSide]);

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.

This layout Effect only copies side into the parent's state (onSide is setMeasured), which architecture:react-component-runtime INV1 and INV2 rule out. Report the side from the measurement's own layout Effect, where useAutoMediaMode.ts:190 already sets it, for example through an optional callback on useSurfaceMediaMode.

Comment on lines +58 to +75
// Syncs with the module loader: element content loads the measurement.
useEffect(() => {
if (SurfaceSide != null) {
return;
}
let isCurrent = true;
surfaceSideModule.load().then(
loaded => {
if (isCurrent) {
setSurfaceSide(() => loaded.TooltipSurfaceSide);
}
},
() => {},
);
return () => {
isCurrent = false;
};
}, [SurfaceSide]);

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.

This repeats the two load Effects in Text/TruncationTooltip.tsx (:79-95, :312-328) line for line. Add one hook beside createModuleLoader in utils/moduleLoader.ts that returns the loaded module or null, and call it from all three.

Comment on lines +534 to +535
// Gothic's secondary text is one light color too, so a light media surface
// takes a darker one that reads on it.

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.

Non-blocking: "one light color too" does not say why the stop changes. Suggested:

// On a light media surface, the page's secondary text falls below 4.5:1.
// This stop reads at 5.04:1 there.

@cixzhang cixzhang removed the needs:design-review Affects visuals — Design should review label Nov 20, 2026

This branch was successfully deployed

1 active deployment
Preview — fc6ef3b7 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant