Skip to content

React Native Integration #2918

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

Closed
wants to merge 4 commits into from
Closed

React Native Integration #2918

wants to merge 4 commits into from

Conversation

scottcrossen
Copy link
Contributor

@scottcrossen scottcrossen commented Apr 16, 2020

No description provided.

@scottcrossen scottcrossen changed the title React Native integration React Native Integration Apr 16, 2020
@scottcrossen scottcrossen requested review from avolkovi and sam-gc and removed request for hiranya911, Feiyang1 and hsubox76 April 16, 2020 04:37
type: PersistenceType = PersistenceType.LOCAL;

async isAvailable(): Promise<boolean> {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should check if actually running in react native

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We dependency-inject this in for builds of react-native. If this file exists then it is running in react native. Would you me to make an additional check via the helper we've created?

Copy link
Contributor

Choose a reason for hiding this comment

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

for non react-native builds this function will still be available through the legacy polyfill, in those cases it should return false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I suck at closure: Are you saying that fireauth.storage.AsyncStorage.prototype.get was part of the public API for the SDK?

* App React Native Builds
*/
{
input: 'src/legacy_polyfill.rn.ts',
Copy link
Contributor

Choose a reason for hiding this comment

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

old SDK only had one file for everything, so we should only have one legacy polyfill that includes everything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't we established that the old SDK did things wrong? I don't think that's good justification for making one entrypoint -- especially since the configuration of the other rollup files (app, firebase) do this as well for tree-shaking purposes. If you would like me to only have one file then we are going to have to access closure to access the dependency injected libraries we need (in extended namespace firebase.INTERNAL.reactNative.AsyncStorage). Is that what you want?

Copy link
Contributor

Choose a reason for hiding this comment

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

for the polyfill we need to support the old API surface which was "wrong", the new SDK API provides multiple entry points

Copy link
Member

@Feiyang1 Feiyang1 Apr 17, 2020

Choose a reason for hiding this comment

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

In the firebase polyfill/compat layer, I want to avoid recreating the legacy internal APIs(used only by auth today) unless absolutely necessary, so it would be great if you can handle the dependencies in auth itself.

So I think it makes sense to have a rn specific entry point in the auth polyfill, because there won't be a rn entry point in @firebase/app polyfill. Otherwise, non RN applications that upgrade to the latest SDK will start to include AsyncStorage code, which increase the app size.

I'm also not sure what happens if you bundle @react-native-community/async-storage in a web application. Does it work at all?

Copy link
Member

@Feiyang1 Feiyang1 Apr 17, 2020

Choose a reason for hiding this comment

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

So I tried to bundle @react-native-community/async-storage and failed because its main field points to a Flow file.
You might get it to work by compiling the Flow file first, but It clearly says to me that user shouldn't bundle @react-native-community/async-storage themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the compat layer we will be using the old 'react-native' dependency as before. The new PR (#2947) has this.

@@ -8,6 +8,7 @@
"browser": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"react-native": "dist/index.rn.cjs.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

old SDK doesn't provide a react native build

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because the old SDK doesn't have a rollup config and doesn't support tree shaking. packages/app and packages/firebase have the react native build that the old SDK detects and abuses


import AsyncStorage from '@react-native-community/async-storage';

class ReactNativeLocalPersistence implements Persistence {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add in a followup PR once we establish how we would like the new SDK to be structured (this PR is finalized). I thought we were tracking these separately on the sheet so I didn't add unit tests.

@scottcrossen scottcrossen deleted the slc/react-native branch April 23, 2020 05:33
@firebase firebase locked and limited conversation to collaborators May 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants