Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 11, 2025

Problem

When users launch the plugin or pull variables from Figma without any stored active theme information, no theme is automatically enabled. This requires users to manually select a theme even when themes are available, creating unnecessary friction in the workflow.

Solution

This PR implements automatic activation of the first available theme when:

  • No active theme is currently set (activeTheme is empty {})
  • Themes are available in the plugin

The auto-enable behavior occurs in two key scenarios:

  1. On plugin startup - When loading token data via setTokenData
  2. When pulling variables - When pulling variables from Figma via setThemesFromVariables

Implementation Details

The solution modifies two key reducers to detect when no active theme is set and automatically enable the first available theme:

setThemesFromVariables (when pulling variables)

// Auto-enable the first theme if no active theme is set and themes are available
const hasActiveTheme = Object.keys(state.activeTheme).length > 0;
const allThemes = [...state.themes, ...newThemes];

if (!hasActiveTheme && allThemes.length > 0) {
  const firstTheme = allThemes[0];
  const groupKey = firstTheme.group || INTERNAL_THEMES_NO_GROUP;
  newActiveTheme = { [groupKey]: firstTheme.id };
  
  // Update usedTokenSet based on the first theme's selectedTokenSets
  // ... (enables the appropriate token sets)
}

setTokenData (on plugin startup)

Similar logic is applied when loading token data during plugin initialization, ensuring the first theme is auto-enabled if no active theme exists.

Both functions update not only activeTheme but also usedTokenSet based on the theme's selectedTokenSets, ensuring that the correct token sets are properly enabled when the theme is activated.

Theme Group Handling

  • If a theme has a group property, it's used as the key in activeTheme
  • If a theme has no group, the INTERNAL_THEMES_NO_GROUP constant is used
  • This matches the existing theme management behavior throughout the plugin

Testing

Added comprehensive test suite covering:

  • ✅ Auto-enabling first theme with groups
  • ✅ Auto-enabling first theme without groups (using INTERNAL_THEMES_NO_GROUP)
  • ✅ Preserving existing active theme when one is already set
  • ✅ Not auto-enabling when no themes are available

All existing tests continue to pass, confirming backward compatibility.

Changeset

Created a patch-level changeset as required by repository guidelines.

Original prompt

When we dont have information on what Themes are active or not, make it so the first theme option is always enabled when launching the plugin or pulling


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

@changeset-bot
Copy link

changeset-bot bot commented Oct 11, 2025

🦋 Changeset detected

Latest commit: 8b98e1d

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 2 commits October 11, 2025 12:35
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Co-authored-by: six7 <4548309+six7@users.noreply.github.com>
Copilot AI changed the title [WIP] Ensure first theme option is enabled by default Auto-enable first theme when no active theme is set on plugin launch or pull Oct 11, 2025
Copilot AI requested a review from six7 October 11, 2025 12:43
Copilot finished work on behalf of six7 October 11, 2025 12:43
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.

2 participants