React lazy does not cause splitting bundle in chunks
up vote
1
down vote
favorite
As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.
Here's my implementation:
import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';
const AppItemComponent = React.lazy(() => import('../AppItem'));
class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;
getApps(3);
}
renderAppItem = () => {
const { apps } = this.props;
return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};
render() {
const { apps } = this.props;
return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}
const mapStateToProps = ({ apps }) => {
return { apps };
};
const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Apps);
I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.
What am I missing here?
reactjs lazy-loading
add a comment |
up vote
1
down vote
favorite
As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.
Here's my implementation:
import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';
const AppItemComponent = React.lazy(() => import('../AppItem'));
class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;
getApps(3);
}
renderAppItem = () => {
const { apps } = this.props;
return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};
render() {
const { apps } = this.props;
return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}
const mapStateToProps = ({ apps }) => {
return { apps };
};
const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Apps);
I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.
What am I missing here?
reactjs lazy-loading
1
Maybe you are importing it like e.g.import AppItem from '../../AppItem';
somewhere else in the code?
– Tholle
Nov 7 at 9:40
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
1
I don't see why that should happen from the code currently in your question, but let's say you imported a componentHome
in yourApps
file, andHome
importedAppItem
, then that would prevent it from being code split into a separate bundle.
– Tholle
Nov 7 at 9:49
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.
Here's my implementation:
import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';
const AppItemComponent = React.lazy(() => import('../AppItem'));
class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;
getApps(3);
}
renderAppItem = () => {
const { apps } = this.props;
return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};
render() {
const { apps } = this.props;
return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}
const mapStateToProps = ({ apps }) => {
return { apps };
};
const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Apps);
I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.
What am I missing here?
reactjs lazy-loading
As in the title, I'm trying to use React.lazy feature which works in my my other project. But not in this one, I don't know what I'm missing here. All works just fine, no errors, no warnings. But for some reason I don't see my bundle split in chunks.
Here's my implementation:
import React, { Component, Suspense } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { getApps } from '../../actions/apps';
import './_apps.scss';
const AppItemComponent = React.lazy(() => import('../AppItem'));
class Apps extends Component {
componentDidMount() {
const { getApps } = this.props;
getApps(3);
}
renderAppItem = () => {
const { apps } = this.props;
return apps && apps.map((item, i) => {
return (
<Suspense fallback={<div>loading...</div>} key={i}>
<AppItemComponent
index={i + 1}
item={item}
/>
</Suspense>
);
});
};
render() {
const { apps } = this.props;
return (
<div className="apps__section">
<div className="apps__container">
<div className="apps__header-bar">
<h3 className="apps__header-bar--title">Apps</h3>
<Link className="apps__header-bar--see-all link" to="/apps">{`see all (${apps.length})`}</Link>
</div>
{this.renderAppItem()}
</div>
</div>
);
}
}
const mapStateToProps = ({ apps }) => {
return { apps };
};
const mapDispatchToProps = dispatch => {
return {
getApps: quantity => dispatch(getApps(quantity)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Apps);
I'm doing this in react-create-app app and in react v16.6, react-dom v16.6.
What am I missing here?
reactjs lazy-loading
reactjs lazy-loading
edited Nov 7 at 9:30
Nguyễn Thanh Tú
4,480827
4,480827
asked Nov 7 at 9:25
Barth
256110
256110
1
Maybe you are importing it like e.g.import AppItem from '../../AppItem';
somewhere else in the code?
– Tholle
Nov 7 at 9:40
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
1
I don't see why that should happen from the code currently in your question, but let's say you imported a componentHome
in yourApps
file, andHome
importedAppItem
, then that would prevent it from being code split into a separate bundle.
– Tholle
Nov 7 at 9:49
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30
add a comment |
1
Maybe you are importing it like e.g.import AppItem from '../../AppItem';
somewhere else in the code?
– Tholle
Nov 7 at 9:40
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
1
I don't see why that should happen from the code currently in your question, but let's say you imported a componentHome
in yourApps
file, andHome
importedAppItem
, then that would prevent it from being code split into a separate bundle.
– Tholle
Nov 7 at 9:49
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30
1
1
Maybe you are importing it like e.g.
import AppItem from '../../AppItem';
somewhere else in the code?– Tholle
Nov 7 at 9:40
Maybe you are importing it like e.g.
import AppItem from '../../AppItem';
somewhere else in the code?– Tholle
Nov 7 at 9:40
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
1
1
I don't see why that should happen from the code currently in your question, but let's say you imported a component
Home
in your Apps
file, and Home
imported AppItem
, then that would prevent it from being code split into a separate bundle.– Tholle
Nov 7 at 9:49
I don't see why that should happen from the code currently in your question, but let's say you imported a component
Home
in your Apps
file, and Home
imported AppItem
, then that would prevent it from being code split into a separate bundle.– Tholle
Nov 7 at 9:49
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186595%2freact-lazy-does-not-cause-splitting-bundle-in-chunks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Maybe you are importing it like e.g.
import AppItem from '../../AppItem';
somewhere else in the code?– Tholle
Nov 7 at 9:40
Are you suggesting that if there is another place with regular (old way) import of the same component it'd prevent code to be split?
– Barth
Nov 7 at 9:46
1
I don't see why that should happen from the code currently in your question, but let's say you imported a component
Home
in yourApps
file, andHome
importedAppItem
, then that would prevent it from being code split into a separate bundle.– Tholle
Nov 7 at 9:49
You're right. It prevents from splitting. I see chunks now :) The only issue left now is that my main bundle file seems to have exactly the same size as before, ie. 550 kb (the other small chunk has 2.7kb but this is not deducted from the main bundle)
– Barth
Nov 7 at 10:30