-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(using-redux): create a fresh store for each SSR page #11134
Conversation
Could you explain:
Creating a new store for each page is something you don't really want when gatsby re-hydrates your page as the redux store should be shared across pages. |
@wardpeet Yes, the redux store should be shared across pages once the page has been loaded, but not for every initial rendering of every single page during Currently, as mentioned in #10912, each page gets rendered retaining the prior state since the store is created static and thus retained between each initial rendering in the |
From #10912, based on the "using-redux" example from this repo: With However,
Note: I'd initially tried using |
A few new remarks: As a result, maybe we should just go back to having separate functions for Further, even placing redux state changes in the Thus, it might be worth updating the example to show pages with differing initial states. e.g., I'm currently using: const getStateFor = (pathname) => {
if (!pathname) {
return {};
}
...<computation here>
return {
...<computed values>
}
}
const createStore = (pathname) => {
const pathState = getStateFor(pathname);
return reduxCreateStore(reducer,
{
...initialState,
...pathState
}, composeWithDevTools(applyMiddleware()));
} |
the |
From pieh's suggestion Co-Authored-By: cpboyd <xpboyd@gmail.com>
@pieh updated with your suggestion |
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.
Thanks @cpboyd!
Holy buckets, @cpboyd — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Description
As I'd mentioned in #10912, the current using-redux example creates a static store that persists across multiple SSR pages.
It seems that the expected behavior should likely be that each page's initial load is from a fresh store, in order to match the behavior of the browser rendering.
Related Issues
Related to #10912