Skip to content

fix(siteImport): rewrite var() references to the slug a colour token is emitted under - #618

Open
ehnruiz wants to merge 1 commit into
CoreBunch:mainfrom
ehnruiz:fix/import-color-token-refs
Open

ehnruiz wants to merge 1 commit into
CoreBunch:mainfrom
ehnruiz:fix/import-color-token-refs

Conversation

@ehnruiz

@ehnruiz ehnruiz commented Oct 11, 2026 •

Copy link
Copy Markdown

Summary

Fixes #616. Site Import turns root-scope colour custom properties into framework colour tokens, and the framework emits each under its normalised slug (normalizeFrameworkColorSlug), so --brand---neutral--700 becomes --brand-neutral-700. The imported var(--brand---neutral--700) references kept the authored name and no longer resolved. On the real 7-page Webflow site in the issue, that left 56 references (23 variables) unresolved.

What changed:

  • Slug settled at plan time. normalizeImportedColorTokens (colorTokens.ts) gives each extracted token the slug the framework will emit and returns an authored → emitted map. buildImportPlan applies it, rewrites the imported var() references in style rules and node inline styles, and only then detects conflicts, so the conflict step, the review UI and the commit all see the emitted name.
  • Collisions keep both tokens. Two authored names that normalise to the same slug (--Brand / --brand, --a--b / --a-b) used to lose one token silently at commit (addImportedColorTokens skips a slug it has already added). Now the name already in emitted form keeps it, and the other takes a -2, -3, ... suffix. A new name also avoids the other custom properties the imported CSS declares.
  • Declarations follow their token. A token rename (normalisation, or a conflict rename) now also renames declarations of the variable in other rules, their !important priorities, and raw @keyframes CSS. Without this, a .dark { --brand---bg: #000 } override would stay on the old name and stop overriding. For conflict renames this changes existing behaviour: an imported override of a renamed token used to override the site's same-named token instead.
  • Conflict rename targets avoid the import's own names. An auto-rename used to reserve only the site's existing slugs, so it could land on another imported token's name.
  • Custom renames are normalised. A colour custom rename (Hero BG) now renames references to the slug it is stored under (hero-bg).
  • New module. The rename helpers move from conflicts.ts to a new siteImport/varRefs.ts, which keeps conflicts.ts under the 700-line module budget.

Not changed, worth a follow-up:

Verification

  • bun run build (exit 0)
  • bun test on this commit (9125aaa): 7047 pass, 0 fail (exit 0) on a quiet machine.
    • An earlier full run on a heavily loaded machine (load average 100–200) failed hundreds of tests on timeouts. Re-running those files with --timeout 60000 found one real failure: module-size-budgets (conflicts.ts at 743 lines). The varRefs.ts split fixes it.
    • bun x madge --circular --ts-config tsconfig.json --extensions ts,tsx src server exits 0 with "No circular dependency found!"
  • 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, plus a :root alias, a .dark override and an inline style reference.
  • Unit tests for normalizeImportedColorTokens: renames, collisions, declared names.
  • Conflict tests:
    • auto-rename skips another imported token's slug and a declared variable;
    • a normalised name meeting a conflict rename keeps both colours;
    • a custom rename is normalised;
    • declarations and priorities are renamed;
    • a font declaration is renamed;
    • raw @keyframes declarations are renamed.

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

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 color tokens are renamed, but var() references to them are not rewritten

1 participant