pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
3.7k stars 261 forks source link

onUploadProgress of useUploadThing going back to previous value #859

Closed marclelamy closed 2 weeks ago

marclelamy commented 3 weeks ago

Provide environment information

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 10.08 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.1 - /opt/homebrew/bin/node
    npm: 10.8.1 - /opt/homebrew/bin/npm
    pnpm: 9.1.4 - ~/Desktop/Code/blendcopycopy/node_modules/.bin/pnpm
  Browsers:
    Chrome: 125.0.6422.142
    Edge: 114.0.1823.58
    Safari: 17.4.1
  npmPackages:
    @uploadthing/react: ^6.6.0 => 6.6.0 
    typescript: ^5 => 5.4.5 
    uploadthing: ^6.12.0 => 6.12.0

Describe the bug

When uploading multiple files using useUploadThing() hook and displaying the progress to the user, the progress number goes back. I assume it's because the onUploadProgress callback is called whenever the status of a file changes

I'm expecting two possible things:

Link to reproduction

couldn't start the localhost due to error β¨― Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc

To reproduce

This is what I use in my app to make it happen

const [uploadStatus, setUploadStatus] = React.useState<string>("Hasn't started");
const { startUpload, isUploading } = useUploadThing(
    "multifilesUploader",
    {
        onUploadProgress: (progress: number) => {
            if (progress !== 100) {
                setUploadStatus("In progress: " + progress + "%")
            } else {
                setUploadStatus("Finilizing upload...")
            }
        },
    },
);

Additional information

CleanShot_2024-06-13_at_20 36 16

πŸ‘¨β€πŸ‘§β€πŸ‘¦ Contributing

Code of Conduct

juliusmarminge commented 3 weeks ago

Can reproduce with the following modifications to the minimal-appdir example:

// app/page.tsx
"use client";
import { useUploadThing } from "~/utils/uploadthing";

export default function Home() {
  const { startUpload } = useUploadThing("videoAndImage", {
    skipPolling: true,
    onBeforeUploadBegin: (files) => {
      console.log("Uploading", files.length, "files");
      return files;
    },
    onUploadBegin: (name) => {
      console.log("Beginning upload of", name);
    },
    onClientUploadComplete: (res) => {
      console.log("Upload Completed.", res.length, "files uploaded");
    },
    onUploadProgress(p) {
      console.log("onUploadProgress", p);
    },
  });

  return (
    <main>
      <input
        type="file"
        multiple
        onChange={async (e) => {
          const files = Array.from(e.target.files ?? []);

          // Do something with files

          // Then start the upload
          await startUpload(files);
        }}
      />
    </main>
  );
}

CleanShot 2024-06-16 at 11 18 58@2x