fix: handle the complete upload response once it loads

FA
8h ago
+11-0

Closes #7736

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable? (no JS test harness for upload.js in the repo; checked with a small script, see below)
  • Have you successfully ran tests with your changes locally?

What and why

The upload endpoint streams application/x-ndjson with no Content-Length, so event.lengthComputable is false on every xhr.onprogress and progress is always 0. In uploadFiles, the "Error parsing chunk" log is gated on progressEvent.progress === 1, so it never runs; a chunk that fails to parse is skipped silently (this is how #7720 stayed hidden).

The same gate means a chunk that was still incomplete at the last progress event is never handled again, because nothing re-runs the parser once the response is complete.

Change (packages/reflex-base/.../web/utils/helpers/upload.js): in xhr.onload, for a 2xx response, call eventHandler one last time with the full responseText and progress: 1, before resolving. resp_idx already tracks handled chunks, so nothing is applied twice; chunks not yet handled are applied, and a chunk that does not parse is now logged. Error responses (non-2xx) are not parsed, as before.

Added a reflex-base news fragment (+upload-final-chunks.bugfix.md).

Testing

Ran uploadFiles in Node with a mocked XMLHttpRequest and socket:

  • progress event with {"a":1}\n{"b": (no Content-Length), then the body completes as {"a":1}\n{"b":2}\n{bad json}\n and onload fires.
  • Before: only {"a":1} was applied and nothing was logged.
  • After: {"a":1} and {"b":2} are applied once each, and Error parsing chunk {bad json} … is logged.

Not tested end to end in a browser with reflex run. Prettier check passes on the changed file.