Skip to content

fix: [M3-7177] - Fix MSW not always intercepting API calls#9717

Merged
bnussman-akamai merged 2 commits intolinode:developfrom
bnussman-akamai:fix/enable-dev-tools-before-loading-app
Sep 26, 2023
Merged

fix: [M3-7177] - Fix MSW not always intercepting API calls#9717
bnussman-akamai merged 2 commits intolinode:developfrom
bnussman-akamai:fix/enable-dev-tools-before-loading-app

Conversation

@bnussman-akamai
Copy link
Member

Description 📝

Sometimes, with the MSW on, you load the app and some API calls don't get properly intercepted and the real API responds with data. I think this is because the MSW is not always being initialized before our app loads.

I think this use to not be an issue, but I think #9525 made it so that the MSW gets enabled later than it use to, causing this race condition.

This PR brings back some logic from #9525 (but using async/await instead of a callback) that will load dev tools before we render the app.

Major Changes 🔄

How to test 🧪

Note

This seemed to be like a race condition so it is hard to reproduce the bug or verify the fix works

  • Check out this PR
  • Turn on the MSW
  • Verify that all API data (like regions, linodes, etc) is coming from the MSW and not the real API
  • Refresh the page a few times and confirm that every time, data is coming from the MSW and not the real API

@bnussman-akamai bnussman-akamai requested a review from a team as a code owner September 25, 2023 15:46
@bnussman-akamai bnussman-akamai self-assigned this Sep 25, 2023
@bnussman-akamai bnussman-akamai requested review from cliu-akamai and cpathipa and removed request for a team September 25, 2023 15:46
Copy link
Contributor

@mjac0bs mjac0bs left a comment

Choose a reason for hiding this comment

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

🙌🏼 I tested this on various pages and with various refreshes and saw the MSW intercepting requests every time. When I walked through the DC pricing changes, there were no issues we saw earlier with the regions endpoint sometimes not being intercepted correctly and not returning the mocked region data from cached regions we would expect.

Thank you for fixing!

types is intercepted by the MSW:
Screenshot 2023-09-25 at 9 12 29 AM

regions is intercepted by the MSW and includes the expected cached region data:
Screenshot 2023-09-25 at 9 13 05 AM
Screenshot 2023-09-25 at 9 13 20 AM

@mjac0bs
Copy link
Contributor

mjac0bs commented Sep 25, 2023

Hmm. I'm looking back at this PR now because I wanted to make sure this fix was true for both localhost and the PR preview link. I am still seeing intermittent issues with the PR preview link. For example:

We're missing the expected id-cgk and br-gru regions here:
image

The request says it's from the MSW:
Screenshot 2023-09-25 at 12 05 30 PM

but the regions data is not returned:
Screenshot 2023-09-25 at 12 05 41 PM

@bnussman-akamai
Copy link
Member Author

@mjac0bs and I talked this over and we think that that it is expected behavior for the preview link to exclude cgk and gru because the CI pipeline overrides the cached regions on every build.

@abailly-akamai
Copy link
Contributor

Tested and looks good! thanks for the fix.

Confirmed locally ✅

And yes, can confirm the cache gets overridden. If you run a production build locally you'll get the same problem 👍

@bnussman-akamai bnussman-akamai merged commit 57e060b into linode:develop Sep 26, 2023
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.

4 participants