See this video for a walkthrough of the bug:
This is a bug that occurs when Firestore multi-tab-persistence is turned on, you have two tabs open to the same app, and you submit mutations in the tab which is not the Firestore leader tab. Conversely, if you submit mutations in the tab which has been internally designated by Firestore as the leader, than everything works as expected.
- Note: my interpretation that "the Firestore leader tab" is important is based on my experience recreating the bug. I don't know for a fact that that is involved with triggering the bug (but I think it is).
- Clone repository
- Note: there's an included
.devcontainerwhich you can use if you're into that sort of thing.
- Note: there's an included
yarn install- Add a
.envfile to the repo root that provides the following environment variables- VITE_FIREBASE_API_KEY= (your value goes here)
- VITE_FIREBASE_AUTH_DOMAIN= (your value goes here)
- VITE_FIREBASE_DATABASE_URL=
- VITE_FIREBASE_PROJECT_ID= (your value goes here)
- VITE_FIREBASE_STORAGE_BUCKET= (your value goes here)
- VITE_FIREBASE_MESSAGING_SENDER_ID= (your value goes here)
- VITE_FIREBASE_APP_ID= (your value goes here)
- VITE_FIREBASE_MEASUREMENT_ID=
- VITE_FIREBASE_EMULATORS=true
- VITE_FIREBASE_EMULATOR_HOSTNAME=0.0.0.0
- Note that
0.0.0.0for the host is important if you're using the emulators inside a devcontainer
- Note that
- VITE_FIREBASE_EMULATOR_FIRESTORE_PORT=8080
- VITE_FIREBASE_EMULATOR_AUTH_URL=http://localhost:9099
yarn emulatorsin one terminal tabyarn devin another terminal tab- Open the app on http://localhost:3000 and open the browser console
- Open a second tab to the app on http://localhost:3000 and open the browser console
- In the second tab (which is not the Firestore leader tab)
- click the button to create a new draft
- Click the button to submit the new tab
- Feel free to edit the draft content or accept the default content--it doesn't matter.
- At this point, you should be able to note the
console.logstatements for the second tab and the first tab do not match. In the second tab, the console statements should indicate that, after submitting the draft, Firestore is emitting an update as expected, then emitting a stale value (i.e. the bug), then emitting the correct value again.