Skip to content
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

Dynamic imports and SSR #46

Open
cbilotta opened this issue Apr 14, 2017 · 1 comment
Open

Dynamic imports and SSR #46

cbilotta opened this issue Apr 14, 2017 · 1 comment
Milestone

Comments

@cbilotta
Copy link
Member

cbilotta commented Apr 14, 2017

With the 1.5 Meteor update, we will be able to split code dynamically.
We can use react-loadable to load components on-demand.

However, how would we go about sending the needed , dynamically imported components on SSR ?

The server will synchronously import components and render the complete HTML correctly.

Once sent to the client, the javascript will mount, provoking a re-render. Since the client doesn't have the components that were loaded synchronously by the server, it will fall into the "component is not loaded" case and display the loading indicator for the component, after the user has already seen this component properly rendered.

How can we avoid this ? I guess the solution is obviously to simply put the required modules for the page in the head, but how do we go about doing that ?

Do we have a way to serve the compiled modules via webhooks ?

Maybe MDG already though of this, but I couldn't find any information, except this interesting conversation with Ben : https://medium.com/@faceyspacey/u-shouldnt-see-loading-briefly-3289d1b3d4ce

In the meantime, we can probably apply the mecanism from #47 to solve this issue.

We would basically prevent re-rendering of the component that needs a dynamically imported module until meteor has properly fetched this module.

Also see : https://github.com/thejameskyle/react-loadable/blob/master/README.md#flushserversiderequirepaths--flushwebpackrequireweakids

However, this would need to be implemented by Meteor itself (at least a hook or something) and I have no idea if that is done, or is planned.

@cbilotta cbilotta added this to the 4.0.0 milestone Apr 14, 2017
@cbilotta cbilotta changed the title Dynamic imports on SSR Dynamic imports and SSR Apr 14, 2017
@sirpy
Copy link

sirpy commented Oct 30, 2017

loadable has a Loadable.Capture that can collect the dynamically imported components.
then it's a matter of calling the correct meteor methods to include those imports.
see discussion here
meteor/meteor-feature-requests#151

there's another solution at the end but i didnt figure out how it works and if it's truly ssr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants