uploadthing icon indicating copy to clipboard operation
uploadthing copied to clipboard

feat: onFileUploadComplete (#1175)

Open markflorkowski opened this issue 8 months ago β€’ 5 comments

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.

markflorkowski avatar Apr 08 '25 16:04 markflorkowski

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

vercel[bot] avatar Apr 08 '25 16:04 vercel[bot]

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

Possibly related PRs

  • pingdotgg/uploadthing#1055: Introduced similar onFileUploadComplete additions, aligning with the updates in callback handling.
  • pingdotgg/uploadthing#1175: Involved adding the onFileUploadComplete property in the UploadButton component and type definitions, directly related to this update.

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.

coderabbitai[bot] avatar Apr 08 '25 16:04 coderabbitai[bot]

More templates

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

commit: 551afc4

pkg-pr-new[bot] avatar Apr 08 '25 16:04 pkg-pr-new[bot]

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[bot] avatar Apr 08 '25 16:04 github-actions[bot]

πŸ“¦ Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.66KB See Treemap πŸ“Š
PR (b547b29c570ab7187577a92e4c9b3cb460429851) 30.72KB See Treemap πŸ“Š
Diff ↑58.00B

github-actions[bot] avatar Apr 08 '25 16:04 github-actions[bot]