Skip to content

feat(native): Swift theme generator warns on lossy values and falls back for impossible ones - #8422

Merged
cixzhang merged 2 commits into
mainfrom
native/swift-theme-diagnostics
Nov 1, 2026
Merged

cixzhang merged 2 commits into
mainfrom
native/swift-theme-diagnostics

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Follows #8420 (CSS reader, merged). Rebased onto main with only its own commit.

User need

With #8420, the Swift theme generator reads every CSS color and length, but two gaps stay:

  • When a conversion loses something (an em is read against the root size, a drop shadow's spread is dropped), it happens silently. A product team never learns that its Swift theme differs from the web.
  • One value with no fixed Swift form (currentColor, 50%, 2vw) stops the whole run, even when core already has a perfectly good default for that token. The team gets no Swift theme at all.

After this change:

  • Product teams see exactly what was approximated: one warning per loss, naming the theme, mode, token, CSS value, and the Swift value written, printed after the files.
  • One impossible value no longer blocks a team's whole Swift theme: that token takes core's default, with a warning. The run stops only when core has no default for it.
  • CI can insist on exact output: --strict turns every warning into an error and writes no file.

Problem and solution fit

No generated Swift changes; every published theme generates with zero warnings.

Current specification

packages/native/specs/swift/library/theme-generator.md (draft) owns the generator; this PR adds G15 there. G7 (values, from #8420) decides what each value converts to; G15 decides what the run does about it.

Public delta and caller burden

Rules (G15):

  • Exact (including G7's stated rounding): nothing printed.
  • Lossy (a color outside Display P3, clipped as Chromium draws it, em, bolder/lighter, normal line height, drop-shadow spread): value emitted, one warning.
  • Not read (a valid CSS form the reader does not read yet, or invalid CSS): the run stops, ending "the Swift theme generator does not read this form"; no fallback.
  • No static form: if the token is optional, core's default is emitted with a warning; otherwise the run stops with theme, mode, token, value, and reason. A token is optional when core's resolver returns a default for it with no theme (resolveThemeTokens(null, {mode})), which covers every shared token. A token core has no default for, and every token of core's own defaults, are required.
  • Warnings print after the files are written; --strict fails before writing.

A product theme run (--theme ./acme.mjs#acmeTheme --out ./out):

wrote ./out/AcmeBrandTheme.swift
warning: acme-brand light: --color-text-accent = oklch(0.7 0.4 150) → Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1): outside Display P3; clipped to match the web
warning: acme-brand light: --radius-element = 2vw → 8: viewport units depend on the screen; core's default 8px used instead
warning: acme-brand dark: --color-accent = oklch(0.78 0.16 255) → Color(.displayP3, red: 0.49411764705882355, green: 0.7215686274509804, blue: 1, opacity: 1): outside Display P3; clipped to match the web

The same run with --strict writes nothing and exits 1:

error: 7 warning(s), which --strict treats as errors:
error: acme-brand light: --color-text-accent = oklch(0.7 0.4 150) → Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1): outside Display P3; clipped to match the web
…

No static form and no core default:

error: acme-broken light: --color-acme-only = currentColor: currentColor depends on where the token is used; Swift has no static value

Callers that pass no options behave as before except that an impossible value in a token core has a default for now generates (with a warning) instead of failing.

Review fixes

Three findings from automated review, each with a test:

  1. renderSwiftTheme(theme) and renderAll(load) called without a warnings list now print each warning to standard error instead of dropping it. This matches G15's rule that warnings print and that a value with no static form falls back with a warning; keeping the error when no list is passed would contradict the fallback. A caller that wants them silently passes its own list.
  2. When a theme's own value fails partway (calc(1em + 2vw)), the notes from that failed read are dropped before the fallback, so the warning names only the failure and core's default.
  3. A token's notes are deduplicated, so calc(1em + 1em) warns once per mode.

Design and alternatives

  • "Optional" means core has a default. That is the one fact the code can check, and core fills every shared token, so a product theme with one impossible value still gets a working Swift theme. Rejected: failing on every impossible value, because one bad token would block a whole team's Swift theme even though core's value is a safe stand-in.
  • Warnings after the files. The files are what the team came for; the warnings are a summary they read once. --strict fails before writing so CI never leaves half-generated output.

Existing authority searched

Writing rubric results

R1 narration: none; G15 states what the run does, in the present tense.
R2 research: none.
R3 evidence: the G15 acceptance row cites concrete inputs and outputs, no PRs.
R4 rejected alternatives: none in the record (the one rejected alternative lives in this PR body).
R5 change references: none (searched for #digits, /pull/, /issues/).
R6 open questions: none.

Evidence

  • Unit tests: lossy warning text (light and dark), core-default fallback for --spacing-4: 2vw, required-token error for a token core has no default for, --strict throwing with every warning listed, and finishRun writing nothing under --strict.
  • The terminal output above is a real run of the CLI at this head.
  • Drift: generate:swift-ios regenerates every published theme byte-identically with zero warnings.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run --project node packages/native         # 9 files, all pass
# run with --testTimeout=120000: contracts.test.ts's type-resolution test (untouched here)
# needs more than 30 s while the machine is busy
pnpm -F @astryxdesign/native generate:swift-ios          # no generated file changes, no warnings
pnpm -F @astryxdesign/native typecheck                   # pass
pnpm check:knowledge                                     # Knowledge templates and records are aligned.

@vercel

vercel Bot commented Oct 25, 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 1, 2026 12:23pm UTC

Request Review

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

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 1, 2026, 12:55 PM UTC

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · af1aa90

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

API changes: core +8 · ~20 · −0 (report stale: run pnpm api:report); richtext +0 · ~1 · −0 (report stale: run pnpm api:report)

29 API changes (advisory)
Package Where Signature Usage
+ core . · Types · interface FieldStatusProps message: string import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {message: …}
+ core . · Types · interface FieldStatusProps ref?: React.Ref<HTMLDivElement> import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {ref: …}
+ core . · Types · interface FieldStatusProps type: InputStatusType import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {type: …}
+ core . · Types · interface FieldStatusProps variant?: FieldStatusVariant = 'attached' import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {variant: …}
+ core . · Types · interface FieldStatusProps xstyle?: StyleXStyles import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {xstyle: …}
+ core . · Types · interface FieldStatusProps inherits AriaAttributes, DOMAttributes, HTMLAttributes import type {FieldStatusProps} from '@astryxdesign/core'
+ core . · Types · interface SearchContext interface SearchContext<T extends SearchableItem = SearchableItem> import type {SearchContext} from '@astryxdesign/core'
+ core ./Typeahead · Also exported from an earlier entry point · SearchContext SearchContext (.) import {SearchContext} from '@astryxdesign/core/Typeahead'
~ core . · Components · component ComplexSelector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors <ComplexSelector statusVariant="attached" />
~ core . · Components · component DateInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <DateInput statusVariant="attached" />
~ core . · Components · component DateRangeInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <DateRangeInput statusVariant="attached" />
~ core . · Components · component Field prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Field statusVariant="attached" />
~ core . · Components · component FieldStatus component FieldStatus(props: FieldStatusProps) → component FieldStatus @deprecated <FieldStatus />
~ core . · Components · component FieldStatus prop variant?: FieldStatusVariant = 'attached' → prop variant: FieldStatusVariant = 'attached' <FieldStatus variant="attached" />
~ core . · Components · component FileInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <FileInput statusVariant="attached" />
~ core . · Components · component MultiSelector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors <MultiSelector statusVariant="attached" />
~ core . · Components · component NumberInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <NumberInput statusVariant="attached" />
~ core . · Components · component PowerSearch prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <PowerSearch statusVariant="attached" />
~ core . · Components · component Selector prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary/ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary/ghost selectors <Selector statusVariant="attached" />
~ core . · Components · component TextArea prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TextArea statusVariant="attached" />
~ core . · Components · component TextInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TextInput statusVariant="attached" />
~ core . · Components · component TimeInput prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <TimeInput statusVariant="attached" />
~ core . · Components · component Tokenizer prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Tokenizer statusVariant="attached" />
~ core . · Components · component Typeahead prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' <Typeahead statusVariant="attached" />
~ core . · Types · interface FieldStatusProps interface FieldStatusProps extends BaseProps<HTMLDivElement> (props of FieldStatus) → interface FieldStatusProps extends BaseProps<HTMLDivElement> import type {FieldStatusProps} from '@astryxdesign/core'
~ core . · Types · interface FieldStatusVariantMap tooltip: true → tooltip: true @deprecated import type {FieldStatusVariantMap} from '@astryxdesign/core'; const x: FieldStatusVariantMap = {tooltip: …}
~ core . · Types · interface SearchSource search: (query: string) => Promise<T[]> | T[] → search: (query: string, context?: SearchContext<T>) => Promise<T[]> | T[] import type {SearchSource} from '@astryxdesign/core'; const x: SearchSource = {search: …}
~ core . · Types · interface UseInputStatusIconOptions statusVariant?: FieldStatusVariant → statusVariant?: FieldStatusPlacement import type {UseInputStatusIconOptions} from '@astryxdesign/core'; const x: UseInputStatusIconOptions = {statusVariant: …}
~ richtext . · Components · component RichTextEditor prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusVariant | 'tooltip' = 'attached' <RichTextEditor statusVariant="tooltip" />

Wide change (shared styles: packages/native/src/theme/swiftIOSTheme.test.ts): add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Separately, renderSwiftTheme(theme) and renderAll(load) called without a warnings list, as the drift test calls it, now return core's value with no signal at all (swift-ios-theme.mjs:311, :729); please print those warnings or keep the old error when no list is passed, and deduplicate the repeated warning that a value with two em operands produces.

[Automated review]

*/
export async function resolveTheme(
theme,
{warnings = [], strict = false} = {},

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.

With warnings defaulting to a throwaway array here (and in renderAll), renderSwiftTheme(theme) and renderAll(load), the drift test's call, now replace an unconvertible value with core's default and report nothing; before this change they threw. Printing the warnings when no list is passed, as the web compiler's warnings?: string[] collector does, or keeping the throw, would keep that substitution visible.

notes.push(`${error.message}; core's default ${fallback} used instead`);
}
const emitted = swiftValue(memberType(group, token), typed);
for (const note of notes) warnings.push(`${where} → ${emitted}: ${note}`);

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.

A value with two em operands, such as calc(1em + 1em), adds two identical notes, so this prints the same warning twice per mode and --strict counts it twice, while G15 says one warning per lossy conversion. Deduplicating the token's notes (new Set(notes)) would fix it.

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Alongside that decision, three fixes are needed:

  • renderSwiftTheme(theme) and renderAll(load) called without a warnings list, as the published-theme and drift tests call them, return core's value with no signal at all (swift-ios-theme.mjs:311, :739); print those warnings or keep the error when no list is passed.
  • When a theme's own value fails partway, its earlier notes stay on the substituted value, so calc(1em + 2vw) warns that an em was read for what is core's default; clear the notes before the fallback (swift-ios-theme.mjs:288).
  • Deduplicate a token's notes so calc(1em + 1em) warns once per mode, as G15 says (swift-ios-theme.mjs:291).

[Automated review]

`${where}: ${error.message}; Swift has no static value`,
);
}
notes.push(`${error.message}; core's default ${fallback} used instead`);

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.

When the theme's own conversion throws partway, notes still holds what css-values.mjs pushed before the failure (an em operand, a drop layer's spread), so calc(1em + 2vw) emits core's 16 with an extra … → 16: em read against the 16px root font size warning per mode, and --strict counts it. Clearing the notes before this push (notes.length = 0) leaves only the substitution warning.

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Alongside that decision, three fixes are still needed:

  • renderSwiftTheme(theme) and renderAll(load) called without a warnings list, as the published-theme and drift tests call them, return core's value with no signal at all (swift-ios-theme.mjs:311, :739); print those warnings or keep the error when no list is passed.
  • When a theme's own value fails partway, its earlier notes stay on the substituted value, so calc(1em + 2vw) warns that an em was read for what is core's default; clear the notes before the fallback (swift-ios-theme.mjs:288).
  • Deduplicate a token's notes so calc(1em + 1em) warns once per mode, as G15 says (swift-ios-theme.mjs:291).

[Automated review]

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning, so that behaviour stays a spec gap until G15 is decided. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. The three fixes requested earlier (printing warnings when no list is passed, dropping a failed read's notes, and one warning per token and mode) are in, each with a test, and no other change is needed.

[Automated review]

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. No other change is needed: the generator matches G15 as written, and every published theme still generates unchanged with no warning.

[Automated review]

…ack for impossible ones

A lossy conversion (a color outside Display P3, clipped as Chromium draws it; an em read against the root; bolder or lighter; a normal line height; a drop-shadow spread) prints a warning after the run, naming the theme, mode, token, value, and the Swift value written. The outside-Display-P3 warning keeps its text, "outside Display P3; clipped to match the web", and now goes through the same warnings list.

A value with no static form (currentColor, %, vh, an unresolved var()) takes core's default for that token with a warning; only a token core has no default for stops the run, ending "Swift has no static value". A form the reader does not read still fails, saying so. --strict turns every warning into an error and writes no file. Product themes (--theme) get the same treatment, and renderSwiftTheme takes `warnings` and `strict` in place of the `warn` callback. The spec gains G15.
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from ccbf760 to f5a83b9 Compare November 1, 2026 09:32
@cixzhang
cixzhang force-pushed the native/swift-theme-diagnostics branch from 6d99f67 to ca5fbe2 Compare November 1, 2026 09:37
@cixzhang
cixzhang changed the base branch from native/swift-theme-css-values to main November 1, 2026 09:51

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a mistyped var() reference) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Separately, the G7 row of the acceptance checks (line 251) still says currentColor, an inherit font family and a colorless shadow fail with "Swift has no static value"; please reword it to match G15, since those shared tokens now take core's default with a warning.

[Automated review]

| G12 | A test reads `packages/themes/*/package.json` and finds one generated file per non-private package plus `default`. A fixture product theme renders through `renderSwiftTheme`. |
| G13 | Editing one generated value or member name by hand fails the drift test with the regenerate command in the message. |
| G14 | The README's generated-Swift note lists the generated theme files. |
| G15 | `oklch(0.7 0.4 150)` emits `Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1)`, clipped as Chromium draws it, and warns in light and dark with theme, mode, token, value, and that Swift value, ending "outside Display P3; clipped to match the web"; `--spacing-4: 2vw` emits core's default and warns; `currentColor` in a token core has no default for fails with theme, mode, token, value, and reason; with `--strict`, a theme that warns fails and no file is written. Without a list, `renderSwiftTheme` prints each warning to standard error; `calc(1em + 2vw)` falls back with one warning that does not mention the `em`; `calc(1em + 1em)` warns once per mode. |

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 row says currentColor fails only in a token core has no default for, but G7's row above (line 251, unchanged) still requires currentColor, --font-family-body: inherit, and a colorless shadow layer to fail ending "Swift has no static value", and "Each G7 form with no static form fails with its reason". All three are shared tokens, so at this head they take core's default with a warning (the tests were rewritten to falls back from %s). Rewording the G7 row to point at G15's fallback would keep the record consistent.

currentColor, an inherit font family, and a colorless shadow layer are reported as having no static form and handled as G15 says: core's default with a warning, or a failed run when core has none.

@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 waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a mistyped var() reference) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. The G7 acceptance row now matches G15 and the code, and no other change is needed.

[Automated review]

@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec af1aa90

@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 is ready to merge: G15's warnings, core-default fallback and --strict are approved by an engineering owner on this head, and the generator, its record, the README and the tests agree. Every published theme still regenerates unchanged with no warning, and no further change is needed.

[Automated review]

@cixzhang
cixzhang merged commit ed24dae into main Nov 1, 2026
57 checks passed
@cixzhang
cixzhang deleted the native/swift-theme-diagnostics branch November 1, 2026 12:57

This branch was successfully deployed

1 active deployment
Preview — af1aa90d Deployed Nov 1, 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