Skip to content

fix(createTokens): follow a {alias} reached through a segment path#589

Merged
johnleider merged 2 commits into
masterfrom
worktree-fix+tokens-segment-alias-rc
Jul 15, 2026
Merged

fix(createTokens): follow a {alias} reached through a segment path#589
johnleider merged 2 commits into
masterfrom
worktree-fix+tokens-segment-alias-rc

Conversation

@johnleider

@johnleider johnleider commented Jul 14, 2026

Copy link
Copy Markdown
Member

Extracts the RB-5 root fix from #566 (Group A, item #1) as a minimal, RC-scoped patch. Only the segment-path alias correctness is here; #566's other three changes (direct-TokenAlias-literal semantics, outer-key caching, resolve<T> type param) stay in that PR for post-RC.

The bug

resolve()'s segment-path branch assigned the terminal value to result without following a trailing {alias}. A dotted-segment lookup that lands on an alias string returned the raw '{alias}' instead of its resolved value. The leaf-value branch already re-resolved terminal aliases; the segment branch didn't.

createTokens(
  { colors: { primary: '#00f' }, group: { blue: '{colors.primary}' } },
  { flat: true },
).resolve('{group.blue}') // was '{colors.primary}', now '#00f'

Why it matters for RC

useTheme resolves theme colors through a flat: true token table, where nested groups are stored whole and addressed by segment. A palette entry that is itself an alias, referenced by a theme via a dotted alias, produced an unresolved {alias}:

  • Through the built-in adapters it was droppedThemeAdapter.generate()'s UNSAFE_CSS guard rejects any value containing {/}, so the CSS variable went missing (wrong/unset color).
  • Read directly off theme.colors.value (inline :style, canvas, handing colors to another lib) it leaked the literal {alias} string.

useTheme is marked stable, so this is a frozen-surface correctness bug. Fix is at the single source (createTokens.resolve); no useTheme change needed.

The fix

Mirror the leaf branch's terminal alias-follow into the segment branch, reusing the visited set so circular detection still holds:

if (isString(current) && isAlias(current)) return resolve(current, visited)

Tests

Three regression cases under segment-path terminal alias (#566) — single-hop resolution, multi-hop chain, and a circular reference reached through a segment path. All three fail against the pre-fix branch (return raw {alias}; the circular case bypasses detection entirely) and pass with the fix.

Verification

  • createTokens unit suite 253/253; useTheme / useFeatures / useLocale / usePermissions 304/304
  • pnpm typecheck clean (0/paper/genesis); knip + sherif clean

Relationship to open PRs

The segment-path branch of resolve() assigned a terminal value to the
result without following a trailing {alias}, so a dotted-segment lookup
landing on an alias string returned the raw '{alias}' instead of its
resolved value. The leaf-value branch already re-resolved terminal
aliases; the segment branch now mirrors it, reusing the visited set so
circular detection still holds.

Surfaces through useTheme, which resolves theme colors through a
flat: true token table: a palette entry that is itself an alias,
referenced by a theme via a dotted alias, previously produced an
unresolved {alias} (dropped by the CSS brace guard, or leaked literally
to consumers reading theme.colors directly).

Ref #566 (Group A, item #1)
@johnleider johnleider added this to the v1.0.0 milestone Jul 14, 2026
@johnleider johnleider added T: bug Something isn't working E: createTokens Composable labels Jul 14, 2026
@johnleider johnleider self-assigned this Jul 14, 2026
Regression tests for the #566 fix: a {alias} reached through a dotted
segment lookup must be followed (single hop and multi-hop chain), and a
circular reference reached that way must be detected rather than leaking
a raw {alias}. All three fail against the pre-fix segment branch.
@johnleider
johnleider marked this pull request as ready for review July 14, 2026 23:29
@johnleider
johnleider merged commit 3b5565d into master Jul 15, 2026
19 checks passed
@johnleider
johnleider deleted the worktree-fix+tokens-segment-alias-rc branch July 15, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

E: createTokens Composable T: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant