Fix $description handling at group and root level for DTCG compliance #3640
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.
Problem
The Tokens Studio Figma plugin does not correctly handle
$descriptionproperties at the group level or root level according to the DTCG specification Section 6.1.1. Instead of preserving them as plain strings, the plugin was:{"$type": "other", "$value": "..."}structure, which violates the DTCG specificationExample of the issue:
According to the DTCG spec: "Groups MAY include an optional
$descriptionproperty, whose value MUST be a plain JSON string containing a human-readable description of the group."Solution
This PR fixes the issue by treating
$description(and$extensions) as metadata properties rather than tokens:1. Metadata Filtering
isMetadataKey()helper to identify metadata keys ($description,$extensions)checkForTokens()to skip metadata keys during iteration2. Metadata Preservation Infrastructure
TokenSetMetadatatype to store group and root level metadataTokenStoretype to include optionalmetadatafieldconvertToTokenArray()to capture and return metadata alongside tokensconvertTokensToObject()andstringifyTokens()to restore metadata when providedChanges
Core files:
src/utils/convertTokens.tsx- Added metadata filtering and collection logicsrc/types/tokens/TokenSetMetadata.ts- New type for storing group/root metadatasrc/types/tokens/TokensStore.ts- Added optional metadata field to storesrc/utils/convertTokensToObject.ts- Added metadata restoration during object conversionsrc/utils/stringifyTokens.ts- Added metadata restoration during stringificationsrc/utils/parseTokenValues.ts- Updated to handle new return type fromconvertToTokenArray()Tests:
src/utils/convertTokens.test.ts- Added test verifying group/root descriptions are not converted to tokenssrc/utils/convertTokensToObject.test.ts- Added test for metadata preservationsrc/utils/convertTokens.roundtrip.test.ts- New comprehensive round-trip testsTesting
✅ All existing tests pass (270 of 271 test suites - 1 unrelated pre-existing failure)
✅ New tests verify group/root descriptions are not converted to tokens
✅ Round-trip tests verify full metadata preservation when provided via API
✅ Verified backward compatibility - metadata parameter is optional
Backward Compatibility
This change is fully backward compatible:
metadataparameter is optional in all modified functionsImpact
$descriptionwas incorrectly treated as a tokenFixes the core issue where group-level and root-level
$descriptionproperties were being treated as tokens instead of metadata, ensuring compliance with the DTCG specification.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.