Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When parsing tokens stored on the local document, first de-duplicate tokens #2779

Open
six7 opened this issue May 20, 2024 · 0 comments · May be fixed by #2807
Open

When parsing tokens stored on the local document, first de-duplicate tokens #2779

six7 opened this issue May 20, 2024 · 0 comments · May be fixed by #2807
Assignees
Labels
bug Something isn't working json files plugin v2 variables, UI, WTCG format, Bitbucket

Comments

@six7
Copy link
Collaborator

six7 commented May 20, 2024

We had a bug that came with #2778 that basically means we store the same token name multiple times. Basically we had an array like this:

  [
    {
        "value": "4",
        "type": "sizing",
        "name": "foo.bar"
    },
    {
        "name": "foo.bar",
        "value": "14",
        "type": "sizing"
    }
]

This is a problem! Because we will have the same token exist multiple times.

To reproduce:

  • Create a token with a name foo.bar and another token with a name otherfoo.bar
  • Right click the group foo and click Rename.
  • Enter otherfoo.

Now if you go to packages/tokens-studio-for-figma/src/plugin/node.ts in getTokenData and add a console log to output the stored token values on line 118: console.log('Getting tokens', values, themes, activeTheme, version, tokenFormat); you will see that there's actually 2 tokens with the same name.

So, when we perform getTokenData in packages/tokens-studio-for-figma/src/plugin/node.ts, after parsing the tokens array from the document, let's de-duplicate that array and prefer the last one appearing (because likely users had been editing tokens and that's the token they've seen)

This is another reason to rather use a map-based token storage everywhere, but for this issue, let's just make sure that we fix existing user's data that's on our users documents by de-duplicating before we pass it on. This should make sure that users won't have faulty data stored.

#2778 will prohibit this from appearing in the first place but we should fix our stored data with this issue.

@six7 six7 added bug Something isn't working plugin v2 variables, UI, WTCG format, Bitbucket labels May 20, 2024
@macintoshhelper macintoshhelper self-assigned this May 30, 2024
@macintoshhelper macintoshhelper linked a pull request May 30, 2024 that will close this issue
@six7 six7 linked a pull request Jun 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working json files plugin v2 variables, UI, WTCG format, Bitbucket
Projects
Status: 🕜 In Progress
Development

Successfully merging a pull request may close this issue.

3 participants