Set FileReader to LOADING state while a read is in progress - #57375
Closed
durvesh1992 wants to merge 1 commit into
Closed
Set FileReader to LOADING state while a read is in progress#57375durvesh1992 wants to merge 1 commit into
durvesh1992 wants to merge 1 commit into
Conversation
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.
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D110191434. |
|
@Abbondanzo merged this pull request in c00813c. |
meta-codesync Bot
pushed a commit
that referenced
this pull request
Jul 28, 2026
Summary: Before #57375, reads never entered `LOADING`, so the active abort path was effectively unreachable. Now that reads use `LOADING`, that path calls `_reset()` before and after transitioning to `DONE`, leaving the reader in `EMPTY` after `abort()` returns. This differs from the [File API abort algorithm](https://w3c.github.io/FileAPI/#dfn-abort), which keeps an active reader in `DONE`. The final reset also overwrites a replacement read started by an `abort` handler, and that new read clears the shared `_aborted` flag before the canceled native promise settles. This change: - keeps an aborted active reader in `DONE` with a null result - skips the old `loadend` if the abort handler starts another read - gives each read an ID so a canceled native promise cannot complete over a newer read ## Changelog: [GENERAL] [FIXED] - Keep `FileReader` in the correct state after aborting a read. Pull Request resolved: #57692 Test Plan: - `yarn jest packages/react-native/Libraries/Blob/__tests__/FileReader-test.js --runInBand` - `./node_modules/.bin/prettier --check packages/react-native/Libraries/Blob/FileReader.js packages/react-native/Libraries/Blob/__tests__/FileReader-test.js` - `./node_modules/.bin/eslint --max-warnings 0 packages/react-native/Libraries/Blob/FileReader.js packages/react-native/Libraries/Blob/__tests__/FileReader-test.js` - `yarn flow-check` Reviewed By: christophpurrer Differential Revision: D113802292 Pulled By: Abbondanzo fbshipit-source-id: d5c8beeaf2539f3784e7f61ba500e67da575164c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FileReader'sreadAsText/readAsDataURL/readAsArrayBuffergo straight fromEMPTYtoDONE— they never setreadyStatetoLOADING. Two consequences:readyStateis never observablyLOADINGduring a read (it should be, per the W3C FileReader spec).abort()is dead during a read. Its body only emits events when the reader is mid-read:Because a read never sets
LOADING,readyStateis stillEMPTYwhenabort()runs, so the guard is false and noabort/loadendevents are dispatched — even though the method is written specifically to handle that case.Fix
Set the
LOADINGstate when each read starts (via the existing_setReadyStatehelper, which also firesreadystatechange). This makesreadyStatecorrect during a read and makesabort()during a read dispatchabort/loadendas its own code already anticipates.Test plan
Added tests to
Libraries/Blob/__tests__/FileReader-test.js:readyStateisLOADINGsynchronously after a read starts.abort()during a read dispatchesabortandloadend.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
FileReaderreadyStatetoLOADINGduring a read soabort()correctly emitsabort/loadend