-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Add support of getStaticProps and getServerSideProps #194
Conversation
e2ed1f5
to
1ff21f3
Compare
@jwkellyiii @jeroenburgers @bsimpson888 @th0th @Poky85 @bjoluc colleagues, since you expressed interest in I've upgraded the way how components and functions are wrapped, and how initial state is delivered. I am planning to release this soon, so if you have any feedback, please share. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor fixes to the README for clarity
1ff21f3
to
57abcde
Compare
@jwkellyiii great job, thank you for review. All fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little busy right now, so here are some Readme-only comments from me as well.
ba1a7ce
to
1204602
Compare
@bjoluc thank you for feedback, everything is fixed now. @jwkellyiii @jeroenburgers @bsimpson888 @th0th @Poky85 @bjoluc let me do some user testing :) do you find new interface comfortable? Does it makes sense to you? |
It does make sense, on the surface. I am going to pull the branch into a project and get a feel for it. |
@jwkellyiii thank you, it will be great. I think for now (if there would be no more suggestions) I'll merge to master and make a canary release. |
Remember last time before the v5 release when there were issues and PRs of people using the new Readme from master with the old package version? Maybe merging this into a canary branch first would reduce confusion. |
Regarding the interface question: While I would really like to hide the complexity from users, I don't really think we can. But we could export a selection of common hydration reducers similar to what redux-persist does with state reconcilers. |
@bjoluc agree about dev branch. Yep, I was also thinking about either a reducer or a middleware. Redux persist works a bit differently though, hydration happens only once, whereas in Next.js every time when user opens a page with It works like this:
|
@kirill-konshin Thanks for the example! My bad, I didn't think about reducer implementations in detail. I can't think of any default behavior other than replacing the client-side state entirely, which is a one-liner anyway. Apart from that, I had a very promising idea: What if we compute a state diff (from the server's initial state) at the end of getServerSideProps and getStaticProps and merge that into the client state via a reducer? That would allow us to update only the server-touched fields of the state by default and leave the rest of the client's state in place. The "merging in what the server touched" approach could be a reasonable default reducer implementation that many users may not need to change! Obviously, the counter example problem remains. The great thing about the diff approach, however: In combination with a tool like redux-cookies-middleware, the |
@bjoluc I'd say, this is a problem for another library ))) state reconciliation may be veeeery tricky. In the doc I ended up just recommending not to update same state tree roots both on client and server. Let server update it's own roots and client can update it's own. Then all server state can be simply merged into existing one. Same way we can introduce a concept of server-only safe roots which can be blindly updated, but again, this is not the main purpose of this lib, so maybe we can find something already available and integrate it. |
@kirill-konshin I am a little worried that a strict state separation would compromise the isomorphy of redux-connected components. Plus, I don't feel very comfortable with letting users adopt their state hierarchy to start using the new features (arguably, they don't have to if they take the effort of writing a complex custom reducer). But you are definitely right that there is not one solution to rule them all, and helping users with this does not have to be within the scope of this library. Nevermind, I think you did a great job on the new interface! Users of the new functions will simply have to face the complexity. Something already available: jsondiffpatch. Users could integrate that themselves if they want to (custom serialization method and hydration reducer). |
@kirill-konshin Another question: What's the motivation behind letting users wrap each page component with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, some more little things.
@kirill-konshin thank you for all the great work! This all looks great, I will try spool this up to test tomorrow. I think the persistence and hydration processes will be relatively simple to leave to other packages or simply baked into apps as a hook that pulls a whitelisted set of keys from session or localstorage when available and hydrate. I already do that for a couple of auth0 ping / pong redirect flows in apps. Thanks again for all your hard work, and I look forward to this release :) |
The reason to make it explicit was 1) to skip dependency on But you've raised a right question. If
I will add a mention of this lib.
I tend to agree. If there will be demand to change it — I'll change it. |
1204602
to
f8df8b2
Compare
@bjoluc |
I didn't want to say anything, but there is a whole team of devs in my company waiting for this new version and thank you very much in advance @kirill-konshin |
I will make a usable NPM canary release today. Thank you all for feedback. |
f8df8b2
to
2d21610
Compare
Merged to dev. Created a follow up PR to master: #196. Published https://github.com/kirill-konshin/next-redux-wrapper/releases/tag/6.0.0-rc.1 |
@kirill-konshin it appears that commit 1204602 didn't make it to 6.0.0-rc.1. Any reason why? |
I messed up Travis config and it published it twice ) second failed obviously |
Fix #192 #173