Skip to content
Source
Sign inSign up
TanStack/db

fix: duplicate alias in sibling includes silently breaks nested children #1455

Closedibirrer(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1455/headopened

Showing 4 changed files with 64 additions and 6 deletions (loading 1).

x
0 of 4 viewed, 4 left
44 additions and 5 deletionspackages/db/src/query/compiler/index.tsModified
View file
@@ -141,6 +141,9 @@
// For includes: parent key stream to inner-join with this query's FROM
parentKeyStream?: KeyedStream,
childCorrelationField?: PropRef,
+ // Factory to create a fresh D2 input for an includes subquery alias.
+ // Each sibling gets its own input to avoid alias collisions.
+ createInput?: (alias: string, collectionId: string) => KeyedStream,
): CompilationResult {
// Check if the original raw query has already been compiled
const cachedResult = cache.get(rawQuery)
@@ -391,10 +394,16 @@
: subquery.query
​
+ // Give each includes child its own D2 inputs so that sibling
+ // subqueries using the same alias letter get independent streams.
+ const childInputs = createInput
+ ? createInputsForSources(childQuery, allInputs, createInput)
+ : allInputs
+​
// Recursively compile child query WITH the parent key stream
const childResult = compileQuery(
childQuery,
- allInputs,
+ childInputs,