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

fetchData and server-side rendering #134

Closed
gbezyuk opened this issue Aug 21, 2015 · 8 comments
Closed

fetchData and server-side rendering #134

gbezyuk opened this issue Aug 21, 2015 · 8 comments

Comments

@gbezyuk
Copy link

gbezyuk commented Aug 21, 2015

Basing on provided setup, I created two nested routes and components: App and Page. Both of them have fetchData method producing promises for dispatched LOAD actions for API calls. There are three actions: two in App, one in Page component. First two does not require any information from router, the last one depends on a page_slug provided. And, in general, everything works just fine.

But, surprisingly, only first two API calls are being made on server side. The last one works only when the page is loaded into browser: thus, no server-side rendering occurs. I tried to move all three actions into single App component's fetchData method, and it did not help.

I would really appreciate any help on this issue.

Full project is located at https://github.com/gbezyuk/django-react-redux-universal-hot-example

@erikras
Copy link
Owner

erikras commented Aug 21, 2015

And you're certain that arePagesLoaded(store.getState()) and areCategoriesLoaded(store.getState())) are both returning false? i.e. there are two promises in the array passed to Promise.all()?

@erikras
Copy link
Owner

erikras commented Aug 21, 2015

I'd also put a console.log(routerParams.page_slug) in Page.js.

@gbezyuk
Copy link
Author

gbezyuk commented Aug 21, 2015

arePagesLoaded and areCategoriesLoaded both return false, and the slug is correct. The troublesome one is loadPage, not the general methods.

@erikras
Copy link
Owner

erikras commented Aug 21, 2015

I'm guessing it's pages.js:17.

promise: (client) => client.get(`/pages/${slug}.json`)

should be

promise: (client) => client.get(`/api/pages/${slug}.json`)

categories.js has the same problem.

@erikras
Copy link
Owner

erikras commented Aug 21, 2015

No, nevermind. None of them should have /api.

@erikras
Copy link
Owner

erikras commented Aug 21, 2015

Because ApiClient adds that only in the browser.

@gbezyuk
Copy link
Author

gbezyuk commented Aug 21, 2015

Actually, after adding /api/ it worked! Looks like it failed while rendered on server. Thanks for the idea and for your attention to the issue in general!

@gbezyuk gbezyuk closed this as completed Aug 21, 2015
@erikras
Copy link
Owner

erikras commented Aug 21, 2015

👍

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

No branches or pull requests

2 participants