Skip to content

fix: Handle undefined xhr.responseText to enable upload retries#2522

Merged
monkeyiq merged 1 commit intofilesender:development3from
victoritis:fix-xhr-responsetext-crash
Jan 28, 2026
Merged

fix: Handle undefined xhr.responseText to enable upload retries#2522
monkeyiq merged 1 commit intofilesender:development3from
victoritis:fix-xhr-responsetext-crash

Conversation

@victoritis
Copy link
Copy Markdown

@victoritis victoritis commented Jan 21, 2026

Description

This PR fixes a JavaScript crash that occurs during large file uploads, particularly in Firefox when network instability (HTTP/3/QUIC resets) causes XHR responses to be empty or undefined.

The Problem

When uploading large files, FileSender uses Terasender workers to upload chunks in parallel. If a network error occurs (timeout, connection reset, HTTP/3 instability), the XHR responseText property may be undefined instead of a string.

The current code attempts to call .replace() directly on responseText:

var msg = xhr.responseText.replace(/^\s+/, '').replace(/\s+$/, '');

This causes a TypeError: Cannot read property 'replace' of undefined, which:

  • Crashes the JavaScript execution
  • Prevents the built-in retry mechanism from activating
  • Results in a blank error screen for users

Affected files:

  • www/js/client.js (line 227) - General API error handling
  • www/js/terasender/terasender_worker.js (line 508) - Chunk upload error handling

The Solution

Added defensive null-checking before accessing responseText:

var msg = (xhr.responseText || '').replace(/^\s+/, '').replace(/\s+$/, '');

This ensures:

  • If responseText exists → Works exactly as before
  • If responseText is undefined/null → Uses empty string, preventing crash
  • The existing retry mechanism can now activate properly

Impact

  • Before fix: Network errors during upload → JS crash → Upload fails permanently
  • After fix: Network errors during upload → Graceful handling → Retry mechanism activates

Files Modified

  • www/js/client.js (line 227)
  • www/js/terasender/terasender_worker.js (line 508)

Type of change

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

How Has This Been Tested?

Tested in production environment with Firefox where HTTP/3 network resets were causing upload failures on large files (500MB+). After applying the fix, uploads complete successfully with automatic retries when network hiccups occur.

@victoritis victoritis changed the title fix: ensure xhr.responseText is a string before trimming whitespace fix: Handle undefined xhr.responseText to enable upload retries Jan 21, 2026
@monkeyiq monkeyiq merged commit 5b0e816 into filesender:development3 Jan 28, 2026
5 checks passed
@madsi1m
Copy link
Copy Markdown
Contributor

madsi1m commented Feb 13, 2026

why not trim() rather than replace(\s) front and back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants