firebase / firebase/firebase-tools

Emulator crashes in unexpected state when queried with startAfter(undefined). forced to restart.

Open
#3,579 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

I'm running into a bug that puts the emulator into a bad state, causing all subsequent queries to fail, and forces me to restart the emulator.

### [REQUIRED] Environment info

**firebase-tools: 9.16.0**

**Platform: macOS**

### [REQUIRED] Test case

see STR:

### [REQUIRED] Steps to reproduce

1. Add documents to a collection:

```javascript
await Promise.all([
firebase.firestore().collection("test").add({"type": "3", created_at: firebase.firestore.FieldValue.serverTimestamp()}),
firebase.firestore().collection("test").add({"type": "3", created_at: firebase.firestore.FieldValue.serverTimestamp()}),
]);
```

2. Confirm you can query successfully with no errors:

```javascript
(await firebase.firestore().collection('test')
.limit(5)
.where("type", "==", "3")
.orderBy("created_at", "desc")
.get()
).docs.map(d => d.data())
```

3. Add in `startAfter(undefined)` to the query:
```javascript
(await firebase.firestore().collection('test')
.limit(5)
.where("type", "==", "3")
.orderBy("created_at", "desc")
.startAfter(undefined) // <---- causes the error
.get()
).docs.map(d => d.data())
```
### [REQUIRED] Expected behavior

The parameter should be skipped, or worst case an error message around not being able to pass `undefined`

### [REQUIRED] Actual behavior

```
[2021-07-14T21:29:17.408Z] @firebase/firestore: Firestore (8.6.8): INTERNAL UNHANDLED ERROR: TypeError: Cannot use 'in' operator to search for 'nullValue' in null
Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'nullValue' in null
[2021-07-14T21:29:44.986Z] @firebase/firestore: Firestore (8.6.8): FIRESTORE (8.6.8) INTERNAL ASSERTION FAILED: Unexpected state
Uncaught Error: FIRESTORE (8.6.8) INTERNAL ASSERTION FAILED: Unexpected state
```

Here's a screenshot showing the same steps in my local console:

![image](https://user-images.githubusercontent.com/7410770/125697038-ba43b6ca-9f3e-4b9a-8fbb-bc09f748fd4f.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.