Skip to content

Close remaining File API spec gaps in FileReader - #57745

Open
Abbondanzo wants to merge 2 commits into
react:mainfrom
Abbondanzo:export-D113819663
Open

Close remaining File API spec gaps in FileReader#57745
Abbondanzo wants to merge 2 commits into
react:mainfrom
Abbondanzo:export-D113819663

Conversation

@Abbondanzo

Copy link
Copy Markdown
Contributor

Summary:
Builds on #57692, which fixed the abort() state machine and reset result/error at the start of each read via the _startRead() helper. A few gaps remain versus the File API spec: a read that starts while the reader is LOADING is silently superseded instead of throwing, loadstart is never dispatched, and error is a plain Error rather than a DOMException.

This change:

  • throws an InvalidStateError DOMException when a read starts while the reader is LOADING, by extending the _startRead() helper
  • fires loadstart when a read begins
  • exposes error as a DOMException (NotReadableError), matching the spec typing

No progress event is synthesized: NativeFileReaderModule resolves the whole payload in a single promise, so there is no incremental read to observe. The spec fires progress opportunistically as bytes stream in (it is not a required event), and emitting one post-completion progress with loaded === total would report data the reader never actually measured — a handler would also see reader.result === null at that point. The lifecycle is covered by loadstart/load/error/abort/loadend. The legacy readystatechange event is left untouched, and the deprecated readAsBinaryString() is out of scope.

Changelog:

[GENERAL] [FIXED] - Fire loadstart, throw InvalidStateError on overlapping reads, and expose FileReader.error as a DOMException.

Differential Revision: D113819663

…oad the correct commit data.

Differential Revision: D113802292
Summary:
Builds on [react#57692](react#57692), which fixed the `abort()` state machine and reset `result`/`error` at the start of each read via the `_startRead()` helper. A few gaps remain versus the [File API spec](https://w3c.github.io/FileAPI/): a read that starts while the reader is `LOADING` is silently superseded instead of throwing, `loadstart` is never dispatched, and `error` is a plain `Error` rather than a `DOMException`.

This change:

- throws an `InvalidStateError` `DOMException` when a read starts while the reader is `LOADING`, by extending the `_startRead()` helper
- fires `loadstart` when a read begins
- exposes `error` as a `DOMException` (`NotReadableError`), matching the spec typing

No `progress` event is synthesized: `NativeFileReaderModule` resolves the whole payload in a single promise, so there is no incremental read to observe. The spec fires `progress` opportunistically as bytes stream in (it is not a required event), and emitting one post-completion `progress` with `loaded === total` would report data the reader never actually measured — a handler would also see `reader.result === null` at that point. The lifecycle is covered by `loadstart`/`load`/`error`/`abort`/`loadend`. The legacy `readystatechange` event is left untouched, and the deprecated `readAsBinaryString()` is out of scope.

## Changelog:

[GENERAL] [FIXED] - Fire `loadstart`, throw `InvalidStateError` on overlapping reads, and expose `FileReader.error` as a `DOMException`.

Differential Revision: D113819663
@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 Jul 28, 2026
@meta-codesync

meta-codesync Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113819663.

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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant