Skip to content

fix: resolve mode-specific baseFontSize for rem scaling in variable e…#3836

Open
akshay-gupta7 wants to merge 4 commits intomainfrom
akshay/fix-per-theme-rem-exportg
Open

fix: resolve mode-specific baseFontSize for rem scaling in variable e…#3836
akshay-gupta7 wants to merge 4 commits intomainfrom
akshay/fix-per-theme-rem-exportg

Conversation

@akshay-gupta7
Copy link
Copy Markdown
Contributor

@akshay-gupta7 akshay-gupta7 commented Apr 8, 2026

…xport

Why does this PR exist?

Closes #3800

This PR addresses issues with baseFontSize resolution when exporting variables to Figma. Previously, numeric or aliased font sizes (especially those involving math evaluation) were not correctly handled during per-mode exports, leading to inconsistent scaling across different modes in the same collection.

What does this pull request do?

  • Improved baseFontSize Resolution: Updated updateVariables.ts to correctly handle number types and evaluate aliases for baseFontSize, ensuring consistent string conversion.
  • Fixed Variable Update Logic: Corrected a logical check in setStringValuesOnVariable.ts that was preventing some existing variable values from being updated correctly.
  • Enhanced Test Reliability:
    • Added tests for math-evaluated font sizes and per-mode rem scaling.
    • Updated updateVariables.test.ts to use isolated variable mocks, ensuring that scaling validation is accurate and free from side effects of shared mocks.

Testing this change

  1. Open the plugin and ensure baseFontSize is set (either as a numeric value or an alias like {typography.baseline}).
  2. Export variables to a Figma collection with multiple modes.
  3. Verify that rem values (e.g., 1rem spacing) are correctly translated to pixels based on the specific baseFontSize defined for each theme/mode.

Automated Tests:
Run the updated test suite:

yarn test src/plugin/updateVariables.test.ts

Additional Notes (if any)

The test mock isolation was necessary because base/font-size and other variables were sharing the same setValueForMode mock, which could hide bugs where specific variables weren't being updated.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 8, 2026

🦋 Changeset detected

Latest commit: e19baf1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tokens-studio/figma-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

⤵️ 📦 ✨ The artifact was successfully created! Want to test it? Download it here 👀 🎁

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Commit SHA:2fa1b4cf4417baf2d38ba09a8d277fbb32165bf5

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: akshay/fix-per-theme-rem-exportg 
Status File % Stmts % Branch % Funcs % Lines
🟢 total 61.51 (0) 53.02 (0.03) 59.29 (0) 61.9 (0)
🟢 packages/tokens-studio-for-figma/src/plugin/updateVariables.ts 96.15 (0) 78.57 (11.91) 100 (0) 96.15 (0)
🟢 packages/tokens-studio-for-figma/src/utils/mapTokensToVariableInfo.ts 100 (0) 87.5 (12.5) 100 (0) 100 (0)

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Figma plugin variable export flow to correctly resolve a theme/mode-specific baseFontSize (including when alias resolution yields a numeric result) so rem/em scaling is computed correctly per mode.

Changes:

  • Allow settings.aliasBaseFontSize to override baseFontSize when getAliasValue returns either a string or a number.
  • Adjust variable setters to allow writing values when a mode has no existing value (instead of returning early).
  • Add/extend Jest tests for numeric alias results and per-mode base font size behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/tokens-studio-for-figma/src/plugin/updateVariables.ts Accept numeric alias-resolved base font sizes and apply per-theme base font size during variable mapping/export.
packages/tokens-studio-for-figma/src/plugin/updateVariables.test.ts Adds tests for numeric baseFontSize alias results and mode-specific baseFontSize handling.
packages/tokens-studio-for-figma/src/plugin/setStringValuesOnVariable.ts Updates early-return logic so unset modes can be written to.
packages/tokens-studio-for-figma/src/plugin/setNumberValuesOnVariable.ts Updates early-return logic so unset modes can be written to.
packages/tokens-studio-for-figma/src/plugin/setColorValuesOnVariable.ts Updates early-return logic so unset modes can be written to.
packages/tokens-studio-for-figma/src/plugin/setBooleanValuesOnVariable.ts Updates early-return logic so unset modes can be written to.

@akshay-gupta7 akshay-gupta7 marked this pull request as ready for review April 10, 2026 07:02
@akshay-gupta7 akshay-gupta7 requested a review from six7 April 10, 2026 07:03
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.

Bug: Token reference in baseFontSize no longer resolves per theme during Variables/Styles export

2 participants