-
-
Notifications
You must be signed in to change notification settings - Fork 265
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 #196
Conversation
When are you going to publish this? |
@dpyzo0o it has been published as 6.0.0-rc.1, you can give it a shot |
thx |
The API has changed - this is a major release. Please have a look in the upgrade section and demos. You will have to do some refactoring. |
@kirill-konshin I am confused on something. In the README, under "Upgrade from 5.x to 6.x" you say "App should no longer wrap it's children with Provider". However, in this commit (1204602) you do exactly that in the Also, when I do have my App wrap its children with a Provider I get "TypeError: Cannot read property 'getState' of undefined", take out the Provider and the error goes away. |
@jwkellyiii it just lost in numerous rebases and fixes. It's all good now as you can see in |
Hi @kirill-konshin. I'm a little bit confused. So in my project, I use custom |
@kirill-konshin so this is the right version: https://github.com/kirill-konshin/next-redux-wrapper/blob/dev/packages/demo/src/pages/_app.tsx Meaning, don't wrap your App children in a |
@jwkellyiii you don't need to wrap with @chermie |
@chermie moreover, I found this issue vercel/next.js#11648 — when you have I fixed the order and released |
Really looking forward to testing this, it will have huge improvements on performance with the SSG support. Thanks for the quick turn around on this! |
@zlwaterfield please let me know if it works as expected. I don't have enough time now to test all possible cases, so if you can give it a shot and provide some feedback, that would be great. |
@kirill-konshin I just want to make a note that using redux-saga is not as easy as mentioned here (https://github.com/kirill-konshin/next-redux-wrapper#usage-with-redux-saga) if you use getServerSideProps. |
@kirill-konshin are you going to push rc.2 to npm? |
Deps upgrade and fix for props order
https://www.npmjs.com/package/next-redux-wrapper/v/6.0.0-rc.2 ( |
Can you tell me more, I'm not familiar with sagas, what is the problem? |
@kirill-konshin it is all async requests and getServerSideProps that are the issue. I'll give more details when I can, but it is more then sagas that are the problem (same thing with redux-thunk, etc.). |
@jwkellyiii same as before you just need to await for all asynchronous actions to finish. Nothing changed in this aspect. |
@jwkellyiii I couldn't get sagas to work either. It doesn't seem to wait for the async actions to resolve and as the result no data lands in the store, it was working fine before I upgraded to rc1 |
@chermie @jwkellyiii here you go, proper Saga example: https://github.com/kirill-konshin/next-redux-wrapper/tree/dev#usage-with-redux-saga |
69ffdce
to
3d12207
Compare
- Redux Saga example - Proper support of `getStaticProps` and `getServerSideProps` - Removed `isServer` - Better tests
Thanks @kirill-konshin it works now, on the demo and on my own app. It was the only problem I found, so thank you very much! 👍 |
@kirill-konshin Hmm, after updating to
It only appears once per new page that I'm navigating to. The warning does not appear if I navigate away and back to that particular page. FYI, all of the pages have their own |
@phuson I've seen this warning and it was supposed to go away because of this special treatment: https://github.com/kirill-konshin/next-redux-wrapper/blob/dev/packages/wrapper/src/index.tsx#L180-L190 Can you check how your pages are mounted? Is there any special treatment? If you can rearrange the demos to show this behavior I'd appreciate it. |
@kirill-konshin I am running into two issues and I think they are related. First: I am seeing the hydration with an empty payload:
It seems to only happen on pages where I do not have Right now the hydration fails unless I add a check like this:
Second: I wrapped my page in an HOC and I am trying to hoist
But hoisting
Any ideas here? I realize I must be doing something wrong with how I am hoisting it. |
@zlwaterfield you need to hoist so-called "non-react statics" yourself if you use any HOCs on top of Wrapper. Here's the package: https://github.com/mridgway/hoist-non-react-statics. @phuson any chance to get a reproducible case for your warning issue? It works for me so far... |
@kirill-konshin I got it working, thanks for the link. One question, why does payload return Currently, my workaround is, as mentioned above, to only HYDRATE the payload if it exists:
The reason I need this is that my HOC that wraps every page is using the wrapper, most pages call one of the static next methods but a few pages don't. This HOC has auth checks and some layout related items, so it would be a pain to split it into two HOCs where some pages use both and some pages use only one. |
const hydrate = useCallback(() => {
store.current.dispatch({
type: HYDRATE,
payload: getDeserializedState(initialState, config),
} as any);
// ATTENTION! This code assumes that Page's getServerSideProps is executed after App.getInitialProps
// so we dispatch in this order
if (initialStateFromGSPorGSSR)
store.current.dispatch({
type: HYDRATE,
payload: getDeserializedState(initialStateFromGSPorGSSR, config),
} as any);
}, [initialStateFromGSPorGSSR, initialState]); As you see it just uses initial state, which is empty, because wrapper provides it, so no wrapper no state. |
Ok thanks, I can stick with my workaround for now. |
So looks like everything is fairly stable now, I'm not seeing any major issues. If this is right, I am going to promote this stuff to a major release. One thing that's left is @phuson's case, but like I said, code has been reworked to work around this particular issue. Can you please provide a reproducible case or confirm that it is now fixed? |
I've had this running with >50 routes on our staging env for a few days now and everything is looking good to us! |
@kirill-konshin Sorry for the late response. I got caught up in another project and couldn't return to this until now. Last time I was testing it, as I recollect, it seems like the conversion from the the class based component implementation (r.6) to the new functional component with hooks (r.8) caused the warning to be thrown in the console log. I spent some times debugging but couldn't figure out exactly why the warning was thrown. Before I was pulled away from this project, I had postulated that it could be that some functionalities were acting differently with the conversion (hooks vs lifecycle functions). Fast forward to today, I'm trying to get back into the project and I am no longer seeing the warning. So for now, please disregard my issue above. I will continue to test it further and will let you know if the issue comes up again. Thanks again for working on this! |
@phuson old version indeed might had this issue. Thank you for confirming. |
* Typo in README - `)` instead of `}` * Comma shouldn't be there either
# Conflicts: # README.md
Thanks to everyone in this thread, you guys helped tremendously to shape and test the new feature. It is now released as next major version: 6.0.0. |
@zlwaterfield Would you mind sharing an example of how you were able to successfully implement an HOC with getServerSideProps? The library that was linked appears to hoist static functions of the wrapped component to the wrapper. What confuses me about how you got this to work is that the Next docs explicitly state |
You need to |
I understand that, but since getServerSideProps is an exported function of a component and not a static function how is it possible to hoist getServerSideProps? I only ask because his question was about how he could hoist getServerSideProps and then he said he got it working. |
What do you mean "to hoist"? It is not hoisted, Nextjs automatically imports this function from the page. |
@tkstang, as @kirill-konshin mentioned you can export the function directly from the page since it is not static, you don't need to hoist it. Here is a slimmed-down page where
|
I see. I misunderstood and thought you had determined a way to export a getServerSideProps function from your core page wrapper HOC that allowed you to have some serverSideProps logic shared between all of your pages. |
Ya sorry, my explanation wasn't great, I was still trying to understand how it all works. Also, I wouldn't recommend having |
Fix #192 #173
Mention #194