Skip to content

fix(client): avoid duplicate subset snapshot prefetch - #4778

Merged
alco merged 4 commits into
mainfrom
fix--snapshot-prefetch-duplicate-4753
Sep 1, 2026
Merged

fix(client): avoid duplicate subset snapshot prefetch#4778
alco merged 4 commits into
mainfrom
fix--snapshot-prefetch-duplicate-4753

Conversation

@alco

@alco alco commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

  • recognize subset snapshot responses via the electric-snapshot response header
  • prevent the chunk buffer from speculatively fetching one-shot subset snapshots a second time
  • require the header value to be exactly true so malformed or false marker values do not disable normal prefetching

Fixes #4753

Testing

  • pnpm --dir packages/typescript-client exec vitest run --config vitest.unit.config.ts fetch.test.ts
  • pnpm --dir packages/typescript-client exec eslint src/fetch.ts test/fetch.test.ts --quiet

alco added 3 commits August 27, 2026 11:10
Snapshot (subset) responses carry a shape handle and offset just like
normal chunks, so the prefetcher mistook them for a chunk stream and
speculatively re-issued the same subset request, downloading the
snapshot twice. Skip prefetch whenever the response is marked with the
electric-snapshot header.

Fixes #4753
@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@electric-sql/react@4778
npm i https://pkg.pr.new/@electric-sql/client@4778
npm i https://pkg.pr.new/@electric-sql/y-electric@4778

commit: 5234cd5

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1ea9cd708

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/typescript-client/src/fetch.ts
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.09%. Comparing base (dc07a1e) to head (5234cd5).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4778      +/-   ##
==========================================
+ Coverage   60.02%   60.09%   +0.07%     
==========================================
  Files         397      397              
  Lines       43772    43773       +1     
  Branches    12588    12594       +6     
==========================================
+ Hits        26272    26306      +34     
+ Misses      17418    17386      -32     
+ Partials       82       81       -1     
Flag Coverage Δ
packages/agents 72.77% <ø> (+0.12%) ⬆️
packages/agents-mcp 77.70% <ø> (ø)
packages/agents-mobile 80.67% <ø> (ø)
packages/agents-runtime 83.80% <ø> (+0.08%) ⬆️
packages/agents-server 75.67% <ø> (+0.20%) ⬆️
packages/agents-server-ui 8.32% <ø> (ø)
packages/electric-ax 51.06% <ø> (ø)
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 91.95% <100.00%> (+0.12%) ⬆️
packages/y-electric 56.05% <ø> (ø)
typescript 60.09% <100.00%> (+0.07%) ⬆️
unit-tests 60.09% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The subset-snapshot response header was set as a raw string outside of
the @electric_headers list that CORSHeaderPlug turns into
access-control-expose-headers, so browser clients on a different origin
could not read it and the client-side prefetch guard was a no-op for
them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFFVFCNmGhPm94KCwK1fg8
@alco
alco merged commit 7b9e9fe into main Sep 1, 2026
105 of 109 checks passed
@alco
alco deleted the fix--snapshot-prefetch-duplicate-4753 branch September 1, 2026 09:42
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This PR has been released! 🚀

The following packages include changes from this PR:

  • @core/sync-service@1.8.0
  • @electric-sql/client@1.5.27

Thanks for contributing to Electric!

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.

Chunk prefetcher re-downloads every subset snapshot: getNextChunkUrl doesn't exclude subset-bearing requests

1 participant