Firestore Web creates thousands of records in localStorage until throws QuotaExceededError
Closed this issue · 6 comments
Operating System
MacOs
Environment (if applicable)
Chrome 139.0.7258.128, React Web Production Build (https://finance.wads.dev/)
Firebase SDK Version
11.7.3
Firebase SDK Product(s)
Firestore
Project Tooling
Project Tooling
The app is built with the following tooling:
- React + Vite + TS
- Firebase Auth, Firestore
Detailed Problem Description
Problem description
During normal app usage, the browser started storing tens of thousands of keys in localStorage with the prefix:
firestore_mutations_firestore/[DEFAULT]/goldenunicornfc/...
I counted more than 37,711 entries of this type.
This quickly filled up the localStorage quota, making the app unusable (DevTools cannot even open the Storage tab, and any call to localStorage.setItem fails).
Additionally, a critical error is thrown in the console:
index-CoKaw0am.js:910 Uncaught Error: FIRESTORE (11.9.0) INTERNAL ASSERTION FAILED: Unexpected state (ID: b815)
CONTEXT: {"cc":"QuotaExceededError: Failed to execute 'setItem' on 'Storage':
Setting the value of 'firestore_clients_firestore/[DEFAULT]/goldenunicornfc/_5aPCl5rs55dDzPdHvpj9' exceeded the quota.
at oh.setItem (...)
at oh.uo (...)
at oh.addLocalQueryTarget (...)
at DO (...)
at async cb1 (...)
at async SO (...)"}
Expected behavior (I think)
localStorage-dump-finance-wads-dev-2025-08-17T03-24-42-197Z.json
- Firestore should primarily use IndexedDB for offline persistence.
localStorageshould only contain a small number of control keys, not tens of thousands.- Processed mutation records should be properly cleared.
Steps and code to reproduce issue
Additional details
- Public repository: GoldenUnicornFinanceControl/Web - 74ea33f62dc9823bc70a551b0f12751398001710
- A full dump of
localStorageis available (I can attach it as JSON if required). - Firebase SDK version: initially
"firebase": "^11.7.3"(in yarn.lock file) - Browser: Chrome 139.0.7258.128
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
@victorwads, is this issue something that you can reliably reproduce? If so, we could benefit from getting some debug logs from the SDK. Enabling debug logging should look something like this.
import {setLogLevel} from '@firebase/firestore';
...
setLogLevel('debug');
...
Also, is there a chance that your device was offline, or the app was not able to connect to the Firestore backend, and the app was making lots of local changes? A hunch here based on what you've shared. But it looks like the app has a bunch of pending mutations, and possibly those mutations are not getting written to the backend and therefore not getting cleared from local storage.
Hey @victorwads. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
I’ll enable debug mode to gather more information about it, but when this issue happens, the browser freezes until localStorage is completely full.
I think I may have found where it occurs — it seems to be a mix between my own implementation and the way Firebase handles some queue internally.
Yes, it also happens in production, but it’s easier to trigger after several page reloads.
Reloading interrupts Firebase requests before they finish and prevents the temporary localStorage data from being cleared, which seems to cause Firestore to enter an infinite loop.
At that point, the only way to recover is by clearing all storage (indexedDB and localStorage), which makes the page work again.
First Scenario:
My code listens to localStorage change events, and from time to time it sends data to Firebase.
This leads to an almost infinite loop.
From what I understand, Firestore creates temporary localStorage entries while processing requests.
In my case, every document.set() triggers another localStorage event.
I partially fixed it by removing the localStorage usage from my logic.
This reduced the frequency of the issue but did not completely stop it.
Second Scenario:
TODO... still collecting data, I will update this.
Hey @victorwads. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@victorwads if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.