-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Changing enhancer during Render causes upload to stop #803
Comments
@raybooysen it is indeed inadvisable to re-create an enhancer at render time of the component that renders Uploady. Can you explain why you're creating your own Tus Enhancer and not using TusUploady? Is there a specific reason? If not, I strongly recommend you do that, it should also help with the issue at hand. |
In this case, the as per the example, the custom header has a value that changes during runtime. Imagine a fingerprint, a token, something like that. To accomplish this I need to be able to modify the headers, although there are other usecases like changing the URL. Since the enhancer is used within React within JSX (or TSX), the expectation would be that the internal state would be idempotent to the enhancer changing, OR that the TusSender memoises based on it's own props. |
There are built-in ways to support your use-case. The See these guides for more information: Also, from the Context, you can use the upload method that accepts UploadOptions where things like headers can be overridden, in case you want more programmatic control when adding files to be uploaded. |
Using the Removing the TusSender, then this HEAD request is not made. |
I browsed the code this morning: https://github.com/rpldy/react-uploady/tree/master/packages/core/tus-sender, allows you to set the headers as we're doing now, and in resumeUpload.js of tusSender, when it creates the HEAD request, but I could not find where those Am I missing something obvious? To be clear, the useRequestPreSend hook works for requests, but the headers for the HEAD call that tusSender fires are not modified to include my dynamic data. |
Thanks for clarifying, I didn't notice you needed the HEAD call headers. Merging happens on line 127 in the file you mentioned. |
Works a charm, thank you |
Describe the bug
The setup is simple, u ploading multiple files to a back end. In my usage, I create an
<Uploady>
component with an TusSender enhancement. As part of that sender I create it as such:In this case the TusSender is created on each render. When I select multiple files to upload, all files are uploaded to the back-end. However, the
useItemProgressListener
anduseItemFinishListener
hook callbacks are only called for the first file. No callbacks are called for the 2nd and subsequent files. This means I cannot track progress of the file uploads.I've managed to create a work-around using useMemo for the enhancer, which suggests the introduction of a new instance of the
TusSender
on each render causes some internal Uploady state to become invalid.To Reproduce
Steps to reproduce the behavior:
Expected behavior
The hooks useItemProgressListener and useItemFinishListener should report status for the subsequent files
Versions
1.9.0
Chrome
The text was updated successfully, but these errors were encountered: