Skip to content

Conversation

markflorkowski
Copy link
Collaborator

@markflorkowski markflorkowski commented Apr 8, 2025

from #1175 -- Created for Canary (since that action fails on forks)

Summary by CodeRabbit

  • New Features
    • Enhanced the file upload experience by introducing a configurable callback that triggers custom actions once an upload completes.
    • Improved the handling of both individual and multiple file uploads, offering greater flexibility and control over post-upload events.

Copy link

vercel bot commented Apr 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2025 4:49pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Apr 8, 2025 4:49pm

Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

Walkthrough

This pull request introduces an onFileUploadComplete callback into the file upload workflow. The changes add the callback property to multiple components and types across the React and upload modules. The UploadButton component, related hooks, and type definitions have been altered to include and pass this callback, while the underlying upload methods in the browser upload module have been adjusted to invoke the callback upon upload completion.

Changes

Files Change Summary
packages/react/src/components/button.tsx
packages/react/src/types.ts
packages/react/src/use-uploadthing.ts
Updated the UploadButton component and related types/hooks by removing outdated type imports and adding new ones from @uploadthing/shared. Introduced the onFileUploadComplete property into the configuration objects and hook parameters to handle upload completion.
packages/uploadthing/src/_internal/upload-browser.ts
packages/uploadthing/src/types.ts
Modified method signatures for both single and multiple file uploads to include an onFileUploadComplete callback. The upload functions now invoke this callback with the appropriate upload data upon completion.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UploadButton
    participant UploadHook as useUploadThingInternal
    participant UploadModule as upload-browser.ts

    User->>UploadButton: Initiates file upload
    UploadButton->>UploadHook: startUpload(config with onFileUploadComplete)
    UploadHook->>UploadModule: uploadFiles(opts with onFileUploadComplete)
    UploadModule->>UploadModule: Process file upload
    UploadModule->>UploadModule: Invoke onFileUploadComplete callback
    UploadModule-->>UploadHook: Return upload result
    UploadHook-->>UploadButton: Complete upload flow with callback execution
Loading

Possibly related PRs

Suggested labels

release canary, @uploadthing/react

Suggested reviewers

  • juliusmarminge

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 3 workspace projects
Progress: resolved 0, reused 0, downloaded 1, added 0
Progress: resolved 17, reused 0, downloaded 17, added 0
Progress: resolved 18, reused 0, downloaded 18, added 0
/tmp/eslint/packages/uploadthing:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/uploadthing: "@uploadthing/mime-types@workspace:*" is in the dependencies but no package named "@uploadthing/mime-types" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/uploadthing

Packages found in the workspace:

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

pkg-pr-new bot commented Apr 8, 2025

More templates

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/react@1177
npm i https://pkg.pr.new/pingdotgg/uploadthing@1177

commit: 551afc4

Copy link
Contributor

github-actions bot commented Apr 8, 2025

A new canary is available for testing. You can install this latest build in your project with:

pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add @uploadthing/[email protected]
pnpm add [email protected]
pnpm add @uploadthing/[email protected]

@github-actions github-actions bot removed the release canary Trigger a canary release to npm label Apr 8, 2025
Copy link
Contributor

github-actions bot commented Apr 8, 2025

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.66KB See Treemap 📊
PR (b547b29) 30.72KB See Treemap 📊
Diff ↑58.00B

Copy link
Contributor

@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 (1)
packages/uploadthing/src/_internal/upload-browser.ts (1)

111-112: LGTM! Consider adding JSDoc for the new callback.

The addition of the onFileUploadComplete callback and the simplified type definition for onUploadProgress are well-implemented. For improved developer experience, consider adding a JSDoc comment that describes the purpose and timing of the new callback.

 opts: {
+  /**
+   * Callback that is triggered when a file upload completes successfully
+   * @param data The uploaded file data including server response
+   */
   onFileUploadComplete?: (_: ClientUploadedFileData<TServerOutput>) => void;
   onUploadProgress?: (_: { loaded: number; delta: number }) => void;
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cff049c and 551afc4.

📒 Files selected for processing (5)
  • packages/react/src/components/button.tsx (2 hunks)
  • packages/react/src/types.ts (1 hunks)
  • packages/react/src/use-uploadthing.ts (1 hunks)
  • packages/uploadthing/src/_internal/upload-browser.ts (3 hunks)
  • packages/uploadthing/src/types.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/uploadthing/src/types.ts (1)
packages/uploadthing/src/_internal/shared-schemas.ts (1)
  • ClientUploadedFileData (96-101)
packages/react/src/types.ts (1)
packages/uploadthing/src/types.ts (1)
  • ClientUploadedFileData (25-25)
packages/uploadthing/src/_internal/upload-browser.ts (2)
packages/uploadthing/src/types.ts (1)
  • ClientUploadedFileData (25-25)
packages/uploadthing/src/_internal/shared-schemas.ts (1)
  • ClientUploadedFileData (96-101)
🔇 Additional comments (8)
packages/react/src/types.ts (1)

56-74: Well-structured callback addition for handling individual file upload completion.

The new onFileUploadComplete callback is properly typed and documented, providing developers with a way to respond to individual file upload completions. This is a useful addition that complements the existing onClientUploadComplete callback which only fires after all files are uploaded.

packages/react/src/use-uploadthing.ts (1)

94-94: Good integration of the new callback into the upload flow.

Correctly passes the onFileUploadComplete callback from the props to the uploadFiles function, ensuring the callback is properly integrated into the upload process.

packages/uploadthing/src/types.ts (2)

12-12: Appropriate import addition.

Added import for ClientUploadedFileData which is needed for the new callback signature.


129-146: Well-structured callback definition matching React implementation.

The onFileUploadComplete callback is properly defined in the UploadFilesOptions type with clear documentation. The structure mirrors the one in UseUploadthingProps, maintaining consistency across the codebase.

packages/react/src/components/button.tsx (2)

6-10: Enhanced type imports for better clarity.

Explicit imports of the necessary types from "@uploadthing/shared" improve code clarity and maintainability.


119-119: Proper integration of callback in UploadButton component.

The onFileUploadComplete property is correctly passed from component props to the internal upload logic, ensuring the callback works as expected when using the UploadButton component.

packages/uploadthing/src/_internal/upload-browser.ts (2)

157-157: Good implementation of the callback invocation.

The Micro.tap operator correctly invokes the callback with the file data after the upload is complete. The optional chaining ensures safety when the callback isn't provided.


206-212:

❓ Verification inconclusive

Well-structured callback with comprehensive context data.

The implementation provides rich context to the consumer by including not just the uploaded file data but also the original file and the complete files array. This gives developers flexibility in how they handle upload completions, especially in multi-file scenarios.

Consider adding tests to verify this callback is invoked correctly with the expected data structure.


🏁 Script executed:

#!/bin/bash
# Check if tests exist for the new onFileUploadComplete functionality

# Look for test files that might test this functionality
echo "Searching for relevant test files..."
rg -l "onFileUploadComplete" --type ts --type tsx

Length of output: 160


Review Focus: Enhance Test Verification for onFileUploadComplete Callback

The callback implementation is solid and provides comprehensive context. However, our initial search for tests referencing this functionality was inconclusive due to a file type configuration issue (the tsx type wasn’t recognized by the search command). Please ensure that tests are added (or, if they already exist, verify their effectiveness) to confirm that the onFileUploadComplete callback is invoked correctly with the expected data structure (i.e., it correctly passes fileData, file, and files).

  • Update the testing configuration or search parameters (e.g., by adding a tsx file type) to confirm test coverage, or manually verify that relevant tests exist.
  • If tests are not already present, consider adding them to cover multi-file and edge-case scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants