Skip to content

fix(siteImport): rewrite var() references to the variable a font token is emitted under - #620

Open
ehnruiz wants to merge 2 commits into
CoreBunch:mainfrom
ehnruiz:fix/import-font-token-refs
Open

ehnruiz wants to merge 2 commits into
CoreBunch:mainfrom
ehnruiz:fix/import-font-token-refs

Conversation

@ehnruiz

@ehnruiz ehnruiz commented Oct 11, 2026 •

Copy link
Copy Markdown

Stacked on #618. This branch contains #618's commit (fd241f70) plus one commit for #619 (cec37f2b). Review only the last commit: cec37f2b. Once #618 merges, this PR's diff shrinks to that commit.

Summary

Fixes #619. Site Import normalised a root --font-* variable at extraction (normalizeFontTokenVariable: --font-Heading → font-heading), and the store emits that form, but the imported var(--font-Heading) references kept the authored name and no longer resolved. Two authored names that normalise to the same variable (--font-Heading / --font-heading) were deduplicated into one token, so one font was lost.

What changed:

Verification

  • bun run build (exit 0)
  • bun test: 7070 pass, 1 fail. The failure is no-circular-dependencies, whose madge call hit the test's 15 s limit at load average ~20. Run on its own, it passes in 6.6 s. bun x madge --circular --ts-config tsconfig.json --extensions ts,tsx src server exits 0 with "No circular dependency found!" across 2781 files. An earlier full run of this branch before the review fixes had 7068 pass, 0 fail.
  • bun run lint (exit 0); tsc -p tsconfig.app.json --noEmit (exit 0)
  • Docker/deployment check, if relevant (not relevant)

New tests fail without the fix and pass with it:

  • End to end (buildImportPlan): the issue's repro with a .dark override; two font names normalising alike both kept; a font name never taking a colour slug.
  • Unit (normalizeImportedTokens): a colour never takes a font's name and a font never takes a colour's; fix(siteImport): rewrite var() references to the slug a colour token is emitted under #618's colour cases carried over.
  • Conflict pipeline: an authored --font-Primary against an existing font-primary token is detected as font-primary, auto-renamed to font-primary-2, and its references follow.

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed (docs/features/site-import.md).
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

…is emitted under

Site Import turned root colour custom properties into framework tokens,
which the framework emits under the normalised slug
(`--brand---neutral--700` -> `--brand-neutral-700`), but left the imported
`var()` references on the authored name, so they no longer resolved.

The slug is now settled at plan time by `normalizeImportedColorTokens`,
and every changed name is rewritten in the imported style rules and node
inline styles before conflict detection, so the conflict step and the
commit see the emitted name. Two names that normalise to the same slug
both survive with a numeric suffix instead of one being dropped at commit.

Token renames (normalisation and conflict renames) now also rename
declarations of the variable in other rules, their priorities, and raw
@Keyframes CSS, so a `.dark { --bg: ... }` override follows its token.
Conflict rename targets skip the import's other token names and any
custom property the imported CSS declares, and a colour custom rename is
normalised like the slug it becomes.

The rename helpers move from conflicts.ts into siteImport/varRefs.ts,
which keeps conflicts.ts under the 700-line module budget.

Fixes CoreBunch#615
…n is emitted under

Site Import normalised a root `--font-*` variable at extraction
(`--font-Heading` -> `font-heading`), and the store emits that form, but
the imported `var(--font-Heading)` references kept the authored name and
no longer resolved. Two authored names that normalise alike were deduped
into one token, losing a font.

Extraction now keeps the authored variable, and `normalizeImportedTokens`
(new `siteImport/tokenNames.ts`) settles the emitted name of every
imported colour and font token at plan time, in one pass against one set
of claimed names, since both kinds share one CSS namespace. The
`authored -> emitted` renames go through the existing var() and
declaration rewrite, before conflict detection.

`normalizeImportedColorTokens` is replaced by `normalizeImportedTokens`.

Fixes CoreBunch#619

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Import: imported font tokens are renamed, but var() references to them are not rewritten

1 participant