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. |
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