#10919·tldraw

Store queries return different results from scratch and incrementally for some matchers

Author: MitjaBezensekCreated Sep 24, 2026Updated Sep 24, 2026
Labelssdk

store.query has two matching strategies: executeQuery (index lookup, used when a query is computed from scratch) and objectMatchesQuery (predicate, used for incremental updates). They disagree on several inputs, so the same ids() / records() / exec() query can return a different set depending on whether it was built from scratch or updated incrementally. Membership then depends on edit history.

Cases that disagree on main

Query From scratch (index) Incremental (predicate)
{ tag: { eq: undefined } } matches nothing (indexes only track defined values) matches records where tag is undefined
{ n: { eq: NaN } } matches NaN (Map lookup is SameValueZero) never matches (NaN !== NaN)
{ n: { gt: NaN } } matches nothing matches every number
{ n: { gt: 70, neq: 75 } } only the first operator applies all operators apply
exec(type, {}), or { metadata: {} } via ids() [] every record
{ metadata: { extras: {} } } or { metadata: { x: 5 } } (no matcher below depth 1) every record only records whose metadata is an object

Repro

typescript
// books with n = 60, 75, 80
const ids = store.query.ids('book', () => ({ n: { gt: 70, neq: 75 } }))
ids.get() // from scratch: 75 and 80 (only `gt` was applied)
store.update(book75.id, (b) => ({ ...b, title: 'renamed' })) // unrelated field
ids.get() // incremental: 80 only (the predicate applies `neq` too)

Expected

One matcher semantics shared by both paths: undefined values match no matcher, eq/neq use SameValueZero, every operator in a matcher applies, NaN never satisfies gt, and an expression with no matchers at any depth constrains nothing (so an empty or matcher-free nested sub-expression matches every record).

Notes

  • #10211 fixed the first five rows by sharing a single matchesValue between both paths, but its nested-expression check (hasAnyKey) only looks one level down, so the last row still disagreed. Skipping a nested entry when extractMatcherPaths(sub).length === 0 (or a recursive "has any matcher" check) would close it. A new fix should include a depth-2 test where the nested field is missing or null, and at least one test that goes through reactive ids() across an incremental update.
  • No first-party caller uses any of these shapes (editor queries are lone eq, or neq on ids/user ids), so this is SDK API correctness, not a user-visible tldraw bug.
  • Part of the store review in #10253.