Skip to content
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

Dynamically fetch OAuth URLs when needed #3841

Merged
merged 6 commits into from
Feb 6, 2025

Conversation

malithsen
Copy link
Contributor

@malithsen malithsen commented Feb 5, 2025

Relates to #3692

Changes proposed in this Pull Request:

This introduces a minor improvement to the Stripe Settings page load by avoiding Stripe OAuth API calls when not required.

Stripe API calls are costly and making those calls on page load introduces ~2s page load time when testing locally. Currently there are 2 cases where we make API calls to Stripe.

  1. To load OAuth URLs
  2. To load Stripe account data.

This PR only addresses the 1st case.

There are three states where OAuth URL is needed.

  1. For new merchants who have not yet connected their Stripe account.
  2. For merchants who need to be reconnected using OAuth (Introducing the Re-Connect Promotional Surface #3322)
  3. When merchants want to reconnect the Stripe account via "Configure connection" modal in Settings.

With this PR, we only make the external Stripe API calls to get OAuth URLs if the store is in 1st or 2nd states.
For 3rd state, we delay the URL fetch until the modal is opened.

In my local tests, this saves ~400ms when loading the settings page.

For comparison, following is how the cachegrind call tree looks like for curl_exec before and after for a connected merchant.

Before
Image

After
cachegrind2

Testing instructions

We mainly want to do regression tests around the three scenarios where the OAuth URL is used.

  1. Go through onboarding as a new merchant and make sure you're able to connect the stripe account.
  2. Re-test Introducing the Re-Connect Promotional Surface #3322 and make sure "Configure connection" button in the promotional surface is still functional.
  3. As a connected merchant, go to Settings -> Configure connection and make sure the "Create or connect account" button works

CleanShot 2025-02-05 at 13 58 35


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

This prevents always loading OAuth URLs at page load and then loading
them via AJAX when needed.

- Add checks to prevent OAuth URL calls at page loads.
- Add AJAX endpoint to fetch Stripe OAuth URLs dynamically
- Update client-side React component to load OAuth URLs asynchronously
- Conditionally fetch OAuth URLs based on account connection status
@malithsen malithsen marked this pull request as ready for review February 5, 2025 20:26
@malithsen malithsen requested review from a team and diegocurbelo and removed request for a team February 5, 2025 20:26
Copy link
Member

@diegocurbelo diegocurbelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @malithsen, I really like this solution 👏🏼.

What do you think about moving the loading spinner inside the blue button (and disabling it)... the reconfigure button does not need the urls so it would work even if the oauth urls fail to load.
Screenshot_2025-02-05_at_17_42_15

@malithsen
Copy link
Contributor Author

What do you think about moving the loading spinner inside the blue button (and disabling it)... the reconfigure button does not need the urls so it would work even if the oauth urls fail to load.

Great suggestion! Thanks @diegocurbelo updated in 7fda578

CleanShot 2025-02-05 at 15 14 09

@malithsen malithsen enabled auto-merge (squash) February 6, 2025 01:35
@malithsen malithsen merged commit 6a91f17 into develop Feb 6, 2025
35 of 37 checks passed
@malithsen malithsen deleted the fix/avoid-unnecessary-stripe-oauth-calls branch February 6, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants