Skip to content

fix(fetch): align Blob snapshot semantics#54

Merged
medz merged 2 commits into
mainfrom
fix/blob-snapshot-semantics
Jun 23, 2026
Merged

fix(fetch): align Blob snapshot semantics#54
medz merged 2 commits into
mainfrom
fix/blob-snapshot-semantics

Conversation

@medz

@medz medz commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Type

Fix

Summary

  • Snapshot byte-backed Blob parts at construction for Uint8List, ByteBuffer, ByteData, and List<int> inputs.
  • Return defensive copies from Blob.arrayBuffer(), Blob.bytes(), and streamed chunks so callers cannot mutate Blob backing.
  • Preserve Blob-part semantics for Blob subclasses by using the existing Blob backing instead of overridable read methods.

Notes

Validation

  • dart format --output=none --set-exit-if-changed .
  • dart analyze
  • dart test -p vm -p node -p chrome

Closes #53

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Blob byte snapshot semantics to ensure byte-backed parts and read buffers are copied consistently across native, Dart I/O, and JavaScript wrapper implementations.
  • Tests

    • Added comprehensive test suite validating Blob behavior including snapshot immutability, defensive copy validation for buffer operations, and stream chunk data isolation.

@medz medz added the bug Something isn't working label Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@medz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 44 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16da3468-c718-4179-a1e2-e7434acb4e63

📥 Commits

Reviewing files that changed from the base of the PR and between acaf2ee and cfd70c2.

📒 Files selected for processing (2)
  • lib/src/fetch/blob.native.dart
  • test/blob_test.dart
📝 Walkthrough

Walkthrough

Fixes Blob byte snapshot semantics across native and JS implementations. The native arrayBuffer(), bytes(), and stream() paths now return fresh Uint8List copies. _normalizePart in both native and JS files copies bytes at construction time. A new blobBacking helper exposes the internal block.Block for JS wrapper use. Tests and a changelog entry are added.

Changes

Blob Byte Snapshot Semantics Fix

Layer / File(s) Summary
Native Blob defensive copy, read paths, and blobBacking
lib/src/fetch/blob.native.dart
arrayBuffer() materializes host bytes into a new Uint8List copy; bytes() delegates to arrayBuffer(); stream() becomes an async* generator re-wrapping each chunk via Uint8List.fromList. _normalizePart ByteBuffer/ByteData branches switch from ByteData.sublistView to Uint8List.fromList. New top-level blobBacking(Blob) function exposes the internal block.Block for platform wrappers.
JS Blob part normalization with typed-data copies and blobBacking
lib/src/fetch/blob.js.dart
Adds dart:typed_data import. _normalizePart now normalizes ByteBuffer, ByteData, Uint8List, and List<int> into Uint8List (with ByteData offset/length slicing). Blob and native.Blob parts are routed through native.blobBacking(...) instead of being returned directly; the fallback is also wrapped with native.blobBacking(...).
Blob snapshot tests and changelog entry
test/blob_test.dart, CHANGELOG.md
New test suite covers construction-time byte snapshotting, defensive copies from arrayBuffer()/bytes(), non-mutability of stream() chunks, and Blob-as-part backing precedence over overridden read methods via _ReadOverridingBlob. Changelog records the fix under "Next".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • medz/ht#6: Introduced the Blob/block-backed implementation that this PR directly builds upon by hardening its _normalizePart, arrayBuffer(), bytes(), stream(), and adding the blobBacking export.

Poem

🐇 A blob once leaked its bytes to the wild,
But now every buffer is copied, compiled.
From native to JS, the snapshots hold true—
Mutate all you want, the blob stays brand new!
No override trick shall hijack my stash,
Each Uint8List copy arrives in a flash. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: aligning Blob snapshot semantics across implementations.
Linked Issues check ✅ Passed The PR fully addresses the objectives from issue #53: snapshots byte inputs during construction, returns defensive copies from arrayBuffer()/bytes(), and uses Blob backing for Blob-as-part behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing Blob snapshot semantics as specified in issue #53; no unrelated refactoring or Body extensions were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/blob-snapshot-semantics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/src/fetch/blob.native.dart`:
- Around line 54-63: The stream method uses async* syntax which defers the
chunkSize validation until the stream is subscribed to, breaking callers
expecting synchronous validation. Split the method into two parts: make the
public stream method a regular synchronous method that validates the chunkSize
parameter immediately, then create a private async* generator method (such as
_streamGenerator) that contains the yield and await for logic. Have the public
stream method perform the validation first, then return the result of calling
the private generator method to preserve eager validation while keeping the
streaming logic deferred.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c861ed6-d8ab-4252-adad-ee448762e956

📥 Commits

Reviewing files that changed from the base of the PR and between ae01032 and acaf2ee.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • lib/src/fetch/blob.js.dart
  • lib/src/fetch/blob.native.dart
  • test/blob_test.dart

Comment thread lib/src/fetch/blob.native.dart
@medz medz merged commit 0546d13 into main Jun 23, 2026
2 checks passed
@medz medz deleted the fix/blob-snapshot-semantics branch June 23, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(fetch): audit Blob snapshot semantics

1 participant