Instatic icon indicating copy to clipboard operation
Instatic copied to clipboard

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

Open ehnruiz opened this issue 1 month ago • 0 comments

Summary

When Site Import turns root-scope --font-* custom properties into font tokens, it stores each under its normalised variable and the publisher emits that name, but the var() references in the imported style rules keep the authored name. A font variable whose name changes under normalisation (uppercase letters, or runs of dashes) is then undefined, and the text falls back to the inherited font with no warning.

This is the font-token counterpart of #615 (colour tokens). #618 fixes the colour path and leaves fonts for a separate change.

Steps to reproduce

  1. Import a static site whose stylesheet contains:
    :root {
      --font-Heading: "Acme Grotesk", serif;
      --font-body--alt: "Inter", sans-serif;
      --font-display: "Acme Grotesk", serif;
    }
    .title { font-family: var(--font-Heading); }
    .body  { font-family: var(--font-body--alt); }
    .hero  { font-family: var(--font-display); }
    
  2. Accept the font tokens in the review step, then publish.
  3. Open the published CSS.

Expected behavior

Every var(--font-…) in the imported rules resolves to its font token: either the token keeps its authored name, or the references are rewritten to the emitted name.

Actual behavior

  • The plan's font tokens are font-heading, font-body-alt and font-display, and the published CSS defines --font-heading, --font-body-alt and --font-display.
  • .title still uses var(--font-Heading) and .body still uses var(--font-body--alt). Neither name is defined anywhere, so both lose their font. .hero works only because its name survives normalisation.

The cause appears to be in src/core/siteImport/fontTokens.ts:96, where extractRootFontTokens stores normalizeFontTokenVariable(prop) (lowercase, every run of non-alphanumerics collapsed to one -). fontTokenCssVariable emits the same normalised form (src/core/fonts/css.ts:163), and nothing maps the authored name to it for the rules that reference it. Two authored names that normalise to the same variable (--font-Heading and --font-heading) are also deduplicated into one token, so the second font is lost.

A possible fix is the approach in #618 for colour tokens: settle the emitted name at plan time, record authored → emitted, and rewrite var() references and declarations through the same rename path conflict renames use (siteImport/varRefs.ts in #618).

Reproduced at f92e8dc with buildImportPlan on the CSS above: fontTokens → ["font-heading", "font-body-alt", "font-display"], .title → var(--font-Heading), .body → var(--font-body--alt).

Version or commit

0.0.20 (f92e8dc, current main)

Deployment mode

Local, bun run start (SQLite), Bun 1.4.2, macOS

ehnruiz avatar Oct 11 '26 08:10 ehnruiz