-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Lazy routes + SSR not working #820
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
Comments
Hi, thanks for filling this issue.
I'm not very familiar with react, would you mind posting a link to their docs/examples about this? Thanks! |
Can you test with the syntax provided on the docs: http://router.vuejs.org/en/advanced/lazy-loading.html? const Foo = resolve => require(['./Foo.vue'], resolve) |
There are some docs for code-splitting / dynamic routes (by dynamic they mean lazy). There is also a section that mentions async routes on the server that I think describes the issue I'm running into with vue-router:
I think that bundling in JS per vue route using
I've tested this syntax as well as |
I took a look at the docs you provided and it doesn't seem to be the case here.
I think if you can just solve this problem then everything will be fine. This means giving the server access to the chunked js bundle files (in this case |
It is. The docs have changed since I last looked at them, but I've been able to accomplish this in many projects in no time at all following a similar approach to this article: https://medium.com/react-weekly/code-chunking-with-webpack-a-pragmatic-approach-e17e8bcc6453#.f51ppe4ja (note: I've tried the
How, exactly? Shouldn't it be available on the server already? The only way I could think is to point to the |
This link doesn't talk about server side rendering either, everything is running on the client side. Since it's not about vue-router, I'm closing this issue, but feel free to continue discussion here. |
@fnlctrl the article you've linked to does not differ from the strategy I'm using - the use of const Foo = BROWSER_BUILD ? () => System.import('../views/Foo.vue') : require('../views/Foo.vue') Instead allowing you to just The Following that article's instructions on a React project, everything works as expected. I'm intrigued by your idea of making the chunk available to the server - but given that webpack is bundling the server as well, I'm confused as to why this isn't the case already 😕 Lazy loading chunks that work in SSR is a valid and known use-case - What can we do to make it a little more straightforward? If you can point me in the right direction, I'm happy to help out. EDIT: I have a lingering suspicion that this stems from the way the bundle renderer handles module dependencies in |
Hi @declandewet I actually have the same error as you and trying to figure this out too. |
Hi @atinux - Unfortunately I haven't found a solution, but I have found out a lot more info regarding the status of the issue - If you head over to https://github.com/vuejs/vue/projects/3, you'll see a card in the "Core" column that says:
According to the Github API endpoint for Vue's project cards, that card was added on October 17th. There is also this post on the forums: http://forum.vuejs.org/t/vue-ssr-how-to-support-lazy-loading/1647
This indicates that a combination of SSR + code splitting is not yet supported in Vue, but will, at some point, be worked on. In the meantime, here is a collection of my findings:
|
Ok you looked deep into it. I will try to find a way to do it, I'm actually working on a copy of next.js for vue. So I have to find a way of doing it while it's not implemented on Vue yet. I'll keep you informed of my progress! |
This next.js? |
Yes, I called it nuxt.js :) https://github.com/Atinux/nuxt.js 2016-10-29 15:42 GMT+02:00 Declan de Wet [email protected]:
|
Hi @declandewet I did it and it's working for vue-hackernews-2.0: https://github.com/Atinux/vue-hackernews-2.0-lazy Live demo: https://vue-hn-lazy.now.sh I'll let you check the code, if you have any question, I will be happy to answer them! |
@atinux this is awesome - great work! I think I understand the majority of what you've done here - if I have any questions I'll let you know. 😄 Thanks for your efforts. I think though that others might benefit from a Medium post - if you're interested in writing one? 😃 |
BTW, great job on vue-meta @declandewet |
Thanks @atinux - it's just a proof of concept right now, I'm sure there are tons of critical bugs - but |
EDIT: fixed it! nuxt/vue-meta@a6b0148 |
@declandewet I can't reproduce this issue, could you create an example so I can reproduce the issue on my side? |
@atinux it was just me being silly and referencing tag elements before they were loaded in the DOM, I fixed it some time ago. :) Back on topic, I think we should raise an issue regarding the functions you're borrowing from |
I agree, I answer on the issue about lazy loading in vue-hackernews-2.0, On Thursday, 3 November 2016, Declan de Wet [email protected]
|
|
Hi @wuchang1123 Do you have this config? atinux/vue-hackernews-2.0-lazy@0109436 If so, the c.0.js and c.1.js should not have any embedded CSS. |
@atinux Yes, I tried, but it is all the css are concentrated, I look forward to is the case |
Actually I found no other solution with Webpack 😞 I you find one I'd love to see it! |
@atinux,thanks again |
@atinux I tried your solution of separate css and it works, THANKS a lot |
Hey guys, I am experiencing a similar issue, SSR doesn't work with lazy-loaded components in vue-router. Rather than writing it all here, please check it in laravel-mix/laravel-mix#2245. @atinux can you please check this? 🙏 I'd be grateful for any help. |
I built off the HackerNews (Vue 2.0 SSR) example and modified the routes to be rendered out lazily:
src/router/index.js
When navigating directly to
/
, app loads fine. Clicking on the links to/foo
as well as/bar
works - the chunks for the respective routes are loaded in lazily as expected. But navigating directly to/foo
or/bar
to trigger a server render crashes the app with "module 0.server-bundle.js not found".I figured this might be my cue to prevent code splitting on the server, so I defined a constant via webpack in both client and server configs:
webpack.client.config.js
webpack.server.config.js
...Then modified the router file to look like this:
src/router/index.js
This worked. Server renders rendered the right UI components depending on the route, and renders on the client fetched lazy chunks as intended.
However, upon closer inspection, it seems that this little trick causes the HTML rendered by the server to mismatch the VNode tree created by the client - which prevents efficient hydration on the client, instead re-rendering the entire app, which is less than ideal 😛
I've tried to get help on Gitter as well as on the forum (http://forum.vuejs.org/t/2-0-help-needed-with-server-rendered-lazy-routes/906) but those avenues didn't get much attention.
Since this is trivial to do in React-land, I'm assuming this might be a bug.
The text was updated successfully, but these errors were encountered: