fix: apply each update an upload streams back once, with a synchronous event listener

Merged
BE
18d ago
+162-20

Fixes #7720.

uploadFiles counted a streamed chunk as processed in a .then() on what the socket's "event" listener returned. Since #6827 that listener is synchronous and returns undefined, so the .then threw after the update was applied, the chunk was never counted, and every later download progress event applied all updates received so far again.

This PR:

  • counts a chunk as processed once it parses, before it is handled, so no later progress event handles it again, whether the listener is sync or async
  • reports a listener that throws or rejects as "Error processing chunk", once, without retrying the chunk or holding up the next one
  • keeps the existing handling of an incomplete last chunk: it fails to parse, is not counted, and is parsed again with the rest of it on the next progress event

tests/units/reflex_base/client_upload.mjs loads the real upload.js and streams three updates over three progress events, the last one split across two of them. A synchronous listener handled them as 1, 1, 2, 1, 2, 3 before and 1, 2, 3 now; an async listener, like the one before #6827, handles them once with and without the fix; and a listener that throws or rejects its promise is reported once and its update not retried.