Firestore: local matching of in/array-contains ignores int/double equality, and NaN matches range filters (getDocsFromServer hangs)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- firebase, node.js, typescript
Research direction
Start with packages/firestore/src/core/filter.ts and trace how in, array-contains, and range filters compare values; the issue also points to mixIntegerDouble and semanticsEqual in the query pipeline. Reproduce the numeric equality and NaN range cases with the Firestore emulator using the supplied script. Done means local matching agrees with the backend for integer/double equality, signed zero, and NaN range filters, and the reported getDocsFromServer query resolves.
Written by the indexing model from the issue text.
Description
Operating System
Linux (Debian 12, kernel 6.1)
Environment (if applicable)
Node.js 26.13.0, Firestore emulator cloud-firestore-emulator-v1.22.0 (firebase-tools 15.35.0)
Firebase SDK Version
13.2.0 (@firebase/firestore 4.19.1)
Firebase SDK Product(s)
Firestore
Project Tooling
Plain Node.js ESM script, no bundler.
Detailed Problem Description
The SDK's local query matching disagrees with the backend on numbers:
in,not-in,array-containsandarray-contains-anycompare with strictvalueEquals, so integer1does not match double1.0and-0does not match0.==usesvalueCompareand does match them. The backend returns the documents, and the SDK then drops them from thegetDocsFromServerresult.- Range filters use
valueCompare, whereNaNsorts before every number, so a cached{ v: NaN }matchesv <= 5locally. The backend excludes it, the view never becomes consistent, andgetDocsFromServernever resolves (anonSnapshotlistener stays onfromCache: true).
Output of the script below:
v == 1: [ 'dbl1', 'int1' ]
v in [1]: [ 'int1' ]
a array-contains 1: [ 'int1' ]
v == -0: [ 'dbl0', 'int0' ]
v in [-0]: []
v <= 5 (cache): [ 'minf', 'nan', 'one' ]
v <= 5 (server): TIMEOUT
Expected: v in [1] and a array-contains 1 return [ 'dbl1', 'int1' ] like v == 1; v in [-0] returns [ 'dbl0', 'int0' ] like v == -0; v <= 5 returns [ 'minf', 'one' ] from both cache and server. Without the NaN document the last query resolves immediately. The docs define one numeric order for integers and doubles, with NaN only equal to NaN: https://firebase.google.com/docs/firestore/manage-data/data-types
The code is unchanged on main (8f4977509): packages/firestore/src/core/filter.ts uses arrayValueContains (strict equality) for the in/array-contains filters and valueCompare for ranges. Using valueEquals with mixIntegerDouble and semanticsEqual (as the pipeline code already does) and excluding NaN from range comparisons would match the backend.
Steps and code to reproduce issue
npm i [email protected]and start the Firestore emulator on 127.0.0.1:8580 (firebase emulators:start --only firestorewith{"emulators": {"firestore": {"port": 8580}}}infirebase.json).- Save as
repro.mjsand runnode repro.mjs:
import { initializeApp } from "firebase/app";
import {
initializeFirestore, connectFirestoreEmulator, collection, doc, setDoc,
getDocsFromServer, getDocsFromCache, query, where,
} from "firebase/firestore";
const PROJ = "demo-test";
const BASE = `http://127.0.0.1:8580/v1/projects/${PROJ}/databases/(default)/documents`;
const db = initializeFirestore(initializeApp({ projectId: PROJ }), {});
connectFirestoreEmulator(db, "127.0.0.1", 8580);
const ids = (snap) => snap.docs.map((d) => d.id).sort();
const timeout = (p) => Promise.race([p, new Promise((r) => setTimeout(() => r("TIMEOUT"), 8000))]);
// 1. Integer 1 / double 1.0 and integer 0 / double 0.0, written over REST
// (as the Admin, Python or Java SDKs can store them).
const c1 = "c1_" + Date.now();
const rest = (id, v) =>
fetch(`${BASE}/${c1}?documentId=${id}`, {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: "Bearer owner" },
body: JSON.stringify({ fields: { v, a: { arrayValue: { values: [v] } } } }),
});
await rest("int1", { integerValue: "1" });
await rest("dbl1", { doubleValue: 1.0 });
await rest("int0", { integerValue: "0" });
await rest("dbl0", { doubleValue: 0.0 });
const col1 = collection(db, c1);
console.log("v == 1:", ids(await getDocsFromServer(query(col1, where("v", "==", 1)))));
console.log("v in [1]:", ids(await getDocsFromServer(query(col1, where("v", "in", [1])))));
console.log("a array-contains 1:", ids(await getDocsFromServer(query(col1, where("a", "array-contains", 1)))));
console.log("v == -0:", ids(await getDocsFromServer(query(col1, where("v", "==", -0)))));
console.log("v in [-0]:", ids(await getDocsFromServer(query(col1, where("v", "in", [-0])))));
// 2. NaN with a range filter, after the documents are in the local cache.
const c2 = "c2_" + Date.now();
await setDoc(doc(db, c2, "nan"), { v: NaN });
await setDoc(doc(db, c2, "one"), { v: 1 });
await setDoc(doc(db, c2, "minf"), { v: -Infinity });
const le5 = query(collection(db, c2), where("v", "<=", 5));
console.log("v <= 5 (cache):", ids(await getDocsFromCache(le5)));
console.log("v <= 5 (server):", await timeout(getDocsFromServer(le5).then(ids)));
process.exit(0);
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 5.2k
- Forks
- 1k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 77
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-js-sdk
-
AI: ChatSession.sendMessage / sendMessageStream throw TypeError on blocked prompts (empty candidates) when tools are setPossibly taken @abhiramshaji-cyber claimed this today. Openapi: firebaseai
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#10641 ·
Maintainers usually reply within 1 day
-
api: firestore needs-attention question Repro Needed
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#10595 ·
Maintainers usually reply within 1 day
-
api: installations api: performance bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
firebase/firebase-js-sdk#10526 · 3 comments ·
Maintainers usually reply within 1 day
-
@firebase/firestore pins @grpc/grpc-js to ~1.9.0, holding consumers on a flagged releasePossibly taken @cherylEnkidu claimed this 51 days ago. Openapi: firestore needs-attention question stack:Angular
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
firebase/firebase-js-sdk#10400 · 4 comments · 9 reactions · 1 assignee ·
Maintainers usually reply within 1 day
-
Some (sub) package.json do not list the licences which lead to tools like syft report unknown licencePossibly taken @phoekerson claimed this 84 days ago. Openquestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#9326 · 5 comments ·
Maintainers usually reply within 1 day
All issues in firebase/firebase-js-sdk
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
inabagumi/shinju-date#7406 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
umami-software/umami#4787 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day