-
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
Framework: Introduce AsyncLoad for asynchronous rendering by code splitting #5356
Conversation
import React, { Component, PropTypes } from 'react'; | ||
import omit from 'lodash/omit'; | ||
|
||
export default class CodeSplitRender extends Component { |
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.
I was thinking of <AsyncLoad>
perhaps?
Nice to see this. |
0058020
to
d831f23
Compare
5cfcf82
to
4a36949
Compare
@@ -326,7 +327,10 @@ const EditorDrawer = React.createClass( { | |||
{ site && ! this.hasHardCodedPostTypeSupports( type ) && ( | |||
<QueryPostTypes siteId={ site.ID } /> | |||
) } | |||
{ this.renderTaxonomies() } | |||
{ config.isEnabled( 'manage/custom-post-types' ) && ! includes( [ 'post', 'page' ], this.props.type ) |
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.
Tab in here. In fact, I think we should drop the ! includes
part of the condition altogether, but fine to leave that as a separate task if you'd prefer.
Edit: As in, this.renderTaxonomies
should be called for any post type (including post and pages), but renderCategoriesAndTags
called for post and page only (above renderTaxonomies
I assume)
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.
Makes sense, I haven't moved taxonomies to be async-loaded because it was causing issues. Leaving that up to your or @timmyc's discretion :)
The |
I think we'd need a separate loader. Are you thinking it'd just do something simple like check for |
Yeah, and we'd need a fallback mechanism for when code splitting is disabled. |
Sorry, missed the ping. I'll echo the opinion that a separate loader should do it. This could be an opportunity to resume some cleanup work on loaders (#2028) that I had to set aside in the past. |
A working example with
|
Offline, we were discussing how we could achieve this with improved usability and to avoid AMD syntax using a Babel plugin. Here's a gist to the work in progress: https://gist.github.com/aduth/e4d2eaf11e04b56077d0ac229e44d7d8 Desired usage is similar to as demonstrated in #6660 , effectively transforming: <AsyncLoad
require="./sharing"
ensure={ this.state.shouldLoad }
placeholder={ <Spinner /> } /> Into: <AsyncLoad
require={ ( callback ) => {
require.ensure( './sharing', () => {
callback( require( './sharing' ) );
} );
} }
ensure={ this.state.shouldLoad }
placeholder={ <Spinner /> } /> Optionally depending on the value of the The implementation of |
Superseded by #8544 |
Prompted by discussion for more granular code splitting, this pull request seeks to try an approach for rendering components with dependencies loaded on-demand by introducing new a component which facilitates rendering via asynchronous
require
.This pull request is a proof-of-concept and should not be merged as-is. The loading experience could be improved to load the contents of the accordion asynchronously by user intent (e.g. hover accordion heading), not whenever the page is loaded. Further, in the case that the bundle is not loaded yet when the user tries to access its content, we should display some placeholder.
Note in the screenshot above that the
post-editor
chunk has decreased from 3.47MB to 3.36MB, a difference of 0.11MB (110kB).Testing instructions:
Note that the sharing accordion still renders correctly when visiting the post editor.
/cc @mtias