gregberge / loadable-components

The recommended Code Splitting library for React ✂️✨
https://loadable-components.com
MIT License
7.58k stars 376 forks source link

Why ChunkExtractor is required? #992

Open vadim-ch opened 5 months ago

vadim-ch commented 5 months ago

Hi there! createLoadable function includes a condition that checks props.__chunkExtractor https://github.com/gregberge/loadable-components/blob/main/packages/component/src/createLoadable.js#L149 What if i don't want to use ChunkExtractor at all? To be more correctly, i can't add ChunkExtractor, because i use ReactJs.NET on my server.

theKashey commented 5 months ago

Without chunk extractor active Loadable will not be able to properly hydrate App as it will not know which chunks are required to be loaded first.

I am not sure how exactly ReactJs.NET works and why you cannot use ChunkExtractor and it's more about webpack rather than platform, but if you still can use Babel try a sibling solution - https://github.com/theKashey/react-imported-component, which does not use anything except Babel

vadim-ch commented 5 months ago

As far as I understand, ChunkExtractor is executed during request processing in node.js. It receives loadableStats.json as chunks information. And then a ChunkExtractor instance is passed to the client components using React Context. So. In this case, the source of truth is loadableStats.json and i can make required scripts by myself based on loadableStats.json. It seems to me that ChunkExtractor is only a helper to create script tags. Am i wrong?

theKashey commented 5 months ago

Correct, it's only a bearer of mapping between import and chunk. This information is generated by a webpack plugin, but can be generated in any other way.