-
Notifications
You must be signed in to change notification settings - Fork 407
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
Reactfire preventing lazy loading of firebase modules #488
Comments
Hi @Mattinton, this is really interesting, thanks for the repros. My first thought was that maybe we were accidentally only exporting the .cjs build of ReactFire, but we do have the |
I wonder if it's because our package.json is missing the
Related TSDX issue (ReactFire uses TSDX for the build): jaredpalmer/tsdx#298 (comment) update: I pulled https://codesandbox.io/s/elegant-roentgen-2iyt8?file=/src/App.tsx down locally, npm installed, then modified ReactFire's package.json in the node_modules folder to have an |
It seems that just using I'm not sure why, because FirebaseAppProvider doesn't import either of those. It only imports the following: Lines 1 to 2 in f768f4d
When I try to just import I think it has something to do with our build. UPDATE: After investigating more, I didn't have tree shaking properly enabled in my tests for my comment above. Once I got tree shaking set up, the extra stuff was dropped from my bundle |
I did fork the repo and play around with it myself and also had no luck. I did notice that importing performance lazily didn't add to the overall package size and worked as expected. What are the differences between performance and firestore/storage? |
Hey @jhuleatt did you ever make any progress on this? Cheers |
Hey there, got the same issue, I just pulled all my hairs out my head to know what libraries was causing this. finally I just did a little hack with the webpack config by using https://webpack.js.org/configuration/externals/ config.externals = { 'firebase/database': 'root Math', }; this hack force remove the firebase/database dependency out of the bundle. |
When using Next.js, every module in Firebase appears to be bundled: #489 (comment) |
When using ReactFire I want to lazy load Firestore to reduce build initial build size and improve load times. When using ReactFire lazy loading firestore does not happen even while using
import('firebase/firestore')
.I have included a version that does not use ReactFire with working lazy loading as shown by the initialisation time.
I have also included a version that does use ReactFire where I am trying to use lazy loading but I believe it is not working.
I noticed this in a Nextjs project with the bundle analyzer but haven't included Nextjs in the examples for simplicity.
Version info
React: 17.02
Firebase: 9.4.1
ReactFire: 4.2.1
Test case
Test case without using ReactFire and lazy loading working:
https://codesandbox.io/s/blissful-scott-05qj6?file=/src/App.tsx
https://csb-9c5hc.netlify.app/
Test case with using ReactFire and lazy loading not working:
https://codesandbox.io/s/elegant-roentgen-2iyt8?file=/src/App.tsx
https://csb-2iyt8.netlify.app/
You can use the network tab to see that 6 networks requests are made without ReactFire but only 5 are made with using it, you can also see the breakdown of chunks in the lighthouse analysis.
Lighthouse Treemap without ReactFire
Lighthouse Treemap with ReactFire
This is quite a big blocker for me so any help would be appreciated.
Steps to reproduce
Open the two codesandbox's/netlify deployments above.
Expected behavior
Firestore is loaded in a separate chunk.
Actual behavior
Firestore is loaded in the initial chunk.
The text was updated successfully, but these errors were encountered: