Initial subset rejection loops in useLiveSuspenseQuery instead of reaching ErrorBoundary
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 57/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
- 領域
- backend
調査の方向性
Start with packages/react-db/src/useLiveSuspenseQuery.ts, especially SuspenseBinding.resolve and the zero-delay retry-entry release described in the issue. Reproduce with the supplied Vite fixture and ?fail, then trace how the failed resource is retained through React’s retry and collection cleanup. Done when one failed load reaches the surrounding ErrorBoundary without repeated loader calls, while cleanup and recovery behavior remain correct.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
A rejected initial loadSubset under useLiveSuspenseQuery + DbProvider can repeatedly recreate the query and call the failing loader instead of reaching the surrounding ErrorBoundary.
This reproduction only returns Promise.reject(error). It does not call sync.fail, configure retries, use short gcTime, or perform a refetch. It therefore also affects query-local first-load errors.
Expected / actual
- Expected: one failed initial acquisition, followed by the ErrorBoundary receiving
Subset denied. - Actual: the fallback stays visible and loads repeat. The included isolated browser run made 5,864 loader calls in about one second, with no boundary output. Exact counts vary with machine speed.
- Retaining the failed Suspense resource until normal collection cleanup gives one loader call and the expected ErrorBoundary.
Reproduction
Use a Vite React/TypeScript app with @tanstack/[email protected], @tanstack/[email protected], [email protected], and [email protected]. Replace src/main.tsx with the code below. The HTML should contain <div id="root"></div>.
No router, external service, persistence adapter, fragments, React Compiler, or application-specific code is required. The two URL modes share a fixture so they can also act as controls.
Complete main.tsx
import { collectionOptions, DbClient, eq } from '@tanstack/db';
import { DbProvider, useLiveSuspenseQuery } from '@tanstack/react-db';
import { Component, Suspense, useLayoutEffect, useState, type ReactNode } from 'react';
import { createRoot } from 'react-dom/client';
// Run ?fail for the rejection case; omit it for synchronous cached queries.
const fail = new URLSearchParams(location.search).has('fail');
const metrics = { loads: 0, fallbacks: 0, rendered: 0, start: 0, elapsed: 0 };
const items = collectionOptions({
id: 'items',
getKey: (row: { id: string; title: string }) => row.id,
syncMode: 'on-demand',
sync: {
sync: ({ begin, write, commit, markReady }) => {
begin();
for (let i = 0; i < 20; i++) {
write({ type: 'insert', value: { id: String(i), title: `Item ${i}` } });
}
void commit();
markReady();
return {
loadSubset: () => {
metrics.loads++;
return fail ? Promise.reject(new Error('Subset denied')) : true;
},
};
},
},
});
const client = new DbClient();
const source = client.collection(items);
await source.preload();
function Detail({ id }: { id: string }) {
metrics.rendered++;
const { data } = useLiveSuspenseQuery(q =>
q.from({ item: source })
.where(({ item }) => eq(item.id, id))
.select(({ item }) => ({ title: item.title }))
.findOne(),
);
useLayoutEffect(() => {
metrics.elapsed = performance.now() - metrics.start;
console.log('committed', { ...metrics });
}, [id]);
return <output data-testid="result">{data?.title}</output>;
}
function Pending() {
useLayoutEffect(() => { metrics.fallbacks++; }, []);
return <p data-testid="pending">Pending</p>;
}
class Boundary extends Component<{ children: ReactNode }, { error?: string }> {
state: { error?: string } = {};
static getDerivedStateFromError(error: Error) { return { error: error.message }; }
render() {
return this.state.error
? <p data-testid="error">{this.state.error}</p>
: this.props.children;
}
}
function ReadyExample() {
// A mounted inventory query already holds the source rows.
useLiveSuspenseQuery(q => q.from({ item: source }).select(({ item }) => ({ id: item.id })));
const [id, setId] = useState<number>();
return <>
<button onClick={() => {
metrics.start = performance.now();
setId(previous => (previous ?? -1) + 1);
}}>Select cached row</button>
{id !== undefined && <Suspense key={id} fallback={<Pending />}>
<Detail id={String(id)} />
</Suspense>}
</>;
}
const root = createRoot(document.getElementById('root')!);
root.render(<DbProvider client={client}>
<Boundary>
<Suspense fallback={<Pending />}>
{fail ? <Detail id="0" /> : <ReadyExample />}
</Suspense>
</Boundary>
</DbProvider>);
Reflect.set(window, 'repro', {
metrics,
close: async () => { root.unmount(); await client.cleanup(); },
});
Open with ?fail. Read window.repro.metrics.loads, inspect the pending/error elements, and call window.repro.close() or close the page afterward to stop the loop.
Suspected cause
SuspenseBinding.resolve in packages/react-db/src/useLiveSuspenseQuery.ts evicts the retry entry with setTimeout(release, 0) when the collection becomes error or crashed. The failed resource can disappear before React retries the initially suspended render. That retry creates a fresh resource, which starts the same failing load again.
Keeping that entry through the React retry, and releasing it on the collection's ordinary cleaned-up event, fixes this reproduction. It still needs to respect explicit cleanup/recovery and abandoned-query lifetime; the proposal is not to keep failures forever.
Related: #1343 was closed after error forwarding was fixed. This appears to be a remaining resource-lifetime case, rather than missing observer-error forwarding. #2396 uses the success mode of the same small fixture for a separate synchronous-readiness problem.
Versions
@tanstack/db / @tanstack/react-db 1.0.0-rc.1.4, React / React DOM 19.3.0, Chromium on macOS ARM64. The zero-delay eviction remains on current main. No router, React Compiler, application adapter, or persistence is involved.
- 主要言語
- TypeScript
- スター
- 4k
- フォーク
- 286
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 105
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/db のほかの issue
-
extractSimpleComparisons returns value: null when the right side of a comparison isn't a literalオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
`avg`, `min`, `max` and `sum` treat `null` values as `0`対応中かも @oyobbeb が 11 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
`Collection.currentStateAsChanges` JSDoc examples don’t match `CurrentStateAsChangesOptions`対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeout対応中かも @jp-knj が 23 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fb55/htmlparser2#2579 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue needs-review
難易度 1/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
Add Module DB Rulesオープンdocumentation public
難易度 1/5 1〜3時間 初心者へのやさしさ 68/100
midnightntwrk/umbradb#65 ·
メンテナーはふだん 2 日以内に返信
-
area/channels kind/bug priority/medium
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nanocoai/nanoclaw#4501 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs verification
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 13 日以内に返信