Skip to content

fix(theme): preserve component overrides in type-scale adaptations - #6710

Merged
imdreamrunner merged 2 commits into
mainfrom
fix/adaptation-component-overrides
Sep 28, 2026
Merged

imdreamrunner merged 2 commits into
mainfrom
fix/adaptation-component-overrides

Conversation

@imdreamrunner

@imdreamrunner imdreamrunner commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Themes that combine typography.scale with authored Heading/Text component styles lose those styles when a scale-only adaptation matches. For example, a butter-shaped theme's display text switches from its Sarina stack to var(--font-family-heading) on narrow touch viewports. This restores the authored component treatment while allowing sizes and leading to adapt.

This is a separate Core fix discovered while reviewing #6699. It does not change that PR or any file under packages/themes/butter.

Problem and solution fit

  1. Why does it occur? resolveThemeAdaptationRules resolves each rule without root components. resolveThemeValues regenerates type-scale component rules and merges only that rule's authored components over them. generateAdaptationRuleRules then emits those defaults after the root at equal specificity.
  2. Why does it harm the task? A rule intended to change the scale also resets font families and other component pins, even though their generated var() wiring is independent of the scale configuration.
  3. Why does that matter? Theme authors cannot adapt typography sizes without repeating unrelated component styling in each condition; branded display text changes unexpectedly by input/viewport state.

The resolver now receives the effective root component map from both defineTheme and the built-metadata compiler path. After normal validation, it omits only generated type-scale component leaves whose exact root path already exists. It never removes an authored rule leaf. The existing root declaration therefore remains authoritative, while changed scale tokens flow through its existing variable references.

Expected behavior and authority

AST-012, current, FR4–FR7 and IR2/IR4:

  • FR4: “Within one rule, values use the root expansion, deep-merge, and kind precedence.” The root authoring contract places generated component typography below explicit component overrides.
  • FR6: “the last matching write to each resolved token or component leaf wins.” Explicit component writes remain intact, including writes equal to root values that intentionally undo an earlier rule.
  • FR7: inherited rules retain their relative order and resolve against the child's effective breakpoint map; child rules append after them.
  • IR2/IR4: runtime/static compilation and source/built extension have the same meaning.

The prior FR4 wording says every produced generative-axis leaf counts as a write. This PR includes a narrow FR4/FR6 amendment making the exception explicit: invariant generated type-scale component defaults at exact paths already declared on the effective root are not writes; generated tokens and rule-authored component leaves remain writes. Consequently, an earlier authored component leaf survives a later scale-only rule only when that path exists at root. Without the root path, the later generated component leaf still wins. This does not make root token pins beat later generated token values.

The current-record amendment requires spec-owner-approval from an eligible engineering owner on the new exact head. Historical approved_by/approved_at and owners are unchanged; no new approval is claimed by this PR.

Smallest restoration

  • No new public authoring API, metadata, theme-specific exception, or token precedence change.
  • No whole-root merge into media blocks: unrelated root components are not copied conditionally.
  • Rule-only scales still emit missing component defaults; exact existing root paths are left alone.
  • Rule-authored overrides still win, and a later scale-only rule does not reset an earlier explicit component write where root wiring exists.
  • The Heading weight guard remains conditional on actual heading component writes; authored Heading defaults still get the guard. A scale-only rule with complete root wiring needs no extra guard.

Rejected alternatives:

  • Duplicating Sarina declarations in butter's adaptation is a theme-side workaround, not a restoration for other themes.
  • Seeding the ordinary value resolver does not fix precedence: generated components currently merge above the seed. Blindly merging all root components would bloat CSS and conditionally reapply unrelated styles.
  • Re-emitting root pins over generated defaults would reset earlier matching component rules. Suppression preserves the real cascade and reduces CSS.
  • Suppressing all generated components would break the rule-only-scale case where root wiring is absent.

Evidence

  • Reproduction before the change: all four new Core regressions fail against unmodified main.
  • Result after the change: the butter-shaped scale-only media block contains scale tokens but no regenerated Heading/Text selectors; all three display-family pins remain in root CSS. A Chromium before/after probe of the original root-less resolver call changes computed family from Outfit, sans-serif to the Sarina stack while keeping the adapted size at 42 px. The minimal probe's component CSS shrinks from 16,103 to 10,778 bytes.
  • Representative unchanged path: themes with no root scale still receive missing generated defaults; token expansion, explicit conditional overrides, and Heading weight precedence retain their behavior.
  • Regression proof: five Core cases cover butter-shaped display 1/2/3, leaf-scoped filling without a root scale, overlapping/root-restoring explicit writes, child inheritance, immutability, built-metadata fallback, and the asymmetric missing-root-path boundary (an earlier authored body size loses to a later generated size when both rules match). Two CLI cases cover defined/plain inputs, runtime/build block parity and order, built-module regeneration, and source/built child parity.
  • Chromium: 767/768 px × coarse/fine pointer retains the Sarina family; display-1 is 42 px only at coarse/767 and 61 px otherwise. A contrast rule explicitly changes the family to monospace. Authored heading weight stays 900, explicitly changes to 300 under the rule, and the public bold override stays 800. This checks computed CSS; remote font loading and real Safari were not tested.

Scope

  • 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.

Testing

  • pnpm vitest run --project=ui packages/core/src/theme/ — 22 files, 1,470 tests passed after the review follow-up.
  • pnpm check:knowledge and pnpm check:changesets — passed after the FR4/FR6 amendment and changeset citation.
  • pnpm vitest run --project=node packages/cli/clients/cli/commands/build-theme.adaptations.test.mjs — 16 tests passed.
  • Remaining CLI theme-build suites — 24 files passed; the two new parity assertions initially needed to account for the CLI's separate layer wrappers, then passed in the full touched-file rerun above.
  • pnpm build — passed; Core rebuilt again from the final implementation before CLI and Chromium checks.
  • pnpm lint:strict — passed, 0 errors (82 existing warnings outside this change).
  • pnpm test --maxWorkers=8 on implementation commit 8a2b26eecc (before the spec/test-only review follow-up) — 920 files passed, 3 skipped; 19,717 tests passed, 2 expected failures, 52 skipped. One unrelated accessibility-audit.integration.test.mjs test failed. Isolated runs on both this branch and a clean detached worktree at base commit 665afc1a0cc94e468ef5fbd15922fdc7defb210a reproduce this fixture's port-allocation failure (EADDRINUSE), affecting different cases. No accessibility test or production code is changed here.

One patch changeset: @astryxdesign/core, [fix], @imdreamrunner.

Current global-baseline routing receipt

Authority base: 665afc1a0cc94e468ef5fbd15922fdc7defb210a. Trigger: theming; each claim matched its record's review-applicability:v1 route.

  • architecture:component-theming-surface: INV3–INV10, INV12, INV14, INV15.
  • architecture:theme-application: INV1, INV2, INV3, INV7, INV8, INV9.
  • architecture:theme-authoring-contract: INV1, INV3, INV8, INV9, INV11, INV12.
  • architecture:theme-compilation: INV2, INV3, INV4, INV6, INV9, INV10.
  • spec:AST-012: FR4, FR5, FR6, FR7.

No target, enrollment, private-variable, or provider-boundary change. The direct restoration is in adaptation resolution; compiler/inheritance parity and unchanged surface/weight behavior are covered by the suites above.

@vercel

vercel Bot commented Sep 28, 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 Sep 28, 2026 11:10pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 28, 2026
@astracat-bot

astracat-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Sep 28, 2026, 11:20 PM UTC

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@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.

This change fixes a real cascade bug: when a theme adaptation only changed the type scale, the regenerated Heading/Text defaults were emitted after the root theme and silently reset authored component styles — for example, a branded display font family reverting on narrow touch viewports. The fix resolves adaptations against the effective root component map and omits only the generated component leaves that already exist at root, so sizes and leading still adapt through the existing variable wiring while authored pins stay authoritative.

The important boundaries are preserved: generated scale tokens still write in rule order, authored rule overrides (including one that restores a root value) still win, themes without a root scale still receive the missing generated defaults, and built themes behave the same as source-defined themes. The new Core and CLI regression cases cover these paths, including child-theme inheritance.

No changes requested.

[Automated review]

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Sep 28, 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.

This change fixes a real cascade bug: when a theme adaptation only changed the type scale, the regenerated Heading/Text defaults were emitted after the root theme and silently reset authored component styles — for example, a branded display font family reverting on narrow touch viewports. The fix resolves adaptations against the effective root component map and omits only the generated component leaves that already exist at root, so sizes and leading still adapt through the existing variable wiring while authored pins stay authoritative. The important boundaries are preserved and covered by new Core and CLI regression cases: generated scale tokens still write in rule order, authored rule overrides (including one that restores a root value) still win, and themes without a root scale still receive the missing generated defaults.

Approval is not yet possible, because this pull request also intentionally changes the established spec: the current AST-012 FR4 wording says every produced leaf counts as a write by that rule, and FR6 gives the last matching write the win with no root-path exception. Approval needs a maintainer to update the existing spec for that intentional change — an eligible engineering owner giving spec-owner approval to this pull request's FR4/FR6 amendment on its current head, which is still pending. What must be settled is whether invariant generated type-scale component defaults at exact leaf paths already declared on the effective root components are not writes (with generated tokens and rule-authored leaves remaining writes), and whether a later scale-only rule preserves an earlier authored component leaf only when its exact path exists at root, while the generated leaf still wins when that path is absent.

No code changes are requested for this hold. Once a maintainer settles the spec update, the evidence in this change supports approval as it stands.

[Automated review]

@imdreamrunner

Copy link
Copy Markdown
Contributor Author

/approve-spec bab2a3b

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Sep 28, 2026
@imdreamrunner
imdreamrunner enabled auto-merge (squash) September 28, 2026 23:20
@imdreamrunner
imdreamrunner merged commit 039a67e into main Sep 28, 2026
44 checks passed
@github-actions
github-actions Bot deleted the fix/adaptation-component-overrides branch September 29, 2026 06:24

This branch was successfully deployed

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

Labels

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