firebase / firebase-js-sdk

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

FR: Firestore Persistence Support for Expo / React Native #7947

Open Yonom opened 8 months ago

Yonom commented 8 months ago

Operating System

iOS 17.2

Browser Version

React Native

Firebase SDK Version

10.7.1

Firebase SDK Product:

Firestore

Describe your project's tooling

React Native 0.73.2

Describe the problem

On React Native (v0.73.2), enabling persistence for Firestore fails.

@firebase/firestore: Firestore (10.7.1): Error using user provided cache. Falling back to memory cache: FirebaseError: [code=unimplemented]: This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.

Steps and code to reproduce issue

npx create-expo-app
yarn add firestore
import { initializeApp } from "firebase/app";
import { initializeFirestore, persistentLocalCache } from "firebase/firestore";

const firebaseConfig = {
  // config here
};

const app = initializeApp(firebaseConfig);

const firestore = initializeFirestore(app, {
  localCache: persistentLocalCache(),
})
yarn start --ios
cherylEnkidu commented 8 months ago

Hi @Yonom ,

Firestore doesn't support using web SDK as node SDK. Here are some possible workarounds:

  1. Use the Native SDK reactive native wrapper for iOS SDK and Android SDK.
  2. Use third party library to hack node environment to have indexdb implementation, but please keep in mind the indexdb behaviour might be different in those libraries.
Yonom commented 8 months ago

The native libraries require use_frameworks which is incompatible with React Native (Flipper, New Architecture/Fabric). I use the JS library for that reason.

This library already supports React Native for firebase/auth, I wish the same support would be extended to firebase/firestore

In the meantime, polyfilling indexdb should do, thanks for the hint

yanodnoralov commented 8 months ago

@Yonom can you please share how you will pollyfill for indexdb if you end up doing it? I'm having the same issue trying to get offline persistence for managed expo react native. Considering if i should eject and use react native firebase instead, but it's a big change.

dconeybe commented 8 months ago

FWIW this is how Firestore does it in its tests: https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/test/util/node_persistence.ts. Note that this is NOT officially supported.

cherylEnkidu commented 8 months ago

Hi @Yonom ,

The ticket has been filed as the feature request for internal tracking (b/320733516). In the meantime, please consider using workarounds suggested above.

yanodnoralov commented 8 months ago

@cherylEnkidu what is the process for feature requests? When might we expect to hear if Firebase will be adding support for persistence in tandem with expo/react-native? I see this is a highly requested feature in the community on various threads.

jonnyreeves commented 7 months ago

Integration with LokiJS could be a viable option here.

cherylEnkidu commented 7 months ago

Hi @yanodnoralov ,

There are a lot of factors contributing to feature request prioritization, number of user requesting is definitely one of them. The persistence support for React Native is a big project so in the meanwhile please do consider finding the other workarounds.

ahmadaIanazi commented 3 months ago

Where do vote on this feature request. Its really needed ! specially nowadays you see offline-first apps are everywhere, and they are requested by clients and companies.

cherylEnkidu commented 3 months ago

Hi @ahmadaIanazi ,

Every time we receive a new reply for the feature request, it will bring to the team discussion to rediscuss the priority. Thank you for reaching out!

dennislysenko commented 3 months ago

All, huge +1 on this. I went into a firebase-react native build under the assumption that what was listed on the firebase official support pages would be reflected in the client libraries. This omission was not documented as far as I could tell. React Native, using JS SDK, is not a small percentage of the apps that are being developed. This seems like a pretty major oversight to me from the Firebase product team.