Skip to content

Conversation

@Rish-it
Copy link
Contributor

@Rish-it Rish-it commented Aug 14, 2025

Description

Fixed three critical bugs in the file upload functionality:

  1. False Success Messages

    • Upload modal was showing "Successfully uploaded" even when files failed to upload.
    • Now properly checks return values from writeFile / writeBinaryFile operations and only shows success when all uploads actually succeed.
  2. Improved Error Handling
    Added comprehensive error feedback with three scenarios:

    • All uploads successful → Shows success message and closes modal.
    • All uploads failed → Shows clear failure message.
    • Partial success → Shows detailed message indicating how many succeeded vs failed.
  3. Enhanced User Experience

    • Users now get accurate feedback about upload status, preventing confusion when uploads silently fail.

Related Issues

Fixes #2675
Closes #2675


Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Release
  • Refactor
  • Other (please describe):

Testing

  • TypeScript compilation passes (bun run typecheck)
  • All existing unit tests pass (bun test)
  • Manual testing scenarios:
    • Upload successful files → shows success message
    • Upload to invalid directory → shows failure message
    • Mixed success/failure → shows partial success message

Screenshots


Additional Notes

The fix addresses the root cause where the upload logic was only catching exceptions but not checking the boolean return values from sandbox write operations.
Files could fail to write (returning false) without throwing an error, leading to false success messages.


Important

Fixes file upload feedback in upload-modal.tsx by checking operation results and providing detailed success/failure messages.

  • Behavior:
    • Fixes false success messages in upload-modal.tsx by checking return values from writeFile and writeBinaryFile.
    • Adds detailed error feedback for all, none, or partial upload success scenarios in upload-modal.tsx.
  • Code Changes:
    • Refactors basePath calculation in code-controls.tsx to derive directory path from activeFile.
    • Passes basePath to UploadModal in code-controls.tsx.
    • Implements uploadResults array to track success of each file upload in upload-modal.tsx.
    • Updates toast messages in upload-modal.tsx to reflect accurate upload status.
  • Misc:

This description was created by Ellipsis for 92a77c3. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Uploads now default to the current folder and respect a provided base path.
    • Per-file upload tracking with clear toasts for all-success, partial-success (with counts), or all-failed outcomes.
    • Modal stays open after partial success to allow retrying failed files; header directory selector for choosing target folder.
  • Bug Fixes

    • More reliable default directory selection and clearer error messaging.
  • Refactor

    • Simplified directory resolution and upload flow wiring.

@vercel
Copy link

vercel bot commented Aug 14, 2025

@Rish-it is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Aug 14, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Derives basePath as the active file's containing directory, passes it into UploadModal, and updates UploadModal to accept basePath, choose target directory accordingly, track per-file upload results, and adjust post-upload toasts and modal behavior based on success/partial/failure.

Changes

Cohort / File(s) Summary
Upload modal enhancements
apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/upload-modal.tsx
Adds optional basePath?: string prop; uses basePath when valid for non-image uploads; replaces single-result flow with per-file upload result tracking; refines error messages; moves directory selector to header; updates upload UI and button labels.
Code controls basePath derivation
apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/code-controls.tsx
Changes basePath derivation from full active file path to its containing directory (substring before last '/'); passes basePath into UploadModal.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant CodeControls
  participant UploadModal
  participant FileSystem as FileSystemService
  participant IDE as IDE/FileList
  participant Toast as ToastService

  User->>CodeControls: Open Upload
  CodeControls->>UploadModal: basePath (dir of active file)
  User->>UploadModal: Select files, Confirm
  UploadModal->>UploadModal: Resolve targetDir (basePath or root)
  loop for each file
    UploadModal->>FileSystem: Write file (binary/text)
    FileSystem-->>UploadModal: success/failure
    UploadModal->>UploadModal: Record per-file result
  end
  alt All succeed
    UploadModal->>IDE: listAllFiles/refresh
    UploadModal->>Toast: Success (count/name)
    UploadModal-->>User: Close modal, onSuccess
  else Some succeed
    UploadModal->>IDE: listAllFiles/refresh
    UploadModal->>Toast: Partial success (counts)
    UploadModal-->>User: Keep modal open
  else All fail
    UploadModal->>Toast: Failure
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Default uploads to folder, not under active file (#2675)
Same bug exists under folder (#2675) No explicit changes to folder-creation modal or folder creation flows; unclear if that part is fixed.
Prevent false success; accurate success/failure handling (#2675)

Possibly related PRs

  • Upload fix #2677 — Modifies same CodeControls and UploadModal files; directly overlaps basePath plumbing and upload handling.
  • Feat/editor improvements #2601 — Touches UploadModal and CodeControls; related to basePath derivation and directory targeting logic.
  • fix: file upload build error #2674 — Alters UploadModal upload flow and directory resolution; overlaps in getSmartDirectory and upload result handling.

Poem

A rabbit taps on paths so neat,
From files to folders—no mis-seat.
With basePath clear and toasts that tell,
Success or fail, we signal well.
I hippity-hop through upload night,
Now every byte hops to the right. 🐇📁✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 92a77c3 and f360e25.

📒 Files selected for processing (1)
  • apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/upload-modal.tsx (5 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/upload-modal.tsx (2)

126-126: Consider await for async operation

The listAllFiles() method appears to be asynchronous based on the pattern used elsewhere in the codebase. Consider awaiting this operation to ensure the file list is refreshed before showing the success toast.

-                editorEngine.sandbox.listAllFiles();
+                await editorEngine.sandbox.listAllFiles();

The same applies to line 145:

-                editorEngine.sandbox.listAllFiles();
+                await editorEngine.sandbox.listAllFiles();

110-117: Consider adding file-specific error tracking

While the current implementation tracks success/failure per file, it doesn't capture which specific files failed. This information could be valuable for users when dealing with partial failures.

Consider tracking failed filenames to provide more detailed feedback:

            const uploadResults: boolean[] = [];
+           const failedFiles: string[] = [];
            
            for (const file of selectedFiles) {
                const directory = targetDirectory === 'root' ? '' : targetDirectory;
                const finalPath = directory ? `${directory}/${file.name}` : file.name;

                let success: boolean;
                if (isBinaryFile(file.name)) {
                    const content = await file.arrayBuffer();
                    success = await editorEngine.sandbox.writeBinaryFile(finalPath, new Uint8Array(content));
                } else {
                    const content = await file.text();
                    success = await editorEngine.sandbox.writeFile(finalPath, content);
                }
                
                uploadResults.push(success);
+               if (!success) {
+                   failedFiles.push(file.name);
+               }
            }

Then update the partial failure message:

                toast(`Partially uploaded files`, { 
-                   description: `${successCount} uploaded successfully, ${failedCount} failed. Please try again for the failed files.` 
+                   description: `${successCount} uploaded successfully, ${failedCount} failed (${failedFiles.join(', ')}). Please try again for the failed files.` 
                });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3e8dc10 and 92a77c3.

📒 Files selected for processing (2)
  • apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/code-controls.tsx (2 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/upload-modal.tsx (3 hunks)
🔇 Additional comments (5)
apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/code-controls.tsx (2)

30-36: Potential issue with root-level files

The current implementation returns an empty string for files at the root level (when lastSlash is 0 or -1), which is correct. However, the condition lastSlash > 0 means files like /file.txt (with lastSlash = 0) will return an empty string, while files like file.txt (with lastSlash = -1) will also return an empty string. This is the expected behavior, but consider adding a comment to clarify this edge case handling.


135-135: LGTM! Proper prop passing to UploadModal

The basePath prop is correctly passed to the UploadModal component, ensuring that uploaded files will be placed in the same directory as the active file rather than under the file itself.

apps/web/client/src/app/project/[id]/_components/right-panel/dev-tab/upload-modal.tsx (3)

104-120: Critical fix for upload success detection

Excellent implementation! The code now properly checks the boolean return values from writeBinaryFile and writeFile operations, which was the root cause of the false success messages. This ensures that the UI accurately reflects the actual upload status.


122-146: Well-structured error handling with clear user feedback

The three-way branching logic provides excellent user feedback:

  1. Complete success → success toast and modal closure
  2. Complete failure → clear failure message
  3. Partial success → detailed breakdown with counts

The decision to keep the modal open for partial failures is user-friendly, allowing immediate retry of failed uploads.


73-79: Smart directory resolution using basePath

The implementation correctly uses the provided basePath when it exists in availableDirectories, falling back to 'root' otherwise. This ensures files are uploaded to the same directory as the active file, fixing the issue where files were incorrectly placed under the active file.

@Kitenite Kitenite merged commit 042d3b9 into onlook-dev:main Aug 14, 2025
0 of 2 checks passed
zongkelong pushed a commit to zongkelong/ulook that referenced this pull request Aug 15, 2025
* 'main' of https://github.com/onlook-dev/onlook: (41 commits)
  feat: fix delete project (onlook-dev#2683)
  feat: reduce search latency (onlook-dev#2682)
  feat: revamp projects ux (onlook-dev#2672)
  Upload fix (onlook-dev#2677)
  feat: using firecrawl to screenshot (onlook-dev#2665)
  fix: file upload build error (onlook-dev#2674)
  feat: new project frames (onlook-dev#2673)
  feat: self hosting docs (onlook-dev#2671)
  fix: docs layout + troubleshoot section (onlook-dev#2670)
  fix(template): suppress hydration mismatch
  Feat/editor improvements (onlook-dev#2601)
  fix: make message content selectable (onlook-dev#2664)
  bugs: transient stream error (onlook-dev#2663)
  feat: update migration files (onlook-dev#2659)
  Start from Blank + Import buttons on the home page (onlook-dev#2653)
  fix: snapshot type conflict and mastra can't view image (onlook-dev#2656)
  fix: typecheck snapshot (onlook-dev#2655)
  feat: clean up mastra branch (onlook-dev#2654)
  feat: mastra no storage (onlook-dev#2650)
  feat: update ai packages (onlook-dev#2648)
  ...
@coderabbitai coderabbitai bot mentioned this pull request Sep 5, 2025
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Oct 4, 2025
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Oct 14, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] should not be able to create file under another file

2 participants