WilliamDASILVA / nuxt-stripe-module

A NuxtJS module to import Stripe client script.
MIT License
114 stars 20 forks source link

Module crashes entire app if offline #25

Closed Radiergummi closed 3 years ago

Radiergummi commented 3 years ago

I've spent a while debugging now and narrowed it down to the Stripe module.

So I'm currently forced to work offline every now and again, and noticed that my Nuxt app seems to just stop during bootstrapping clientside.
After stepping through the code with the debugger, I arrived at the loadStripe function exported by the stripe client. Here, the script can't be loaded, and it rejects the promise with an error. This all makes sense from Stripe's perspective, but it doesn't work for Nuxt.

I propose catching the error in the plugin function and setting the Stripe instance to null or similar: while Stripe of course can't work offline, this should only cause an error if we actually attempt to make calls to its API.
Otherwise, there's nothing we can do to catch the error and recover from it.
As this doesn't only affect developer mode but also PWAs without network access or outages, it'd make sense to handle offline mode.

I'll happily create a PR if you're interested.

WilliamDASILVA commented 3 years ago

Hello, thanks for opening the issue. I've made the Stripe instance nullable if the loadScript comes to fail.

Radiergummi commented 3 years ago

Wow, awesome! Thank you for the quick fix! 🎉