firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.81k stars 884 forks source link

Web Worker support for persisting multiple tab #8438

Open u12206050 opened 3 weeks ago

u12206050 commented 3 weeks ago

Operating System

Windows & OSX

Browser Version

All

Firebase SDK Version

10.13.0

Firebase SDK Product:

Firestore

Describe your project's tooling

Vite, Vue, Web Worker

Describe the problem

We have a had massive success in regards to performance moving all the Firestore logic to a Web worker, however when we implemented it a year ago the only option for persistence was with persistentSingleTabManager and forceOwnership: true. A year on and one of the our most common issues are users opening our app in multiple tabs, and then saying things are not working as expected.

It seems currently due to the lack of support of Local Storage in web workers, I propose a simple adapter solution, whereby during the setup of persistentMultipleTabManager in the context of a web worker, developers can supply there own local storage adapter, that implements the same interface as the most common localStorage in modern browsers.

The adapter could then handle the messaging part/storage that Firestore requires in order to manage multiple tabs.

Steps and code to reproduce issue

Setup firestore in a Web worker, and use persistentMultipleTabManager

by default it attempts to use LocalStorage, but ideally can be supplied with an adapter for LocalStorage that could handle cross window messaging.

ehsannas commented 3 weeks ago

Hi @u12206050 ! Thanks for your proposal. I brought it up with the team, and we think it'd be a useful addition.

While we can't prioritize adding this feature right now, we always welcome contributions. I think you'd need to pass in your adapter instance somewhere (such as PersistentCacheSettings), and then use your adapter here.