Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRequestPreSend isn't isolated #758

Closed
maxsalven opened this issue Oct 11, 2024 · 8 comments · Fixed by #764
Closed

useRequestPreSend isn't isolated #758

maxsalven opened this issue Oct 11, 2024 · 8 comments · Fixed by #764
Assignees
Labels
bug Something isn't working completed

Comments

@maxsalven
Copy link

maxsalven commented Oct 11, 2024

Version 1.8.3

import UploadButton from "@rpldy/upload-button";
import Uploady from "@rpldy/uploady";
import { useRequestPreSend } from "@rpldy/uploady";

const Hook = () => {
  useRequestPreSend((batch) => {
    if (batch.items[0]?.file.name === "a.txt") {
      return {
        options: {
          destination: {
            url: "/a",
            headers: { a: "true" },
          },
        },
      };
    } else if (batch.items[0]?.file.name === "b.txt") {
      return {
        options: {
          destination: {
            url: "/b",
            headers: { b: "true" },
          },
        },
      };
    } else {
      return false;
    }
  });
  return null;
};

const Uploader = () => {
  return (
    <Uploady multiple>
      <Hook />
      <UploadButton />
    </Uploady>
  );
};

export default Uploader;

If you upload multiple files at once, named a.txt and b.txt, then in the network call to /b you'll see it has both a and b headers:
image

I'd expect two separate file uploads to have isolated options, and not have them polluting each other.

This is a real world problem, as I need to send video uploads via tus, and all other uploads via xhr to different endpoints with different parameters (specifically, I need to override send with the regular xhr sender for non video files), but the requests end up overwriting each other and it ends up trying to use the xhr sender for the tus endpoint.

@maxsalven maxsalven changed the title Separate sender per file type useRequestPreSend isn't isolated Oct 11, 2024
Copy link
Contributor

It's been a while. Waiting for an update... 🧐

@yoavniran
Copy link
Collaborator

hey @maxsalven
was on vacation this last couple of weeks.
will look into the issues in the next few days

@yoavniran yoavniran added the bug Something isn't working label Oct 30, 2024
@yoavniran yoavniran self-assigned this Oct 30, 2024
@yoavniran
Copy link
Collaborator

This is actually a serious bug. Interesting how its never been raised before.

The issue isn't with the isolation of the useRequestPreSend calls but indeed with the destination object being polluted across batches.

Will fix soon. thanks!

@maxsalven
Copy link
Author

Fantastic, thanks @yoavniran! Do you know if there's an easy way for me to test this in my app prior to an npm release being published?

@yoavniran
Copy link
Collaborator

I'll publish an RC version to npm for you to test with.
Since next version will take a little longer with more fixes, the RC will let you test it once I publish (hopefully later today)

@yoavniran
Copy link
Collaborator

@maxsalven RC version released and can be tested.
Let me know if there's still an issue

@maxsalven
Copy link
Author

@yoavniran I've been running this in production for the last 24 hours and everything seems to be working!

Thanks so much for your efforts.

@yoavniran
Copy link
Collaborator

great to hear. thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants