Repository navigation
Update figma-files-raycast-extension extension - #22254
Conversation
|
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. |
|
I'm not sure why the CI is failing here. But the changes work just fine. |
There was a problem hiding this comment.
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
useFigmaDatahook 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/apiand@raycast/utilsto 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)
-
extensions/figma-files/src/api.ts, line 34-44 (link)logic: Rate limit retry logic allows 3 attempts instead of 2.
The check
attempts++ >= maxRetriesincrements AFTER comparing, so withmaxRetries = 2, the code actually retries whenattemptsis 0, 1, and 2 (3 total attempts instead of 2). To fix:
20 files reviewed, 1 comment
|
Can you please make sure I didn't break or make something wrong? I fixed the CI error :) |
|
@pernielsentikaer thanks so much! I'll take a look in a bit and get back to ya. |
|
@pernielsentikaer looks good to me. Thanks so much. |
There was a problem hiding this comment.
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:readto granular scopes (file_content:read,file_metadata:read,file_versions:read,projects:read) - Refactored the
requestfunction to use nativefetchinstead ofnode-fetchdependency - 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) - withmaxRetries = 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
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@greptileai can you do a fresh review? |
There was a problem hiding this comment.
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
- OAuth Compliance: Updated scopes to match Figma's new requirements - critical for continued functionality
- Better Architecture: Nice refactoring with custom hooks (
useFigmaData,useFileCollection) that centralize logic - Improved Caching: More sophisticated TTL-based caching system with project-level granularity
- Error Handling: Enhanced error handling with retry logic for rate limiting
- 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 availableShould 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
-
Consider keeping branch data: Unless there's a specific reason to disable it, branch information might be valuable to users
-
Add migration notice: Since you're deprecating personal access tokens, consider adding a toast notification to guide existing users
-
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! 🎉
There was a problem hiding this comment.
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
useFigmaDatahook - Adds project-level TTL caching to improve performance
- Updates dependencies to latest versions (@raycast/api, @raycast/utils, TypeScript, ESLint)
- Removes
node-fetchdependency 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 |
| @@ -1,5 +1,11 @@ | |||
| # Figma Files Changelog | |||
|
|
|||
| ## [Adds cache clearing action] - 2025-09-23 | |||
There was a problem hiding this comment.
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}
| const { defineConfig } = require("eslint/config"); | ||
| const raycastConfig = require("@raycast/eslint-config"); | ||
|
|
||
| module.exports = defineConfig([ | ||
| ...raycastConfig, | ||
| ]); |
There was a problem hiding this comment.
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];
| const { defineConfig } = require("eslint/config"); | |
| const raycastConfig = require("@raycast/eslint-config"); | |
| module.exports = defineConfig([ | |
| ...raycastConfig, | |
| ]); | |
| const raycastConfig = require("@raycast/eslint-config"); | |
| module.exports = [...raycastConfig]; |
Co-authored-by: Copilot <[email protected]>
Updated the date placeholder for the cache clearing action entry.
pernielsentikaer
left a comment
There was a problem hiding this comment.
Looks good to me, approved 🔥
|
🎉 🎉 🎉 We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag. |
Description
Checklist
npm run buildand tested this distribution build in Raycastassetsfolder are used by the extension itselfREADMEare placed outside of themetadatafolder