-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
Equivalent to preloadAll #207
Comments
Hello @heygrady, const Loadable = loadable(({ page }) => import(`./${page}`)) Import function is not static, it depends of the context, for a different route you can have a different bundle loaded. This is why the function cannot be implemented in Loadable Components. I hope it answers your question! |
I believe that "impossible" is an overstatement. React-loadable is able to do it and I am using it in production and it is working. I described part of their technique for accomplishing preloading. Even loadable-components offers a Your point is that you may not quite know when the app will encounter an
One issue would be a loadable that is only encountered inside the I will be revisiting this at some point in the near future and I may be able to provide more details. I haven't looked into the code behind loadable-components enough to know how hard this would be to implement. |
React Loadable does not support aggressive dynamic import, this is why it can do it. We have to traverse the React tree to know what to do, and the only efficient way to do it is to call a I understand your point, but I don't want to create a |
I also need a edit: I use esm for node. |
I don't need a Loadable.preload = function (props) {
if (typeof window === 'undefined') {
if (typeof ctor.requireSync === 'function') {
return ctor.requireSync(props)
}
throw new Error('`preload` cannot be called server-side')
}
return ctor.requireAsync(props)
}; The dynamic naming works with Node, with Webpack it's confusing at the time of the build but Node has everything to make a require that works at the time of the execution. This code works perfectly with my modification if the const App = loadable( () => import( `./containers/App.${part}` ) ); And it will work for full-dynamic as well. |
I was upgrading our existing app from
react-loadable
to@loadable/components
. In my previous server-side configuration I was relying onpreloadAll
from react-loadable to initialize all of the loadable components before starting my app.Looking at the server-side example for loadable-compoents you are doing something similar in
nodeExtractor.requireEntrypoint()
.My problem: My app is set up slightly differently than the example and using
requireEntrypoint
would mean a significant refactor.Why? Long ago we made the decision to build the entire express server using webpack/babel. In the example you build the react app twice with the exact same entrypoint and build the express server separately. That's an interesting approach but it's not the only approach.
Why
preloadAll
? You have recognized this issue on the client and provided a dedicatedloadableReady
function. On the server it would be nice to be able to resolve all loadables prior to running the app. UsingrequireEntrypoint
only works if you're initializing a separately built app. Something likepreloadAll
allows you to initialize the app from within the bundle itself.preloadAll
is pretty clever. It works by keeping an internal reference for every loadable. It would be like adding to an array every timeloadable
is called. It then loops through those references recursively whenpreloadAll
is called. Because it resolves each loadable recursively it's able to initialize the entire tree without the need to have a separate stats file for the server build.In a server-side context the penalty is a brief pause while the server is initializing. Having something like
preloadAll
available would make it far easier to integrate loadable-components into a project that had been successfully running react-loadable 5.Chicken and egg: There are some interesting issues with the way
preloadAll
works if you don't use node-externals in your server bundle. In the past I had designed apps to work more similarly to the server-side example and had issues withpreloadAll
. Something likerequireEntrypoint
would've made my life easier. However, I was able to solve the issue by re-exportingpreloadAll
from my entrypoint to ensure that it was referencing the version of react-loadable in the bundle. That way my server was able to importApp
andpreloadAll
to initialize the bundle before using it.Example:
The text was updated successfully, but these errors were encountered: