Skip to content

Set FileReader to LOADING state while a read is in progress#57375

Closed
durvesh1992 wants to merge 1 commit into
react:mainfrom
durvesh1992:fix-filereader-loading-abort
Closed

Set FileReader to LOADING state while a read is in progress#57375
durvesh1992 wants to merge 1 commit into
react:mainfrom
durvesh1992:fix-filereader-loading-abort

Conversation

@durvesh1992

Copy link
Copy Markdown
Contributor

Summary

FileReader's readAsText / readAsDataURL / readAsArrayBuffer go straight from EMPTY to DONE — they never set readyState to LOADING. Two consequences:

  1. readyState is never observably LOADING during a read (it should be, per the W3C FileReader spec).

  2. abort() is dead during a read. Its body only emits events when the reader is mid-read:

    abort() {
      this._aborted = true;
      // only call onreadystatechange if there is something to abort, as per spec
      if (this._readyState !== EMPTY && this._readyState !== DONE) {
        this._reset();
        this._setReadyState(DONE);
      }
      this._reset();
    }

    Because a read never sets LOADING, readyState is still EMPTY when abort() runs, so the guard is false and no abort/loadend events are dispatched — even though the method is written specifically to handle that case.

Fix

Set the LOADING state when each read starts (via the existing _setReadyState helper, which also fires readystatechange). This makes readyState correct during a read and makes abort() during a read dispatch abort/loadend as its own code already anticipates.

Test plan

Added tests to Libraries/Blob/__tests__/FileReader-test.js:

  • readyState is LOADING synchronously after a read starts.
  • abort() during a read dispatches abort and loadend.

Both fail before this change and pass after; the existing read tests and the full Blob test suite still pass (20/20). ESLint clean on the changed files.

Changelog:

[General] [Fixed] - Set FileReader readyState to LOADING during a read so abort() correctly emits abort/loadend

FileReader's readAs* methods went straight from EMPTY to DONE: they
never set readyState to LOADING. As a result readyState was never
observably LOADING, and abort() — which only emits events when
readyState is neither EMPTY nor DONE — silently did nothing when called
during an in-progress read, so no 'abort'/'loadend' events fired.

Set the LOADING state when each read starts (via _setReadyState, which
also fires 'readystatechange'), matching the FileReader spec and making
abort() during a read work as its own code already anticipated.

Add tests for the LOADING state and for abort() dispatching abort/loadend
during a read.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 30, 2026
@meta-codesync

meta-codesync Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D110191434.

@meta-codesync meta-codesync Bot closed this in c00813c Jun 30, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jun 30, 2026
@meta-codesync

meta-codesync Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Abbondanzo merged this pull request in c00813c.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant