fix(client): report upload chunk parse errors on completion (fixes #7736)
Merged
TH
3d ago+92+92+01234567890123456789-16-16-01234567890123456789
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?
- Have you successfully ran tests with your changes locally?
Description of Changes
Problem:
During file uploads, streamed responses lack a Content-Length header (Transfer-Encoding: chunked), meaning event.lengthComputable is false and progress === 1 is never evaluated as true. As a result, malformed chunks that failed parsing were silently ignored and never logged. In addition, xhr.onload resolved the upload promise without a final pass over the complete response.
Fix:
eventHandler(responseText, complete = false)inpackages/reflex-frontend/src/utils/helpers/upload.jsreplaces the progress-ratio check with a completion flag.xhr.onprogressno longer computes a progress ratio.xhr.onloadcallseventHandler(xhr.responseText, true)for a 2xx response, before the error-frame check from #7808. So an error frame that only the final pass sees still fails the upload.- A chunk that does not parse is logged once, when the response is complete. This is also true when the response has a
Content-Lengthheader. - An empty response is skipped, so it logs nothing.
- Tests in
tests/units/reflex_base/client_upload.mjs: a bad chunk is logged at load, a final chunk is completed after the last progress event, a response has no progress events, a progress ratio of 1 is not completion, an error frame is seen only at load, and an empty response. The existing error-status test covers the non-2xx case. - Newsfragment:
packages/reflex-base/news/+upload-completion-errors.bugfix.md.