figma-plugin icon indicating copy to clipboard operation
figma-plugin copied to clipboard

Remove unused 'id' field functionality from studio.tokens extension and add cleanup logic for legacy tokens

Open Copilot opened this issue 6 months ago • 3 comments

Summary

This PR removes all functionality related to the automatically generated 'id' field in the studio.tokens extension while adding backward compatibility to clean up existing ID fields when parsing tokens. The id field was being added to tokens but never actually used anywhere in the codebase, making it unnecessary overhead.

Changes Made

Removed Utility Functions

  • addIdPropertyToTokens.ts - Completely removed this utility that was adding UUIDs to tokens
  • removeTokenId.ts - Removed utility for stripping IDs from tokens
  • removeIdPropertyFromTokens.ts - Removed batch ID removal utility

Added Cleanup Logic

  • cleanupTokenExtensions.ts - New utility function that removes 'id' fields from studio.tokens extensions during token parsing
  • Updated convertToTokenArray - Integrated cleanup logic to automatically remove legacy ID fields when parsing tokens
  • Comprehensive tests - Added test coverage for the cleanup functionality to ensure proper removal of ID fields

Updated Core Token Handling

  • tokenState.tsx - Removed all calls to addIdPropertyToTokens() and UUID imports
  • updateTokenPayloadToSingleToken.ts - Simplified to no longer generate or include IDs and refactored for better code quality
  • Token formatting utilities (stringifyTokens.ts, formatTokens.ts, convertTokensToObject.ts) - Removed ID-related parameters and processing

Updated Components and Storage

  • Removed storeTokenIdInJsonEditor parameter usage from components like PushJSON.tsx and MultiFilesExport.tsx
  • Updated storage providers (GitSyncOptimizer.ts, RemoteTokenStorage.ts) to use simplified function signatures
  • Cleaned up unused imports and variables

Test Updates

  • Updated test expectations to no longer expect ID fields in token objects
  • Removed UUID mocks that are no longer needed
  • All core functionality tests continue to pass

Impact

Before:

{
  "name": "primary",
  "type": "color", 
  "value": "#ff0000",
  "$extensions": {
    "studio.tokens": {
      "id": "abc-123-def-456"
    }
  }
}

After:

{
  "name": "primary",
  "type": "color",
  "value": "#ff0000"
}

Benefits

  • Reduced complexity: Eliminates unnecessary ID generation and management code
  • Better performance: Removes UUID generation overhead for every token operation
  • Cleaner data: Token objects are now simpler without unused metadata
  • Smaller payload: Reduced memory usage and serialization size
  • Backward compatibility: Automatically cleans up legacy ID fields from existing tokens during parsing

No breaking changes to user-facing functionality since the IDs were never exposed or used in the UI or token operations. Users with existing tokens containing ID fields will have them automatically removed during parsing.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 09 '25 06:09 Copilot

🦋 Changeset detected

Latest commit: 6e4363837ad79af8d6162a92ee48805bb14747e7

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

changeset-bot[bot] avatar Sep 09 '25 06:09 changeset-bot[bot]

@copilot shall we have some logic in still on parse? When users would still have this in their tokens, remove it.

six7 avatar Sep 09 '25 07:09 six7

@copilot shall we have some logic in still on parse? When users would still have this in their tokens, remove it.

Added cleanup logic in convertToTokenArray function to automatically remove legacy 'id' fields from studio.tokens extensions during token parsing. This ensures backward compatibility for users who still have ID fields in their existing token files. The cleanup removes the ID field and cleans up empty extension objects. Commit: 6e43638

Copilot avatar Sep 09 '25 07:09 Copilot