fuentesloic / nuxt-stripe

MIT License
90 stars 8 forks source link

Lazy load and loading only on the page that it needed #20

Closed YosefMets closed 1 year ago

YosefMets commented 1 year ago

Hi, After adding this modul to nuxt.config all Stripe scripts and HTML element were rendered on all pages. I don't even use it. Is it possible to only add it to pages where I use it and with lazy loading?

sandros94 commented 1 year ago

It all comes down to this:

https://github.com/fuentesloic/nuxt-stripe/blob/23c74938a3c10173f07c451dba3fbb20fb493931/src/module.ts#L73-L74

But I'm having an hard time trying to fix this.

sandros94 commented 1 year ago

In #19 I wanted to fix a double call for the useClientStripe, but in doing so I was able to just remove that line, this could potentially fix both issues.

YosefMets commented 1 year ago

@Sandros94 I don't understand your approach. So you finally fixed it? Cause there's nothing I can do about this problem

sandros94 commented 1 year ago

So you finally fixed it? Cause there's nothing I can do about this problem

Yes, I did manage to fix it, but it is still under review in that PR. I should update the description to mention this issue too.

I don't understand your approach.

The issue was just that the stripe-js (the one that is responsible to load Stripe script and HTML elements client side) not only it was forcefully loaded as a global plugin, always present and available, but it was double called when used with useClientStripe.

I know its not a good practice (with security concerns), but you could clone the repo I use for the PR and do yarn && yarn prepack && yarn pack to create a local tgz to use test in your project.

flozero commented 1 year ago

Hey hope you doing good I will have a look this weekend of your work :)

flozero commented 1 year ago

Hey I have done a PR that should handle the behavior you are expecting. It will be loaded only the first time you will use it. Check the PR. This will be merge this week. It will create a breaking change as we are going to harmonize the api config

sandros94 commented 1 year ago

I'll mainly respond in the PRs #19 and #22. But long story short IMO:

22 currently just delays when the stripe-js client is loaded, but doesn't make it lazy load. Relying on addPlugin it will make it load app/website wide, degrading user performance once it has loaded it regardeless of the page where the user is.

Why open up a new PR when there is already another one that is currently discussed on with the maintainers?