Skip to content

Upload responses are re-applied on every download progress event since #6827 #7720

Closed

Description

@benedikt-bartscher

An upload handler's response is streamed back as newline-delimited updates, and uploadFiles (utils/helpers/upload.js) hands each one to the socket's "event" listener as it arrives. It only counts a chunk as processed in a .then() on what the listener returns:

event_callbacks.map((f, ix) => {
  f(chunk)
    .then(() => {
      if (ix === event_callbacks.length - 1) {
        // Mark this chunk as processed.
        resp_idx += 1;
      }
    })

Since #6827 the listener in state.js is no longer async and returns undefined, so f(chunk).then throws a TypeError right after the update was applied. The surrounding try swallows it and only logs it, as "Error parsing chunk", when the download progress is 1. resp_idx stays 0, so every later progress event of the upload applies every update received so far again: an upload that streams 3 updates over 3 progress events applies them as 1, 1, 2, 1, 2, 3.

Besides the wasted work, a re-applied update overwrites any newer value that arrived over the socket in between with its older one, until the upload's own updates replace it again.

To reproduce, stream updates from an upload handler that take a moment each:

class State(rx.State):
    step: int = 0

    @rx.event
    async def handle_upload(self, files: list[rx.UploadFile]):
        for step in range(1, 4):
            self.step = step
            yield
            await asyncio.sleep(0.5)

Each later progress event dispatches the earlier deltas again (visible with a breakpoint in the "event" listener, or with React DevTools' highlight updates).

Activity

  1. linear-code commented on Nov 2, 2026

    @linear-code
  2. added
    bug
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions