nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
641 stars 99 forks source link

Support for Firebase Version 9 + #573

Closed lupas closed 2 years ago

lupas commented 2 years ago

Background

With Version 9 of the Firebase JS SDK, Firebase is adopting a new module first format that is optimized for elimination of unused code. The result is a potential significant reduction of Firebase library code in JavaScript bundles with a reduction of up to 80% in some scenarios. The way the Firebase modules are imported changed completely and does not really support the way this module injects Firebase into your Nuxt app.

This module was written for the Firebase Javascript SDK Version 8 and prior. It is currently not compatible with the new Version 9 supporting tree-shaking. To make it compatible with the new version while keeping the benefits of the new version, the module would most likely need to be re-written completely.

Workaround

Compat Syntax

You can use v8.0.0-beta.0 which supports Firebase v9+ with compat syntax.

Be aware that this is not future proof and will not work from v10 on forwards.

New Modular Mode Syntax

If you want to use Firebase version 9 in the new modular syntax, we advice you to implement Firebase yourself as described step-by-step in the following medium article. The approach is straight-forward and not harder than using this module.

This approach allows you to use three-shaking and all the features of the new version, while staying more flexible with future changes in the SDK.

Future of this module

It is currently unclear when, and if, this module will support modular mode (i.e. Firebase version 10+).

The module needs to become lighter, only focussing on the nuxt-specific issues at hand, while keeping the flexibility of using the benefits of the newer Firebase SDK modular mode.

I personally won't find time to re-write this module in the next few months. I might, but I can't promise. So if you are interested in working on it, let me know by creating a merge request, I would greatly appreciate it.

productdevbook commented 2 years ago

Come with nuxt 3 and gear support. I hope you can update soon.

simeon9696 commented 2 years ago

@lupas I know I'm in no position to ask this but would you consider updating the packaging to include @firebase/compat

This would allow your users to upgrade to v9 for now. It's supposed to be a drop in addition: image

bkuri commented 2 years ago

FWIW I just tried forking and adding /compat everywhere and failed miserably. There seem to be some assumptions regarding how the code was structured in v8 which apparently changed on the new version.

Hopefully @lupas can let us know what needs to be changed in order for me to submit a PR, which I would be happy to do.

lupas commented 2 years ago

@simeon9696 , @bkuri Thanks for the hint with the compat packages - great idea for the time being!

I just published v8.0.0-beta.0 which uses the /compat packages and seems to work very well with Firebase v9+ and the compat syntax.

I'm using it already on nuxt-firebase-demo - but haven't fully tested it.

Would be great if you could test it out if it works for you, I'll do some more tests and would publish it later on.

Thanks guys for your support!

PS: For the new modular syntax I still think either using Firebase directly or completely re-creating this module would be the way to go, since a lot would change.

bkuri commented 2 years ago

@lupas Thanks for the beta version! I've started testing and so far so good.

Now I see why my version failed… I missed a few dynamic calls here and there. :P

I'll keep testing it out for a few more days and report back!

mfreeman451 commented 2 years ago

I'm missing types support in my IDE, do I need to add something to tsconfig ?

lupas commented 2 years ago

@leku451 https://firebase.nuxtjs.org/tutorials/typescript

bkuri commented 2 years ago

@lupas just wanted to update you on my beta testing. So far I've experienced no issues at all on this side. I'm using pretty much every available feature (except for realtime db) on my apps, so I'm pretty confident that they'll work just fine in prod. :+1:

Do let me know if there's something specific that you'd like me to try out and I'll give it a shot. Cheers!

lupas commented 2 years ago

@bkuri Thanks a lot for your testing - really appreciate it! So far I haven't encountered any issues, therefore just published this in v8.0.0.

Closing this issue in favour of https://github.com/nuxt-community/firebase-module/issues/597.