Skip to content

Test/progressive nested fastpath bug#1532

Draft
ibirrer wants to merge 2 commits into
TanStack:mainfrom
ibirrer:test/progressive-nested-fastpath-bug
Draft

Test/progressive nested fastpath bug#1532
ibirrer wants to merge 2 commits into
TanStack:mainfrom
ibirrer:test/progressive-nested-fastpath-bug

Conversation

@ibirrer
Copy link
Copy Markdown

@ibirrer ibirrer commented May 17, 2026

🎯 Changes

✅ Checklist

  • I have tested this code locally with pnpm test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

The e2e tests hung indefinitely in beforeAll on Node 24. The jsdom test
environment provides its own AbortController/AbortSignal, but fetch is
Node's native undici fetch. The Electric ShapeStream creates an
AbortController (jsdom) and passes its signal to fetch (undici); Node 24's
undici strictly rejects the foreign signal with a TypeError. The Electric
client's backoff wrapper treats that error as retryable and retries
forever, so preload() never resolves and beforeAll times out.

The e2e tests exercise Postgres + Electric data sync and use no DOM APIs,
so switch the environment to `node`, where AbortController and fetch are
both Node-native and compatible.

CI did not catch this because it pins Node 20, whose undici accepted the
jsdom signal via a looser duck-typed check.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e3445e7-31e4-4d34-aabe-6684ee8ca277

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

…are static

In `progressive` sync mode an Electric collection serves a fast-path snapshot
for any loadSubset that arrives before its first `up-to-date` message, then
loads the rest in the background. A collection queried directly got this fast
path; the same collection fetched as a nested `toArray` child — or joined to a
filtered parent — did not. Its rows only appeared once the entire child
collection finished syncing.

Root cause is ordering. Includes and joins lazy-load the child/joined
collection by tapping the parent pipeline and issuing the child loadSubset
only once the parent has produced rows. That deferred call resolves after the
child's full background sync has completed, so its snapshot is discarded as
stale and the query never sees the intermediate fast-path result.

Fix: when the parent query statically constrains the correlation/join field to
known keys (e.g. `.where(eq(parent.id, 5))`), push an equality predicate onto
the child so it loads its subset eagerly — in parallel with the parent —
through the normal subscription path, instead of via the deferred tap. When
the keys are not statically known the existing lazy-loading behaviour is kept.

- extractEqualityKeys() in expression-helpers.ts reads a fixed key set from a
  WHERE expression (eq / in, possibly nested in and).
- compiler/index.ts applies it to `toArray` includes children.
- compiler/joins.ts applies it to inner/left join sources (the only join
  types where filtering the joined side is sound).

Tests:
- packages/db/tests/query/progressive-includes-fastpath.test.ts
  Deterministic unit test: the nested child loadSubset now runs eagerly,
  inside the fast-path window, even while the parent collection is unsynced.
- packages/electric-db-collection/e2e/progressive-nested.e2e.test.ts
  End-to-end against a real Electric server: the direct query, the nested
  toArray query and the nested join query all surface their 40-row target
  subset after only 40/4540 rows have loaded.
@ibirrer ibirrer force-pushed the test/progressive-nested-fastpath-bug branch from 96a33e4 to 43d0237 Compare May 17, 2026 18:20
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.

1 participant