Skip to content

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

Open
ibirrer wants to merge 1 commit intoTanStack:mainfrom
ibirrer:fix/includes-duplicate-alias
Open

fix: duplicate alias in sibling includes silently breaks nested children#1455
ibirrer wants to merge 1 commit intoTanStack:mainfrom
ibirrer:fix/includes-duplicate-alias

Conversation

@ibirrer
Copy link
Copy Markdown

@ibirrer ibirrer commented Apr 4, 2026

Summary

When two sibling includes in .select() use the same alias (e.g., { i: issues } and { i: tags }), nested child collections silently produce empty results. The root cause is that all includes aliases are flattened into a single namespace — sharing one D2 graph input and one subscription, so the second sibling's collection data overwrites the first.

Fix

Give each includes subquery its own independent D2 graph input:

  • extractCollectionAliases no longer traverses into IncludesSubquery nodes, keeping collectionByAlias scoped to the top-level query
  • compileQuery accepts a createInput factory; when processing includes, each child gets fresh inputs for its source aliases
  • compileBasePipeline merges the new inputs into inputsCache and compiledAliasToCollectionId under unique keys (__inc_N_alias), so each gets its own subscription feeding the correct collection

Test

Regression test added to includes.test.ts: sibling includes with duplicate alias "i" — nested comments are populated. Fails without fix, passes with fix.

Fixes #1454

When two sibling includes in .select() used the same alias (e.g.,
{ i: issues } and { i: tags }), nested child collections silently
produced empty results. The root cause was that all includes aliases
were flattened into a single namespace — sharing one D2 graph input
and one subscription, so the second sibling's collection data
overwrote the first.

Fix: give each includes subquery its own independent D2 input.
- extractCollectionAliases no longer traverses into IncludesSubquery
  nodes, keeping collectionByAlias scoped to the top-level query.
- compileQuery accepts a createInput factory; when processing includes,
  each child gets fresh inputs for its source aliases via
  collectAllSourceAliases + createInput().
- compileBasePipeline merges the new inputs into inputsCache and
  compiledAliasToCollectionId under unique keys (__inc_N_alias),
  so each gets its own subscription feeding the correct collection.
@ibirrer ibirrer force-pushed the fix/includes-duplicate-alias branch from 0c54be0 to 309e89e Compare April 4, 2026 20:07
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.

Duplicate alias in sibling includes silently breaks nested children

1 participant