facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.56k stars 26.8k forks source link

Lazy loading of CSS modules can break when importing sub module #5987

Closed penx closed 5 years ago

penx commented 5 years ago

Thanks for the support for Lazy Loading and CSS Modules. Would also be great if they could work together.

As far as I can tell, CSS modules that are imported by modules that loaded via import()/React.lazy are appended to CSS files that are loaded immediately rather than alongside the associated JS bundle.

I have something in progress here:

https://github.com/penx/govuk-frontend-react-example

When running a production build, all of the CSS is loaded on page load, even though some of it is only needed by the lazy loaded components.

penx commented 5 years ago

Closing for now as this appears to work in some cases:

https://github.com/penx/cra-lazy-css

penx commented 5 years ago

This is the actual issue that is occurring, raised as a bug:

https://github.com/facebook/create-react-app/issues/5989