Skip to content

Update figma-files-raycast-extension extension - #22254

Merged
raycastbot merged 7 commits into
raycast:mainfrom
michaelwschultz:ext/figma-files-raycast-extension
Oct 30, 2025
Merged

raycastbot merged 7 commits into
raycast:mainfrom
michaelwschultz:ext/figma-files-raycast-extension

Conversation

@michaelwschultz

@michaelwschultz michaelwschultz commented Oct 17, 2025 •

Copy link
Copy Markdown
Contributor

Description

  • Updated oauth scope requested by Figma
  • Refactor of some nasty code to make the extension a bit easier to develop
  • Improved async logic thanks to a warning from Raycast 👍

Checklist

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: figma-files Issues related to the figma-files extension platform: macOS platform: Windows OP is author The OP of the PR is the author of the extension labels Oct 17, 2025
@raycastbot

raycastbot commented Oct 17, 2025 •

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! 🎉

🔔 @michaelwschultz @GLaDO8 you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

You can expect an initial review within five business days.

@michaelwschultz
michaelwschultz marked this pull request as ready for review October 19, 2025 09:35
@michaelwschultz

Copy link
Copy Markdown
Contributor Author

I'm not sure why the CI is failing here. But the changes work just fine.

@greptile-apps greptile-apps Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR modernizes the Figma extension with critical OAuth scope updates and substantial code improvements. The OAuth scopes have been updated from the deprecated files:read to granular permissions (file_content:read, file_metadata:read, file_versions:read, projects:read) as required by Figma's platform updates.

Key Improvements

  • Smart Caching System: Implements project-level TTL caching (30 min) that only refreshes stale projects, significantly reducing API calls
  • Rate Limiting & Retry Logic: Adds exponential backoff for 429 errors with configurable retry attempts
  • Code Consolidation: Created useFigmaData hook eliminating duplication between index.tsx and menu-bar.tsx (reduced menu-bar from 44 to 13 lines)
  • Better Organization: Extracted utilities for filters and file storage, improving maintainability
  • Dependency Updates: Removed node-fetch (now built-in in Node 21+), updated @raycast/api and @raycast/utils to latest versions

Issues Found

  • Minor off-by-one error in rate limit retry counter (allows 3 retries instead of 2)

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after addressing the retry counter issue.
  • Score of 4 reflects a well-executed refactoring with comprehensive improvements. The OAuth scope update is critical and correctly implemented. The caching system is thoughtfully designed. The single logical issue found (off-by-one in retry counter) is minor and easy to fix - it just means one extra retry attempt rather than causing failures. Code quality is excellent with proper error handling, type safety, and good separation of concerns.
  • extensions/figma-files/src/api.ts - fix the retry counter logic on line 35

Important Files Changed

File Analysis

Filename Score Overview
extensions/figma-files/src/api.ts 4/5 Major refactor: added rate limiting, retry logic, caching with TTL, and removed node-fetch dependency. Contains minor off-by-one issue in retry counter.
extensions/figma-files/src/oauth.ts 5/5 Updated OAuth scopes from generic files:read to granular permissions as required by Figma's updated API requirements.
extensions/figma-files/src/cache.tsx 5/5 New file implementing project-level TTL caching system (30 min) with functions for managing cache invalidation and file storage.
extensions/figma-files/src/hooks/useFigmaData.ts 5/5 New custom hook that consolidates data fetching logic for allFiles, starredFiles, and visitedFiles, improving code reusability.
extensions/figma-files/src/index.tsx 5/5 Refactored to use useFigmaData hook, extracted filter logic to utilities, removed duplicate desktop app detection code.
extensions/figma-files/package.json 5/5 Updated dependencies to latest versions, removed node-fetch (now built-in), added keywords, deprecated personal access token preference.

Additional Comments (1)

  1. extensions/figma-files/src/api.ts, line 34-44 (link)

    logic: Rate limit retry logic allows 3 attempts instead of 2.

    The check attempts++ >= maxRetries increments AFTER comparing, so with maxRetries = 2, the code actually retries when attempts is 0, 1, and 2 (3 total attempts instead of 2). To fix:

20 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@raycastbot raycastbot added the OP is contributor The OP of the PR is a contributor of the extension label Oct 21, 2025
@pernielsentikaer

Copy link
Copy Markdown
Contributor

Hi @michaelwschultz

Can you please make sure I didn't break or make something wrong? I fixed the CI error :)

@michaelwschultz

Copy link
Copy Markdown
Contributor Author

@pernielsentikaer thanks so much! I'll take a look in a bit and get back to ya.

@pernielsentikaer
pernielsentikaer marked this pull request as draft October 23, 2025 06:42
@michaelwschultz
michaelwschultz marked this pull request as ready for review October 29, 2025 00:05
@michaelwschultz

Copy link
Copy Markdown
Contributor Author

@pernielsentikaer looks good to me. Thanks so much.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Updates the Figma extension to comply with Figma's new OAuth scope requirements and significantly refactors the API layer. The changes include:

  • Updated OAuth scope from generic files:read to granular scopes (file_content:read, file_metadata:read, file_versions:read, projects:read)
  • Refactored the request function to use native fetch instead of node-fetch dependency
  • Added retry logic with exponential backoff for rate limiting (429 errors)
  • Implemented project-level caching with TTL to reduce API calls
  • Added better error handling for authentication and HTTP errors
  • Deprecated personal access token in favor of OAuth
  • Updated dependencies to latest versions

Issues Found

  • Critical: Off-by-one error in retry counter logic (api.ts:35) - with maxRetries = 2, only 1 retry occurs instead of 2

Confidence Score: 4/5

  • This PR is safe to merge after fixing the retry logic bug
  • The refactoring improves code quality and adds important features like caching and retry logic. However, there's a critical off-by-one error in the retry counter that needs to be fixed. The OAuth scope update is necessary and correct. Once the retry logic is corrected, this will be a solid improvement
  • Pay attention to extensions/figma-files/src/api.ts - fix the retry counter before merging

Important Files Changed

File Analysis

Filename Score Overview
extensions/figma-files/src/api.ts 3/5 Refactored request function with rate limiting, retry logic, and caching; contains off-by-one error in retry counter
extensions/figma-files/package.json 5/5 Updated dependencies, deprecated personal access token, added keywords, and updated build scripts
extensions/figma-files/src/oauth.ts 5/5 Updated OAuth scope from generic files:read to granular scopes as per Figma's new requirements

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread extensions/figma-files/src/api.ts Resolved
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@pernielsentikaer

Copy link
Copy Markdown
Contributor

@greptileai can you do a fresh review?

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this PR, I can see several good improvements to the Figma Files extension. Let me provide a comprehensive review:

🎯 Overall Assessment

This is a solid refactoring that addresses Figma's OAuth scope requirements and improves the codebase architecture. The changes show good engineering practices with better separation of concerns and more maintainable code structure.

✅ Strengths

  1. OAuth Compliance: Updated scopes to match Figma's new requirements - critical for continued functionality
  2. Better Architecture: Nice refactoring with custom hooks (useFigmaData, useFileCollection) that centralize logic
  3. Improved Caching: More sophisticated TTL-based caching system with project-level granularity
  4. Error Handling: Enhanced error handling with retry logic for rate limiting
  5. Code Organization: Better file structure with utility modules (filterUtils.ts, fileStorage.ts)

🔧 Technical Improvements

The new caching system is well-designed:

  • Project-level TTL tracking
  • Smart refresh logic that only fetches expired data
  • Fallback to cached data when API calls fail

The hook refactoring makes components cleaner and more testable.

🐛 Issues Found

1. Potential Breaking Change in API

// Line 55 & 97 in api.ts
const result = await request<ProjectFiles>(`/projects/${project.id}/files?branch_data=false`

Setting branch_data=false when it was previously true could break functionality for users who rely on branch information.

2. Typo in Help Documentation

// HELP.md line 9
> Unfortunitly <b>drafts</b> are not available

Should be "Unfortunately" and the <b> tags should be markdown **drafts**.

3. Version Mismatch in Changelog

The changelog shows version 2025-09-23 but we're still in 2024. The package.json version 1.6.2 seems more appropriate.

💡 Suggestions

  1. Consider keeping branch data: Unless there's a specific reason to disable it, branch information might be valuable to users

  2. Add migration notice: Since you're deprecating personal access tokens, consider adding a toast notification to guide existing users

  3. Error message clarity: The new auth error message is good, but you might want to include a link to re-authenticate

📋 Minor Nits

  • The eslint config change from array to object format is fine but not necessary for functionality
  • Some dependency updates are quite large jumps (especially ESLint 8→9) - make sure all functionality still works

🚀 Verdict

This is a well-executed refactoring that maintains functionality while improving code quality. The OAuth scope update is essential, and the architectural improvements set the extension up for easier maintenance going forward.

Recommendation: Approve with minor fixes for the typo and consideration of the branch data change.

Great work on modernizing this extension! 🎉

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors and modernizes the Figma Files extension with several improvements:

  • Refactors code organization by extracting utility functions into separate modules (filterUtils, fileStorage)
  • Updates OAuth scopes to be more granular for better Figma API permissions
  • Consolidates data fetching logic into a shared useFigmaData hook
  • Adds project-level TTL caching to improve performance
  • Updates dependencies to latest versions (@raycast/api, @raycast/utils, TypeScript, ESLint)
  • Removes node-fetch dependency in favor of native fetch API
  • Adds HELP.md file for better user documentation
  • Improves action label clarity (renames "Clear All Cache" to "Reload Files")

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Updates dependencies and adds keywords
package-lock.json Updates lock file for new dependencies
eslint.config.js Adds flat ESLint config file
oauth.ts Updates OAuth scopes to be more granular
api.ts Adds rate limiting, TTL caching, and better error handling
cache.tsx Implements project-level TTL caching system
lib/filterUtils.ts New utility module for filter operations
lib/fileStorage.ts New utility module for file storage operations
hooks/useFigmaData.ts New shared hook consolidating data fetching
hooks/useFileCollection.ts New generic hook for file collection management
hooks/useStarredFiles.ts New hook for starred files functionality
hooks/useDesktopApp.ts New hook for desktop app detection
hooks/useVisitedFiles.ts Refactored to use useFileCollection
index.tsx Refactored to use new hooks and utilities
menu-bar.tsx Refactored to use new hooks
components/*.tsx Updated imports to use new lib structure
CHANGELOG.md Added new entry but missing {PR_MERGE_DATE} template
HELP.md New help documentation file
.eslintrc.json Minor formatting update

Comment thread extensions/figma-files/CHANGELOG.md Outdated
@@ -1,5 +1,11 @@
# Figma Files Changelog

## [Adds cache clearing action] - 2025-09-23

Copilot AI Oct 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG.md entry must end with the template string {PR_MERGE_DATE} instead of a specific date. Replace 2025-09-23 with {PR_MERGE_DATE}. The correct format should be: ## [Adds cache clearing action] - {PR_MERGE_DATE}

Copilot generated this review using guidance from repository custom instructions.
Comment thread extensions/figma-files/HELP.md Resolved
Comment on lines +1 to +6
const { defineConfig } = require("eslint/config");
const raycastConfig = require("@raycast/eslint-config");

module.exports = defineConfig([
...raycastConfig,
]);

Copilot AI Oct 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defineConfig import from eslint/config is incorrect. ESLint flat config doesn't export this function. Remove this line and the defineConfig wrapper, and export the config array directly: module.exports = [...raycastConfig];

Suggested change
const { defineConfig } = require("eslint/config");
const raycastConfig = require("@raycast/eslint-config");
module.exports = defineConfig([
...raycastConfig,
]);
const raycastConfig = require("@raycast/eslint-config");
module.exports = [...raycastConfig];

Copilot uses AI. Check for mistakes.
Per Nielsen Tikær and others added 2 commits October 30, 2025 06:54
Updated the date placeholder for the cache clearing action entry.

@pernielsentikaer pernielsentikaer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, approved 🔥

@raycastbot
raycastbot merged commit ea7ccaf into raycast:main Oct 30, 2025
@github-actions

Copy link
Copy Markdown
Contributor

@raycastbot

Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

tktcorporation added a commit to tktcorporation/extensions that referenced this pull request