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

wpcom-proxy-request: Return Promise if no callback specified #39683

Merged
merged 13 commits into from
Feb 27, 2020

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Feb 25, 2020

Changes proposed in this Pull Request

The promise wrapper introduced by @andrewserong et al. in #38823 seems generic enough for it to make sense to have it in wpcom-proxy-request. This PR moves it there. This follows precedent set by wpcom.js.

Note that this is a technically a breaking change, as noted in the package's History.md:

  • [...] Return Promise (rather than XMLHttpRequest instance) if no callback argument is provided.
    • In practice, most people have probably been using the callback rather than the returned XMLHttpRequest instance, so this shouldn't be a breaking change for most.

Testing instructions

Verify that Gutenboarding still works (esp account and site creation).

@matticbot
Copy link
Contributor

@ockham ockham force-pushed the add/wpcom-proxy-request-promise-return branch from dddfd73 to 93e07ed Compare February 25, 2020 18:29
@ockham ockham added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Feb 25, 2020
@ockham ockham requested review from noahtallen, sirreal and a team February 25, 2020 18:40
@ockham ockham marked this pull request as ready for review February 25, 2020 18:40
@ockham ockham requested a review from a team as a code owner February 25, 2020 18:40
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

More notes and thoughts than you wanted on this smallish PR 🙂

I'm particularly concerned about sideEffects - that likely breaks some functionality completely.

@sirreal sirreal requested review from sgomes and a team February 26, 2020 11:24
@ockham ockham force-pushed the add/wpcom-proxy-request-promise-return branch from 3945ba4 to 989506c Compare February 26, 2020 16:49
@ockham
Copy link
Contributor Author

ockham commented Feb 26, 2020

Thanks a lot for reviewing, Jon!

Addressed all feedback, should be ready for another look!

@ockham ockham requested a review from sirreal February 26, 2020 17:05
Copy link
Member

@p-jackson p-jackson left a comment

Choose a reason for hiding this comment

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

LGTM @ockham I just have a question about the calls to requestAllBlogsAccess() added in 989506c. Are they just there for testing purposes?

Doesn't seem related to this PR, but this call is needed for the stores to work properly perhaps we need a way of coordinating the calls so we don't create a network storm during app boot.

@ockham
Copy link
Contributor Author

ockham commented Feb 27, 2020

LGTM @ockham I just have a question about the calls to requestAllBlogsAccess() added in 989506c. Are they just there for testing purposes?

No, this was supposed to stay as-is. That's the call that was previously run at module level in packages/data-stores/src/utils/wpcom-wrapper.ts.

Doesn't seem related to this PR, but this call is needed for the stores to work properly perhaps we need a way of coordinating the calls so we don't create a network storm during app boot.

Is there a high risk for that? requestAllBlogsAccess() is now called from both the user and the site stores' createControls() function, which AFAICT should each be invoked only once -- in the register() function of each of these stores (site, user).

@ockham ockham mentioned this pull request Feb 27, 2020
1 task
@sirreal sirreal added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 27, 2020
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

Looks good, I don't see any regressions. Thanks!

@@ -64,6 +64,3 @@ cached-requests.json
/apps/*/dist/
/apps/*/types/
/packages/*/dist/
# Redundant after https://github.com/Automattic/wp-calypso/pull/39173
# Safe to remove after some time has passed
/packages/*/types/
Copy link
Member

Choose a reason for hiding this comment

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

👍 thanks!

Comment on lines +13 to +15
requestAllBlogsAccess().catch( () => {
throw new Error( 'Could not get all blog access.' );
} );
Copy link
Member

Choose a reason for hiding this comment

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

It's worth noting that this is async, so we'll synchronously return the controls below, but may asynchronously error.

That seems alright to keep the happy path simple and failing fast.

@ockham ockham merged commit 3a001be into master Feb 27, 2020
@ockham ockham deleted the add/wpcom-proxy-request-promise-return branch February 27, 2020 08:27
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 27, 2020
ockham added a commit that referenced this pull request Feb 27, 2020
ockham added a commit that referenced this pull request Feb 27, 2020
ockham added a commit that referenced this pull request Feb 27, 2020
@p-jackson
Copy link
Member

That's the call that was previously run at module level

🤦‍♂ ah so it was

Is there a high risk for that? requestAllBlogsAccess() is now called from both the user and the site stores' createControls() function, which AFAICT should each be invoked only once -- in the register() function of each of these stores (site, user).

I shouldn't have said "network storm", that was the wrong term. Calling requestAllBlogsAccess() once per store is what I'm worried about. There's only two stores now, but what about when there are 5 stores, or 10 stores. An app that registers them all will fire 10 identical requests to the same endpoint on boot.

@matticbot
Copy link
Contributor

matticbot commented Feb 28, 2020

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~327 bytes added 📈 [gzipped])

name                   parsed_size           gzip_size
entry-main                  +235 B  (+0.0%)      +88 B  (+0.0%)
entry-login                 +235 B  (+0.0%)      +84 B  (+0.0%)
entry-jetpack-cloud         +235 B  (+0.0%)      +93 B  (+0.0%)
entry-domains-landing       +235 B  (+0.0%)      +72 B  (+0.0%)
entry-gutenboarding         +165 B  (+0.0%)      -10 B  (-0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants