-
-
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
Hydration fix #523
Hydration fix #523
Conversation
751457f
to
d84d89b
Compare
d84d89b
to
8032b7a
Compare
Btw, I also added a HOC for legacy pages function Page () {
const foo = useSelector(...);
return <div>{foo}</div>;
}
function Loading () { return <div>Loading</div>; }
export default wrapper.withHydration(Page, { Loading }); In this case hook-based This smells like old school HOC approach, but abstracts implementation nuances from users. Alternative API may look like this: function Page () {
const { loadingSelector, loading } = wrapper.useHydration();
const foo = useSelector(loadingSelector(someRealSelector, 'someDefaultValueMaybe?'));
if (loading) return <div>Loading</div>;
return <div>{foo}</div>;
} @daniil4 @voinik @Pikachews @bjoluc thoughts? |
d56e400
to
68582c3
Compare
68582c3
to
da3e1cd
Compare
Implemented the above. Updated readme can be found here: https://github.com/kirill-konshin/next-redux-wrapper/tree/hook-api I significantly simplified everything. Seems to be the right direction. |
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.
Looks like the right step to me and I love the new simplicity – great job! I'm only a little worried about server-side hydration behavior: Will the server-rendered markup contain anything that's introduced with the HYDRATE
action (such as state from cookies in next-redux-cookie-wrapper
)?
Few more considerations regarding
So I am considering to just return Honestly, I have a question to authors of |
Yup, fully on board with that. Folks should either use optional chaining in a selector, or let the store ensure the selected path is available at any time. Let's keep things simple on our end; the Readme is bloated enough :D |
Readme have been shortened a bit, and I will cut it down even more ;) it's a direct consequence of tricky Next.js props management. And it will be even worse if I will find a way to make wrapper to work with Server Components and new |
0eeeb61
to
71ef5c3
Compare
I just had a breakthrough moment. I have ditched |
Congratulations! 🎉 The middleware approach looks really good! I wonder how we didn't consider replaying actions before 😅 Of course, this means actions and reducers must be designed s.t. dispatching the same action multiple times does not alter state (i.e., no toggle actions and friends). But that seems like a fair tradeoff for not needing to maintain ignoreActions: (action: AnyAction) => boolean config option in case some actions are not safe/meant to be replayed? |
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.
Looks very good. I'm in favor of renaming the page props from initialStateABC
to reduxActionsABC
since it's no initial state but actions. And I'd like to have redux
in the name to somehow make clear where the props come from / where they belong to. WDYT?
Don't mind my words, I hadn't reviewed |
Co-authored-by: bjoluc <[email protected]>
Co-authored-by: bjoluc <[email protected]>
Done.
Better late than never... |
792f3bb
to
fdb3551
Compare
fdb3551
to
9094362
Compare
Any updates on this 😎. Just experienced this issue also. |
Dear @DamienDeloubes, as you can see from the activities listed in this PR, @kirill-konshin is actively working on this. The fix became a major rewrite and releasing it with confidence is a time-consuming job, given that @kirill-konshin is mostly left alone working on this library, despite its popularity. So please be patient and consider reading this post on issue bumping. Thanks! |
Latest update — I have finally fixed all tests, they are all passing and it all seems to be working fine. I plan to release it to master, to let people test it in real apps. You guys are welcome to provide more testing, if you can. |
Great news! I'll likely find some time to plug this into an existing app tomorrow. If you'd like me to, I can also work on improving test coverage then. Re master, let me refer to #194 (comment) – if this becomes |
0c0dde0
to
74a930f
Compare
74a930f
to
5844ffd
Compare
It would be great if you can test it out. I usually just switch default branch, so that when you open the repo, I have just fixed the coverage too, btw. |
V8 is now default branch, this PR has been committed to master. |
@kirill-konshin can we get a prerelease for the v9? I am struggling testing it out on my local with master |
https://github.com/kirill-konshin/next-redux-wrapper/releases/tag/9.0.0-rc.1 |
You can't dispatch from |
It seems the question is about using rtk query and next-redux-wrapper. This is the recommended way to get data inside getStaticProps. Also without the HYDRATE action, the recommended way to use rtk query with the next-redux-wrapper is no longer possible. |
Why not possible? All actions are recorded and re-dispatched on client. https://github.com/kirill-konshin/next-redux-wrapper/tree/master/packages/demo-redux-toolkit use the example. Just make sure to dispatch all actions from |
But if I use rtk query to get the number of paths in getStaticPaths, I need to dispatch an action to call the endpoint. As shown in the screenshot. |
I tried getting all patches in getStaticPatch with fetch, but finally, I got 404 when accessing a mapped page. And of course, you can't use getStaticProps without getStaticPaths on [param] pages. It looks like we need to check that the paths are created before doing anything else. Any ideas? |
any update on when there will be a new release with this fix? |
Any updates on when it will be released? |
The solution with wrapper.useHydration(props); will not perform rendering on SSR in Layout if getLayout is used for Per-Page Layouts. |
Refactored
wrapper.useWrappedStore()
to just returnstore
with no hydration. All hydration was moved intowrapper.useHydration(props)
.Props logic was simplified.
Memo hydration is now called only once per page load, to accommodate server side rendered HTML. All subsequent hydrations are dispatched by layout effect. This means all selectors must take into account the fact that data may be unavailable.
This will be released as 9.x major release.
@voinik pls have a look.
Fixes #522
Fixes #520
Honestly, I find it really weird that old component is not unmounted when new is mounting. Sounds like a bug.