Skip to content

useBatchAddListener callback sometimes delays execution for over 2 seconds, causing remote directory to change before upload #900

@xiabingwu

Description

@xiabingwu

Describe the bug
The useBatchAddListener hook occasionally delays the execution of its callback for more than 2 seconds. This randomness causes problems in our workflow, especially when the remote upload directory changes between the time files are selected and when the callback is finally executed.

Scenario
Our application allows users to select a remote directory for uploads. Due to the unpredictable delay in the useBatchAddListener callback, the remote directory may be changed by the user before the hook executes. As a result, files can end up uploading to a directory different from the one intended at selection time.

To Reproduce
Steps to reproduce the behavior:

  1. Use the useBatchAddListener hook in a React component within a typical upload scenario.
  2. Allow users to change the remote upload directory after selecting files.
  3. Observe that sometimes the callback is executed with a delay exceeding 2 seconds, and the files are uploaded to a directory different from the one selected during file selection.

Expected behavior
The callback registered by useBatchAddListener should be executed immediately when the batch add event occurs, so the remote directory matches the user's intention at the time of selection.

Versions

  • @rpldy/uploader: [please fill in]
  • @rpldy/react-uploady: [please fill in]
  • Browser: [please fill in]

Code

useBatchAddListener((batch) => {
    // Uses current remote directory from state to determine upload target
    console.log("batch add", batch, remoteDirectory);
});
// Sometimes this log appears with a delay of more than 2 seconds,
// and remoteDirectory has changed.

Any insight into what might be causing this delay, or if it is a bug in the hook implementation, would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions