fix(design-tokens): backfill generationRule for legacy semantic tokens#1433
Open
fix(design-tokens): backfill generationRule for legacy semantic tokens#1433
Conversation
Semantic tokens persisted by rafters versions before the generationRule fix shipped have dependsOn but no generationRule. populateDependencyGraph silently skipped them, so semantic cascade was dormant on every existing project: changing a family's seed only updated the seed, not the variants. Self-heal at registry init: infer the rule from name suffix (-foreground -> contrast:auto, -hover -> state:hover, etc.) plus dependsOn[0] for scale position. No on-disk migration; in-memory backfill writes back through the normal persist path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The /-(\d+)$/ token-name parser was inlined three times (registry.ts, plugins.ts twice). Consolidate into scale-positions.ts where the rest of the position math lives. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Existing rafters projects' on-disk
semantic.rafters.jsonwas authored beforesemantic.tsstarted writinggenerationRule.populateDependencyGraphrequires bothdependsOnANDgenerationRuleto enter the dependency graph, so legacy semantic tokens are silently skipped at registry init -- the cascade is dormant on every project initialized before the fix shipped.Verified in this repo: 198/198 semantic tokens in
.rafters/tokens/semantic.rafters.jsonhavegenerationRule = null. Settingaccentto a new family via the studio API would update only the seed; every variant (-foreground,-hover,-active,-border,-ring) would stay pointing at the previous family. Designer sees a half-themed UI.Self-heal at registry init by inferring the rule from the token name suffix and
dependsOn[0]shape:-foreground/-text/-contrast->contrast:auto-hover/-active/-focus/-disabled->state:*scale:Nfrom value position ordependsOn[0]suffixIn-memory only -- no on-disk migration. The next normal write through the persist path picks up the backfilled rule.
Includes a small refactor: extracted
parseTokenPosition()toscale-positions.tsto consolidate three inlined copies of the same regex.Test plan
legacy semantic token backfilldescribe block inpackages/design-tokens/test/semantic-cascade.test.tscascades semantic tokens loaded without generationRule-- stripsgenerationRulefrom generated tokens, constructs registry, cascades neutral, asserts primary + primary-hover + primary-foreground all followpreserves explicit generationRule when present-- regression guard so live-generated tokens still carry their explicit rule🤖 Generated with Claude Code