Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: deprecation guide for moving to firebase-js-sdk v9 modular API #8279

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .spellcheck.dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ mono-repo
multidex
Multidex
namespace
Namespaced
namespaced
natively
NDK
Expand All @@ -133,6 +134,7 @@ OAuth
onboarding
onwards
OpenID
Perf
perf
performant
personalization
Expand Down Expand Up @@ -163,6 +165,7 @@ RN60
RN61
RNFB
RNFirebase
RTDB
SafetyNet
Salakar
scalable
Expand Down Expand Up @@ -213,6 +216,7 @@ v5
v6
v7
v9
v22
Ventura
VPN
VSCode
Expand Down
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: React Native Firebase
description: Welcome to React Native Firebase! To get started, you must first setup a Firebase project and install the "app" module.
next: /typescript
next: /migrating-to-v22
---

> React Native Firebase has begun to deprecate the namespaced API (i.e firebase-js-sdk `< v9` chaining API). React Native Firebase will be moving to the modular API (i.e. firebase-js-sdk `>= v9`) in the next major release. See [migration guide](/migrating-to-v22) for more information.

React Native Firebase is the officially recommended collection of packages that brings React Native support for all Firebase services on both Android and iOS apps.

React Native Firebase fully supports React Native apps built using [React Native CLI](https://reactnative.dev/docs/environment-setup?guide=native) or using [Expo](https://docs.expo.dev/).
Expand Down
74 changes: 74 additions & 0 deletions docs/migrating-to-v22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Migrating to v22
description: Migrate to React Native Firebase v22.
previous: /
next: /typescript
---

# Switching off warning logs

You may notice an influx of console warning logs as we continue deprecating all existing namespaced API. If you would like to switch these logs off, you may set the following global property to `true` anywhere before you initialize Firebase.

```js
globalThis.RNFB_SILENCE_V8_DEPRECATION_WARNINGS = true;
```

# Migrating to React Native modular API

React Native Firebase does not currently have documentation for modular API. A refresh of the React Native Firebase documentation is something we will be aiming to achieve in the near future. We're keen to move the project to TypeScript which will then allow us to generate reference documentation from those types.

However, if you are familiar with the Firebase JS SDK, it will be a much smoother process. React Native Firebase is using the same API as can be found on the official [Firebase JS SDK modular API documentation](https://firebase.google.com/docs/reference/js).
Comment on lines +18 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how much guide we really need? Upstream is pretty thin. I link it here then add a rough explanation and I think that's a "guide" really. No need to talk about the future typescript plans or anything, just "here's the idea, here's an upstream link, get it done" ?

Suggested change
React Native Firebase does not currently have documentation for modular API. A refresh of the React Native Firebase documentation is something we will be aiming to achieve in the near future. We're keen to move the project to TypeScript which will then allow us to generate reference documentation from those types.
However, if you are familiar with the Firebase JS SDK, it will be a much smoother process. React Native Firebase is using the same API as can be found on the official [Firebase JS SDK modular API documentation](https://firebase.google.com/docs/reference/js).
If you are familiar with the Firebase JS SDK, the upgrade will be a familiar process, following similar steps to [the migration guide](https://firebase.google.com/docs/web/modular-upgrade#refactor_to_the_modular_style) for firebase-js-sdk.
React Native Firebase uses the same API as the official [Firebase JS SDK modular API documentation](https://firebase.google.com/docs/reference/js) so the same migration steps apply here, except there is no need for special "compat" imports as an intermediate step.
The process will always follow the same steps for every API you use:
- determine the new modular API function for the old namespaced API you are using
- import that new modular API function
- change the call from using the firebase module to access the API and passing parameters, to the new style of using the modular API function, passing in the firebase module object(s) required for it to work and then the parameters.
In the end, it should be a very mechanical process and can be done incrementally, one API call at a time.
There are concrete examples below to show the process


## Firestore Deprecation Example

### Namespaced (deprecated) Query

You ought to move away from the following way of making Firestore queries. The React Native Firebase namespaced API is being completely removed in React Native Firebase v22:

```js
import firestore from '@react-native-firebase/firestore';

const db = firestore();

const querySnapshot = await db.collection('cities').where('capital', '==', true).get();

querySnapshot.forEach(doc => {
console.log(doc.id, ' => ', doc.data());
});
```

### Modular Query

This is how the same query would look using the new, React Native Firebase modular API:

```js
import { collection, query, where, getDocs, getFirestore } from '@react-native-firebase/firestore';

const db = getFirestore();

const q = query(collection(db, 'cities'), where('capital', '==', true));

const querySnapshot = await getDocs(q);

querySnapshot.forEach(doc => {
console.log(doc.id, ' => ', doc.data());
});
```

For more examples of requesting Firestore data, see the official Firebase documentation for [Get data with Cloud Firestore](https://firebase.google.com/docs/firestore/query-data/get-data).

### Migration Help

You will find code snippets for "Web namespaced API" and "Web modular API" throughout the official Firebase documentation. Update your code to use "Web modular API". Here are some links to help you get started:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fantastic


- [Firestore](https://firebase.google.com/docs/firestore/quickstart)
- [Auth](https://firebase.google.com/docs/auth/web/start)
- [RTDB](https://firebase.google.com/docs/database/web/start)
- [Storage](https://firebase.google.com/docs/storage/web/start)
- [Remote Config](https://firebase.google.com/docs/remote-config/get-started?platform=web)
- [Messaging](https://firebase.google.com/docs/cloud-messaging/js/client)
- [Functions](https://firebase.google.com/docs/functions/callable)
- [App Check](https://firebase.google.com/docs/app-check/web/recaptcha-provider)
- [Analytics](https://firebase.google.com/docs/analytics/get-started)
- [Perf](https://firebase.google.com/docs/perf-mon/get-started-web)
- [Crashlytics](https://github.com/invertase/react-native-firebase/blob/main/packages/crashlytics/lib/modular/index.d.ts) (Crashlytics doesn't exist on Firebase web, this is a link to the type declarations which contains all methods available).
2 changes: 2 additions & 0 deletions docs/sidebar.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- - Getting Started
- '/'
- - Migration Guide to v22
- '/migrating-to-v22'
- - TypeScript
- '/typescript'
- - Platforms
Expand Down
2 changes: 1 addition & 1 deletion docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: TypeScript
description: Using TypeScript with React Native Firebase
next: /other-platforms
previous:
previous: /migrating-to-v22
---

The React Native Firebase project comes with support for TypeScript. The project provides
Expand Down
17 changes: 11 additions & 6 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ const mapOfDeprecationReplacements = {
};

const v8deprecationMessage =
'This v8 method is deprecated and will be removed in the next major release ' +
'as part of move to match Firebase Web modular v9 SDK API.';
'This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release ' +
'as part of move to match Firebase Web modular v9 SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was called out as confusing - using "v9" at all - js-sdk is on v11 now anyway, and was it v9 of react-native-firebase, but we're going to v21? With enough context it makes sense but I think just strictly using "namespaced" and "non-modular" is good enough

Suggested change
'as part of move to match Firebase Web modular v9 SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22';
'as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22';


export function deprecationConsoleWarning(nameSpace, methodName, instanceName, isModularMethod) {
if (!isModularMethod) {
Expand All @@ -225,8 +225,11 @@ export function deprecationConsoleWarning(nameSpace, methodName, instanceName, i
const deprecatedMethod = instanceMap[methodName];
if (instanceMap && deprecatedMethod) {
const message = createMessage(nameSpace, methodName, instanceName);
// eslint-disable-next-line no-console
console.warn(message);

if (!globalThis.RNFB_SILENCE_V8_DEPRECATION_WARNINGS) {
// eslint-disable-next-line no-console
console.warn(message);
}
}
}
}
Expand Down Expand Up @@ -367,6 +370,8 @@ export function warnIfNotModularCall(args, replacementMethodName = '') {
message += ` Please use \`${replacementMethodName}\` instead.`;
}

// eslint-disable-next-line no-console
console.warn(message);
if (!globalThis.RNFB_SILENCE_V8_DEPRECATION_WARNINGS) {
// eslint-disable-next-line no-console
console.warn(message);
}
}
Loading