Skip to content

fix: compare DataViews by bytes instead of hanging (#150) - #159

Merged
ryan-roemer merged 1 commit into
masterfrom
fix/dataview-hang
Nov 13, 2026
Merged

ryan-roemer merged 1 commit into
masterfrom
fix/dataview-hang

Conversation

@ryan-roemer

Copy link
Copy Markdown
Member

Fixes #150.

isEqual never returned when given two DataViews. ArrayBuffer.isView() is true for a DataView, but it has no length, so the typed-array loop counted down from NaN forever. Upstream fast-deep-equal has the same bug.

  • New // START: Modifications block before the typed-array block: compares byteLength, then each byte via getUint8. ES5, guarded with typeof DataView.
  • Fixtures: a new dataViews group (equal, different bytes, different lengths, nested). Each view has a trap getter on NaN, so a regression throws instead of hanging the test run.
  • pack-snapshot.json regenerated (index.js changed). Patch changeset.

Bench: flat (within noise). No bench group for DataViews: published and fast-deep-equal still hang, so there's nothing to compare against.
Size: min+gz 653 → 702 B (+49).
Known note: a DataView from another realm (e.g. an iframe) fails instanceof and still hangs, the same instanceof check Map/Set use.

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0b7e125

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-fast-compare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ryan-roemer

Copy link
Copy Markdown
Member Author

@trackoor -- can you take a look at this fix if you have a moment?

@trackoor

Copy link
Copy Markdown

Looks good to me, thanks! The original repro now returns true right away. The node tests pass (126), and the 6 new DataView cases fail on main as expected. I also checked a few extra cases: views with a byteOffset over a larger buffer, a DataView against a Uint8Array with the same bytes (returns false), and DataViews nested in objects. All behave correctly.

@ryan-roemer
ryan-roemer merged commit af48b1e into master Nov 13, 2026
5 checks passed
@ryan-roemer
ryan-roemer deleted the fix/dataview-hang branch November 13, 2026 21:53
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026
ryan-roemer pushed a commit that referenced this pull request Nov 13, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to master, this PR
will be updated.


# Releases
## react-fast-compare@3.2.3

### Patch Changes

- [#159](#159)
[`af48b1e`](af48b1e)
- Fix `isEqual` hanging forever when comparing two `DataView`s. They're
now compared byte by byte.

- [#157](#157)
[`2b76164`](2b76164)
- Add `"sideEffects": false` to `package.json` so bundlers can drop the
module when it's imported but unused.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

isEqual never returns when comparing two DataView objects

2 participants