Nested includes are undefined on next render after collection.update
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- react, typescript
調査の方向性
再現例に示されている、ネストされた useLiveQuery クエリと親の documentCollection.update 呼び出しから始めます。ドキュメント、スキーマ、フィールドの各コレクションを使って問題を再現し、その後、更新がネストされた結果にどのように伝播するかを追跡します。collection.update と更新の後に、関係のない React の再レンダリングを強制せず、ネストされたスキーマデータとフィールドデータがレンダリングされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
- I've validated the bug against the latest version of DB packages
Packages:
"@tanstack/db": "^0.6.7",
"@tanstack/electric-db-collection": "^0.3.5",
"@tanstack/react-db": "^0.1.85",
Describe the bug
I have a useLiveQuery with nested collections. When I call update on the parent collection, the nested collections are undefined. Sometimes refreshing the page the nested items are still undefined. A hard refresh is required.
This is using electric-sync. I can see the successful write call and shape update with matching txid.
If you force a re-render, the nested objects appear. See Additional Context below.
// collection
// the other two collection funcs are almost identical
export const createDocumentCollection = (labId: number) =>
createCollection(
electricCollectionOptions<DocumentRow>({
id: `documents:${labId}`,
shapeOptions: {
url: electricSyncUrl,
params: {
table: 'documents',
where: 'lab_id = $1',
params: { '1': String(labId) },
columns: SYNC_COLUMNS,
},
fetchClient: (input, init) => fetch(input, { ...init, credentials: 'include' }),
columnMapper: snakeCamelMapper(),
parser: {
data: (data) => JSON.parse(data),
},
},
getKey: (row) => row.id,
onUpdate: async ({ transaction }) => {
const { original, changes } = transaction.mutations[0]
const response = await DocumentService.updateDocument(labId, original.id, changes)
return { txid: response.txid }
},
})
)
// query
const { data: documentQuery } = useLiveQuery(
(q) =>
q
.from({ document: documentCollection })
.where(({ document }) => eq(document.id, documentId))
.select(({ document }) => ({
...,
schema: toArray(
q
.from({ schema: schemaCollection })
.where(({ schema }) => eq(document.schemaId, schema.id))
.select(({ schema }) => ({
...,
fields: toArray(
q
.from({ field: fieldCollection })
.where(({ field }) => eq(field.schemaId, schema.id))
.select(({ field }) => field)
),
}))
),
})),
[documentCollection, schemaCollection, fieldCollection, documentId]
)
const document = documentQuery[0]
const schema = document.schema[0] // comes up undefined
const fields = schema?.[0].fields ?? []
const update = (name: string, v: string) => {
return documentCollection.update(documentId, (draft) => {
draft[name] = v
})
}
To Reproduce
Steps to reproduce the behavior:
- Setup nested include collection like above example
- Call collection.update where collection is the parent collection (documentCollection in example)
- Observe nested objects are now undefined
- Refresh the page
- Observe nested objects are now undefined
Expected behavior
I would expect the nested data to render after the update.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop:
- OS: macOS
- Browser: chrome
- Version 148.0.7778.97
Additional context
If i add a simple useState counter to force a re-render, the nested collections appear
const [count, setCount] = useState(0)
return (
<>
<button onClick={() => setCount((c) => c + 1)}>{count}</button>
...rest of my component
</>
)
- 主要言語
- TypeScript
- スター
- 3.9k
- フォーク
- 272
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 212
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/db のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"対応中かも @KyleAMathews が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
TanStack/db#2056 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
yjh051108/dsh-routing-suite#216 ·
-
kind/bug priority/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memory対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 半日 初心者へのやさしさ 66/100
apache/fineract-consumer-facing#175 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1時間未満 初心者へのやさしさ 82/100
awslabs/visual-asset-management-system#413 ·
メンテナーはふだん 1 日以内に返信