Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Problem

The current variable synchronization process automatically updates all variables, including existing ones. For teams with formal review and version control processes, this behavior is risky as it provides no visibility into what changes will be made before they're applied.

Solution

This PR implements a comprehensive Variable Sync Preview system that shows users exactly what will change before any variables are created, updated, or deleted. Users can then selectively choose which changes to apply.

Key Features

🔍 Sync Preview Modal

  • Shows all potential changes categorized as "To Be Created", "To Be Updated", and "To Be Deleted"
  • Displays detailed information including current vs new values, descriptions, and collection context
  • Provides a clear summary of the scope of changes before any action is taken

⚙️ Granular Control

  • Category-level toggles: Ignore entire categories (e.g., only create new variables, don't update existing ones)
  • Individual selection: Cherry-pick specific variables within each category
  • Default behavior: All changes are selected by default, maintaining existing workflow for users who want everything

🚀 Optimized Architecture

  • Preview phase analyzes all potential changes once and stores token metadata
  • Apply phase works directly from preview results without re-computation
  • Eliminates logic duplication between preview and actual variable creation

Technical Implementation

New Async Messages:

PREVIEW_VARIABLE_SYNC // Analyzes and categorizes potential changes
APPLY_VARIABLE_CHANGES // Applies only selected changes efficiently

Enhanced UI Flow:

  1. User clicks "Export to Figma" → Preview modal appears
  2. User reviews categorized changes with detailed before/after information
  3. User selects desired changes using category toggles and individual checkboxes
  4. System applies only approved changes without re-analyzing tokens

Example Preview Output:

  • To Be Created (5): New color tokens for dark theme
  • To Be Updated (2): Primary button color changed from #007AFF to #0066CC
  • To Be Deleted (1): Unused spacing token no longer referenced

Benefits

  • Safety: Teams can review all changes before application
  • Flexibility: Granular control from category-level down to individual variables
  • Efficiency: No performance impact - preview results are reused during application
  • Transparency: Clear visibility into what will change and why

This addresses the core need for safer variable syncing while maintaining the existing workflow for users who want to apply all changes automatically.

Original prompt

This section details on the original issue you should resolve

<issue_title>Provide Granular Control Over Variable Syncing</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
The current variable synchronisation process automatically updates all variables, including existing ones. For teams with a formal review and version control process for management, this behavior is risky. Users need a safer way to sync new variables without affecting existing, approved ones.

Describe the solution you'd like
Instead of a simple "create only" mode, we should implement a more comprehensive and flexible solution. Before any changes are applied, the user should be presented with a "Sync Preview" screen. This screen would provide a summary of all potential changes, categorised as follows:

  • To Be Created: A list of new variables that do not exist in the current environment.
  • To Be Updated: A list of existing variables whose values would be changed.
  • To Be Deleted: A list of variables that exist locally but are not in the source, which would be removed.

Users should be given a choice to ignore certain parts - e.g. individual tokens, to not be created/updated/deleted. (should be a toggle to ignore/not ignore), by default the user just needs to Confirm for it to take action on all those.
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3592

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI assigned Copilot and six7 Sep 25, 2025
Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: bd3118f

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

Copilot AI and others added 4 commits September 25, 2025 10:46
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Provide Granular Control Over Variable Syncing Add granular variable sync preview with selective application Sep 25, 2025
@Copilot Copilot AI requested a review from six7 September 25, 2025 11:08
Copilot finished work on behalf of six7 September 25, 2025 11:08
Copy link
Contributor

github-actions bot commented Sep 26, 2025

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

Copy link
Contributor

Commit SHA:854b7b7e190183e556d922e24b475d0601190cb6

Test coverage results 🧪

Code coverage diff between base branch:main and head branch: copilot/fix-fc37fc54-e3d7-4713-a40e-abf89ef0d728 
Status File % Stmts % Branch % Funcs % Lines
🔴 total 63.98 (-1.32) 55.73 (-1.27) 61.39 (-1.13) 64.33 (-1.32)
✨ 🆕 packages/tokens-studio-for-figma/src/app/components/VariableSyncPreviewModal.tsx 0.97 0 0 1.06
🟢 packages/tokens-studio-for-figma/src/plugin/controller.ts 98.27 (0.06) 100 (0) 75 (0) 100 (0)
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/applyVariableChanges.ts 25 100 0 25
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/previewVariableSync.ts 25 100 0 25

Copy link
Contributor

Commit SHA:854b7b7e190183e556d922e24b475d0601190cb6
Current PR reduces the test coverage percentage by 1 for some tests

six7 added 11 commits September 26, 2025 22:14
- Ensure collections are created using the same logic as original createLocalVariablesInPlugin
- Fix collection/mode determination in handleCreateVariable to properly match themes
- Add explicit collectionName for token sets to use 'Default' collection
- Prevent variables from being created in separate collections incorrectly

This maintains the 1:1 logic where variables are organized by theme groups while only creating the actual changes that were selected in the preview.
- Add debug logs to previewVariableSync to trace token data capture
- Add debug logs to applyVariableChanges to trace the creation process
- Add debug logs to all setter functions (color, number, string, boolean)
- Fix setter functions to properly handle new variables (undefined existingValue)
- This should help identify why variables are created with blank values
- Add special handling for TokenTypes.FONT_WEIGHTS that come as arrays
- Use token.value[0] for font weight arrays (same as original logic)
- This fixes issue where font weights like ['Regular'] were not being set properly
- Now font weight variables will get the correct string value instead of 'String value'
- Add normalizeTokenValue() function to handle font weight arrays early
- Apply normalization in preview generation, not at variable creation
- Store normalized values in tokenData to ensure consistency
- This prevents font weights from always appearing as 'changed' in preview
- Fixes comparison logic between existing variables and new values
- Both preview display and variable creation now use the same normalized values
- Improve getCurrentVariableValue() to properly format Figma variable values
- Add proper handling for color objects (RGB/RGBA) using figmaRGBToHex
- Add proper formatting for variable references, booleans, numbers, strings
- Improve getFormattedTokenValue() to handle complex references properly
- Add comprehensive debug logging to shouldUpdateVariable()
- This fixes 'apples to oranges' comparisons that showed false changes
- Colors now compare '#2d3748' vs '#2d3748' instead of '[object Object]' vs '#2d3748'
- References compare '{dimension.xs}' vs '{dimension.xs}' properly
- Modify getFormattedTokenValue() to use resolved values instead of rawValue expressions
- Only treat as reference if the resolved VALUE contains unresolved curly braces
- Add proper handling for empty/null/undefined token values
- Add comprehensive debug logging to token set processing
- This should fix issues where preview showed '{dimension.xs} * {dimension.scale}'
  but actual resolved value was '8', causing false change detection
- Now both current and new values should show actual resolved numbers/strings
- Resolve variable aliases to their actual values instead of showing as references
- Add proper rounding (3 decimal places) to prevent precision mismatches
- Try to resolve referenced variables to numbers/strings/colors when possible
- Only show as reference when the value truly can't be resolved
- Apply consistent rounding to both current and new values for comparison
- This should fix: 'Current: {dimension.xs} New: 4' → 'Current: 4 New: 4'
- And: 'Current: 13.600000381469727 New: 13.6' → 'Current: 13.6 New: 13.6'
- Improve mode-aware reference resolution (same collection = same mode, different collection = find matching mode name)
- Add smart reference comparison to avoid resolving references unnecessarily
- When both current and new values are references, compare reference names directly
- Only fallback to value comparison when reference comparison fails
- Add comprehensive debug logging for mode selection and reference resolution
- Fix TypeScript type issues with VariableAlias type checking
- This should fix issues where Light/Dark mode variables got wrong values
- And where {accent.default} vs #7f9cf5 showed as different when referencing same value
- Reduce verbose debug output to essential information
- Focus on mode-specific operations: CREATE/UPDATE with mode names
- Show variable values and reference resolution clearly
- Remove excessive object dumping and repetitive logs
- Key logs now: variable reads, reference chains, update decisions
- This should make it easier to identify Dark mode creation/update issues
- Change preview logic from theme-centric to collection-centric approach
- Group themes by collection name and process all tokens from all modes
- Ensure each variable gets preview entries for ALL modes in its collection
- Fix issue where only first mode was updated in Light/Dark collections
- Resolve 'second mode is never updated' problem
- Clean up duplicate function definitions and fix linting issues
- Add progress tracking document for future reference

Fixes the core multi-mode variable processing issue in variable sync preview.
- Add theme selection and processing visibility
- Show token generation statistics per theme
- Log UPDATE/SKIP/CREATE decisions per theme
- Add final summary breakdown by mode
- Reduce debug noise, focus on critical decision points
- Ready to identify why Dark mode shows 'No changes'

This will help determine:
- Whether Dark theme is processed at all
- Whether tokens are generated for Dark theme
- What comparison logic causes false 'no changes'
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.

Provide Granular Control Over Variable Syncing
2 participants