Skip to content

"Analyze Component" silently no-ops on plugin reopen — handleProviderChange clobbers apiKeySaved during startup state restore #2

Description

@GiacomoPatella

Summary

For the last few days, when reopening the plugin, the Analyze Component button looks enabled but clicking it doesn't do anything, no plugin message is sent and no analysis runs. There's a brief "Please save API key first" toast, but it's easy to miss because the "API key is configured" status banner is showing at the same time.

I think this may have been introduced in commit 1a265b4 ("Fix provider state-sync bug, support AQ. Gemini keys, refresh model lineup"). Happy to be wrong about that, just sharing what Claude found while debugging.

Repro

  1. Save an Anthropic (or any) API key, confirm analyze works.
  2. Close the plugin window.
  3. Reopen the plugin in the same or a different Figma file.
  4. Select a Component / Component Set.
  5. Click Analyze Component.

Expected: Analysis runs.
Actual: Nothing visible happens. The dev console shows no Sending message to plugin: analyze-enhanced … log, which suggests the handler is returning early at the !apiKeySaved guard.

What Claude thinks is happening

handleProviderChange() in ui-enhanced.html resets a few pieces of state (this looks intentional and correct for a user-initiated provider switch):

apiKeySaved = false;
clearApiKeyLink.classList.add('hidden');
updateAnalyzeButtonState(false);

handleApiKeyStatus() which runs on startup after the check-api-key round-trip, also calls handleProviderChange(), with a comment noting it's there to refresh labels and model visibility. From what I can trace, the sequence ends up being:

  1. handleApiKeyStatus sets apiKeySaved = hasKey (true).
  2. It calls handleProviderChange(), which resets apiKeySaved = false.
  3. It then calls updateAnalyzeButtonState(true), so the button looks enabled.
  4. On click, handleAnalyzeComponent hits if (!apiKeySaved) return; and exits without sending a message.

One small thing I noticed in the console that pointed me here: the Provider changed to: … log fires twice during plugin load, and each call clears the flag.

Possible fix

A one-line option would be to re-assert the flag after the synthetic handleProviderChange() call inside handleApiKeyStatus:

if (provider && providerSelect) {
  providerSelect.value = provider;
  handleProviderChange();
  apiKeySaved = hasKey; // re-assert; handleProviderChange resets it
}

A cleaner version might be to give handleProviderChange an isStartupRestore flag so it can skip the saved-state reset on that path, or to inline only the label / option-visibility updates that handleApiKeyStatus actually needs. Either way, you'll have a much better sense of which fits the codebase best.

Workaround for anyone hitting this

Click Clear saved API key, then re-enter and save the key. That routes through handleApiKeySaved, which sets apiKeySaved = true after any handleProviderChange() call, so the flag survives for the session.

Environment

  • FigmaLint v2.5.1
  • Figma Desktop, macOS
  • Provider: Anthropic (from a quick read of the code the same path looks like it would affect OpenAI and Google too, but I only verified Anthropic)

Thanks for the plugin, it's been really useful for auditing our library :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions