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

Ability to hydrate all pages without getServerSideProps and connect. #27

Closed
lukasfri opened this issue Dec 27, 2021 · 4 comments
Closed

Comments

@lukasfri
Copy link

I opened this in the next-redux-wrapper issues but it might be more appropriate here. I use Redux for saving my current theme I use in Material UI. They use a wrapper that provides the theme and as such I have a component that uses a selector to get the current theme and apply it. The issue is that I need to hydrate all pages for it to work meaning I have to create lots of empty getServerSIdeProps functions and connect pages which leads to alot of boilerplate. I would like the ability to turn on hydration for all pages regardless of if it is connected or not.

@bjoluc
Copy link
Owner

bjoluc commented Dec 27, 2021

Hi @DreamplaySE,

that's exactly what #22 is about – I addressed #22 by always dispatching a HYDRATE action on the initial client-side page load, accepting duplicate HYDRATE actions on pages with data loading functions. In other words, this should work with version 2.1.2.

On the server, next-redux-cookie-wrapper only dispatches a HYDRATE action if client cookies are actually available, so on static pages (= without getServerSideProps), your server-rendered markup has no chance to respect a client-specific theme. If you want this, @kirill-konshin's suggestion is the way to go – although/because it disables automatic static optimization.

Cheers!

@bjoluc bjoluc closed this as completed Dec 27, 2021
@lukasfri
Copy link
Author

lukasfri commented Dec 27, 2021

Sorry I should've been more clear! I read thru that issue but basically my hope was for some future feature to simply the boilerplate by maybe providing a wrapper of some kind that automatically provides it all through the _app file. Since you need to default export the page and you can't provide getServerSideProps as a property of the page it means that there's no way to easily make a one-line function that both connects and enables server-side rendering. My question was if there's any way you could create a feature that enables this via a config or some kind of special function of the wrapper that also specifies to NextJS that you're server-side rendering with cookies.

@bjoluc
Copy link
Owner

bjoluc commented Dec 29, 2021

by maybe providing a wrapper of some kind that automatically provides it all through the _app file

I believe what you are looking for is adding getInitialProps to your _app file, as suggested in the next-redux-wrapper issue. All your pages will be server-rendered on each request then, no matter if they have getServerSideProps or not.

@lukasfri
Copy link
Author

lukasfri commented Dec 29, 2021 via email

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