tokens-studio / figma-plugin

Official repository of the plugin 'Tokens Studio for Figma' (Figma Tokens)
https://www.figma.com/community/plugin/843461159747178978
MIT License
1.34k stars 194 forks source link

fixes variable references not using reference of current theme #2806

Closed six7 closed 2 months ago

six7 commented 3 months ago

Why does this PR exist?

Closes #2798

Previously when creating variables and different theme groups were affecting the same token structure (e.g. to avoid the figma mode limit), sometimes users would end up with the wrong references.

What does this pull request do?

Adjust the logic around mergeVariableReferences where we now use references from only the selected sets, not from all created themes. This was a mistake in the first place.

Testing this change

Create the following sets:

{
  "global": {
    "red": {
      "$value": "#ff0000",
      "$type": "color"
    }
  },
  "globalB": {
    "red": {
      "$value": "#f80",
      "$type": "color"
    }
  },
  "semanticA": {
    "warning": {
      "$value": "{red}",
      "$type": "color"
    }
  },
  "semanticB": {
    "warning": {
      "$value": "{red}",
      "$type": "color"
    }
  }

and then create theme groups like this:

CleanShot 2024-05-30 at 11 18 34@2x image

And create variables - one theme group at a time (first A, then B). The references will then pick the right ones. If you create all themes at once, it will still have the wrong reference, as it will just use the red reference from the first theme.

Additional Notes (if any)

I don't think this is the final solution. I'd love for us to isolate the variable creation and update logic and possibly extract that to its own package. As in we pass in a list of tokens and a theme configuration, and the package handles everything when it comes to creation and updates of variables. Right now variable creation and updating that one is quite scattered and really hard to follow (not having worked on the original solution I found it hard to grasp how everything tied together)

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: edb7a70bb2a3c202cbbc5357af9619ba07f9ee2e

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