-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Load middleware async #40913
Load middleware async #40913
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime (~238 bytes added 📈 [gzipped])
Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded. App Entrypoints (~13098 bytes removed 📉 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~32993 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~39491 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. 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. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻Overall, I like the approach.
However, this particular case is making the separate lazyLoadDependencies
export feel a bit awkward to me. Notice how the section's default
export is essentially a no-op when config.isEnabled( 'reader' )
is falsy. We don't do the same check in lazyLoadDependencies
, so we could theoretically get Lasagna middleware but no Reader routes.
Rather than invoking lazyLoadDependencies
in sections-middleware, what if we kept the contract to just the default export? With this being the only section using this opportunity to load dependencies (as far as I'm aware, anyway), we can perhaps just leave it up to the section itself to clearly delineate between route registration and dependency loading in its default exported function.
Not all routes fall under the feature flag check, if reader is not enabled it will fallback to wp-calypso/client/reader/index.js Line 105 in b9357d1
I added it to the section middleware to make sure it is loaded before a section is activated as some of our code will open a websocket based on |
I'll try to add the lazy loading to the default export to see if I encounter any |
Feedback addressed, ready for re-review, thank you very much for taking the time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢Looks great! Thanks for stepping in and getting this added so quickly.
3a8a05c
to
cf02a42
Compare
e82f316
to
399cf94
Compare
Hey folks! Any updates on this PR? Do you need any help getting this to work post- |
👋 I'll try to rebase and merge this today, I got a bit sidetracked, thanks for the headsup. |
No worries, thank you! Let me know if you need a hand! 👍 |
To come in follow up PR
399cf94
to
56b8f22
Compare
Changes proposed in this Pull Request
We are adding redux-dyamic-middlewares package, which would allow us to have a very light "placeholder" like middleware which can be used to add/remove middlewares based on our needs, in this case we would want to only load the lasagna middleware if the reader section is loaded.
More context #40396
Testing instructions
localStorage.debug="lasagna:*"
Fixes https://github.com/Automattic/wp-for-teams/issues/90