fix: Optimize image uploads in Editor#7129
Conversation
WalkthroughThe updates include adding a new "chokidar" version resolution to the package configuration, refactoring a React component to extract inline callbacks into named hooks, fixing typos in type imports and aliases across several components, and updating a dependency array in a custom hook to include a missing callback. No changes were made to exported or public APIs beyond type alias corrections. Changes
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
package.json(1 hunks)packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx(2 hunks)packages/editor/src/core/hooks/use-file-upload.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx (3)
packages/editor/src/core/helpers/get-extension-storage.ts (1)
getExtensionStorage(5-8)packages/editor/src/core/hooks/use-file-upload.ts (1)
useUploader(20-89)packages/editor/src/core/constants/config.ts (1)
ACCEPTED_IMAGE_MIME_TYPES(11-11)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
packages/editor/src/core/hooks/use-file-upload.ts (1)
77-85: Excellent fix for preventing stale closures and multiple upload calls.Adding
onInvalidFileto the dependency array ensures theuploadFilecallback always references the current version of this function, preventing stale closures that could lead to multiple upload attempts or inconsistent error handling. This directly addresses the PR objective of fixing multiple file upload calls.packages/editor/src/core/extensions/custom-image/components/image-uploader.tsx (3)
10-11: Good organization of imports.Moving the
getExtensionStorageimport to group with other helpers improves code organization and readability.
76-86: Excellent refactoring to prevent multiple upload calls.Extracting these inline callbacks into proper
useCallbackhooks prevents unnecessary re-renders and ensures stable function references. This directly addresses the PR objective by eliminating a common cause of multiple upload calls - inline functions that create new references on every render.The dependency arrays are correctly specified:
uploadImageEditorCommanddepends oneditorandimageEntityIdhandleProgressStatusdepends oneditor
92-93: Perfect implementation of the extracted callbacks.Using the extracted
useCallbackhooks instead of inline functions ensures stable references and prevents theuseUploaderhook from unnecessarily re-executing its internal logic, which was likely causing the multiple upload calls issue.
* fix: memoize file upload functions * chore: update extension name * chore: update notation * chore: resolve chokidar package * fix: spelling mistakes
Description
This PR fixes the bug where multiple upload calls happen for an image upload.
Type of Change
Summary by CodeRabbit
Chores
Refactor