Comments (9)
@neoziro I've got it working with a fork, this is enough: https://github.com/dgieselaar/loadable-components/blob/65ee245f1166a8ed0ab46760821748ce93cba79e/src/loadable.js#L116. Does it make sense?
from loadable-components.
@dgieselaar thanks for this! It looks great!
from loadable-components.
This is not possible at this time. To do it we need to couple it with Webpack. I will probably do it soon.
from loadable-components.
This is necessary if you are splitting your CSS, otherwise there will be FOUC. The <link>
tag needs to be included in the server html.
from loadable-components.
+1. This feature would be VERY useful to have.
from loadable-components.
I've started thinking about moving from react-loadable to loadable-components today and I really enjoy the async rendering loadable-components provide! However, not being able to prefetch the chunks seems like a deal breaker for me. Is there any reason why you are unwilling to couple to webpack? Since loadable-components already maps the necessary modules (e.g. window.__LOADABLE_STATE__ = {"children":[{"id":"./home.page.js"}]};
) it seems like a small step to know which bundles are necessary,
from loadable-components.
@ricardobrandao it is more complicated than it looks like. Actually it is just an idea and not the real name of the chunk. We need access to webpack stats in order to know which will be the final file. But I am thinking about a rewriting / simplification of Loadable Components with preload support.
from loadable-components.
FYI, here's a (gross) snippet that is working w/ my fork (use/edit at your own peril):
import fs from 'fs';
import {
uniq,
flattenDeep,
pickBy,
} from 'lodash';
import getRenderedComponents from './getRenderedComponents';
const records = fs.readFileSync('records.json'); // from webpack's recordsOutputPath
const components = getRenderedComponents();
const chunks = uniq(flattenDeep(
components.map((component) => {
return component.modules.map((m) => {
if (!records.chunks) {
return [];
}
const chunkIds = values(pickBy(records.chunks.bySource, (value, key) => key.endsWith(` ${m}`)));
const chunkNames =
Object.keys(pickBy(records.chunks.byName, value => chunkIds.includes(value)));
return chunkNames;
});
})
)).filter(identity);
I get the components I need to load from the route definition (I have a top-down route configuration), but once you have that, you can use this to get the assets from Webpack. Again, gross, and only works with my fork (which I would not recommend using in production unless you're me).
from loadable-components.
Loadable Components v3 has been released 🎉, and it supports <link rel="preload">
!
👉 https://github.com/smooth-code/loadable-components
from loadable-components.
Related Issues (20)
- problem with redial HOT 2
- How to change referencing external styles to preload mode
- Fallback running even when component has previously loaded HOT 1
- Webpack doesn't like @loadable/server 5.16.4 HOT 5
- Server is caching old request split chunks, and these are not being re-requested when a new request is made to the server.
- ctor.requireAsync is not a function error HOT 1
- Race condition
- Support the chunkName method
- Can use this package for React Native?
- Fallback behaviour HOT 1
- Main.js is rendered on every page even if I splitted each page into chunks with @loadable/component
- error in ./node_modules/@loadable/component/dist/loadable.esm.mjs HOT 9
- Why ChunkExtractor is required? HOT 3
- Is website sync with repo?
- If I am using react18, do I still need loadable-components HOT 6
- Add esbuild support HOT 3
- react-native-web SSR support HOT 1
- Loading state is always true on first render HOT 3
- Add query parameter support HOT 3
- SSR is broken for component v5.16.2+ HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loadable-components.