fix(admin): resolve image upload race condition and premature cleanup#291
Conversation
Fixes two critical issues preventing uploaded images from displaying: 1. Race condition in onUploadSuccess callback - Previously called handleInputChange twice sequentially - Second call used stale component.props, overwriting first update - Fixed by updating both src and _imagePath in single onPropsChange call 2. Auto-cleanup deleting newly uploaded images - cleanupUnusedImages triggered 100ms after upload via debouncedSave - Component state not yet updated with new _imagePath - Cleanup logic incorrectly identified new image as unused - Temporarily disabled auto-cleanup to prevent premature deletion Additional improvements: - Added 1.2s delay before closing upload dialog to show success state - Removed all debug console.log statements for cleaner output - Removed unused imports (createClient, useState, cleanupUnusedImages) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
@pixelsama is attempting to deploy a commit to the zhang's projects Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello @pixelsama, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where newly uploaded images were being deleted due to a race condition in the cleanup process. Previously, the cleanup ran before the database save completed, leading to incorrect identification of new images as "unused." The changes refactor the cleanup mechanism to run post-save, ensuring that only genuinely unused images are removed, thereby preventing data loss and enhancing the reliability of content management. Additionally, the user experience is improved with clearer feedback on cleanup operations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a critical race condition by ensuring image cleanup occurs after the database save operation completes. The refactoring to centralize cleanup logic, extract a helper function, and improve user feedback with toast notifications are all excellent improvements. My review focuses on further enhancing maintainability by addressing code duplication and removing dead code.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
5c459df to
3b4d859
Compare
…tructure - Add user feedback for image cleanup failures with toast warning - Refactor duplicated section collection logic into shared helper function - Remove commented-out dead code from about-editor - Restructure image-upload-dialog into modular directory structure - Replace img tag with Next.js Image component for better performance - Add i18n support for cleanup failure messages (en-US, zh-CN) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3b4d859 to
237707b
Compare
Consolidate ImageUploadDialog component by merging image-upload-dialog.tsx directly into index.tsx, removing unnecessary indirection layer. Changes: - Merge image-upload-dialog.tsx content into index.tsx - Remove redundant index.ts export file - Maintain all existing functionality and exports - No breaking changes to import paths 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Important
Fixes #<issue number>What & Why
What: Fixed race condition in image upload cleanup logic that caused newly uploaded images to be deleted prematurely.
Why: The auto-cleanup functionality was running before the save operation completed, causing it to analyze the old database state and incorrectly identify newly uploaded images as "unused", deleting them from storage before they could be properly saved.
Fixes #290
Pre-PR Checklist
Run these:
pnpm type-checkpnpm format:checkpnpm lintpnpm buildpnpm i18n:check(if applicable)Type
Changes
Bug Fix (commit 92b9c31)
about-editor.tsxtopage.tsxhandleSavefunctionRefactoring (commit 463ed3e)
cleanupUnusedImagesAfterSaveto eliminate code duplication between About and Home page handlersconsole.logwith toast notifications showing cleanup resultsmessages.cleanupImagestranslation key with plural supportTechnical Details
Root Cause
The cleanup logic in
about-editor.tsxwas being called during the save process but before the actual database update completed. This created a race condition where:Solution
Files Changed
app/admin/content/page.tsx- Main fix and refactoringcomponents/admin/content/about-editor.tsx- Removed outdated cleanup codemessages/en-US.json- Added cleanup feedback translationTesting