formspree / formspree-js

The fastest way to hook up a React form
https://formspree.io/javascript
MIT License
63 stars 12 forks source link

Stripe js in production even though it's not being imported #16

Closed judsonlmoore closed 1 year ago

judsonlmoore commented 2 years ago

I am using the @formspree/react component in a project that is then somehow getting a bunch of stripe js in production. Locally, these files are not being injected. You can see this in production at https://bikefi.net.

For example: https://js.stripe.com/v3 is being loaded, but there are 6 "stripe" items if you search the code in developer tools.

In my project I am importing the component like this import { useForm, ValidationError } from '@formspree/react'

Stripe is not configured as a plugin on my formspree account, either.

Any ideas?

rohitdatta commented 2 years ago

Hi @judsonlmoore! That is strange, Stripe is supposed to be lazy loaded so it only gets loaded if you use the Stripe plugin. However, I'm seeing the same thing so we'll investigate what's going on.

judsonlmoore commented 2 years ago

Thanks @rohitdatta if I can support at all, please let me know. I'll follow this ticket for updates.

colevscode commented 2 years ago

In the mean time if you pin @formspree/react to version 2.2.5 you'll avoid this problem until we sort it out. See https://github.com/formspree/formspree-react/commits/main

colevscode commented 2 years ago

Hi we have a version at @formspree/react@2.3.4-beta.2 that should correctly lazyload stripe. If you have a minute @judsonlmoore can you try it out to make sure stripe isn't loading?

nathanielbelen commented 2 years ago

2.3.3 was loading Stripe for me when unnecessary, and 2.3.4-beta.2 works correctly.

judsonlmoore commented 2 years ago

I can confirm that 2.2.5 resolved the issue. I don't see 2.3.4-beta.2 available in the list of public releases so assume that might be private and therefor I couldn't test with that one.

colevscode commented 2 years ago

Since version 2.4.0 stripe should correctly lazy load. There is still a small (~6kb compressed) react shim in the bundle, but the main stripe library doesn't load unless a stripe publishable key is set when adding <FormspreeProvider>.

I'll keep this issue open for a bit longer until we make our announcement about stripe support in Formspree React. Until then feedback welcome!

colevscode commented 1 year ago

See our announcement here: https://formspree.io/blog/react-payments-stripe-elements/

mwskwong commented 1 year ago

@colevscode Did you guys change something? I'm using v2.4.1 and I noticed Stripe is bundled even though all I use is useForm.

And I taken a look at the source code of useForm and noticed it does import from Stripe, but it appears to be a normal import, not dynamic import. image

colevscode commented 1 year ago

@mwskwong yes as mentioned above:

Since version 2.4.0 stripe should correctly lazy load. There is still a small (~6kb compressed) react shim in the bundle, but the main stripe library doesn't load unless a stripe publishable key is set when adding <FormspreeProvider>.

Is this what you're seeing?