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

Framework: add separate server state hydration #3343

Merged
merged 1 commit into from
Feb 19, 2016

Conversation

gwwar
Copy link
Contributor

@gwwar gwwar commented Feb 16, 2016

Following the conversation in #3337 This is an example of what a separate server state hydration pipeline might look like. Reducers would only need to implement this for subtrees that do not contain plain JavaScript objects. Feel free to call out other suggestions for the action name.

cc @aduth @seear

@gwwar gwwar self-assigned this Feb 16, 2016
@gwwar gwwar added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 16, 2016
@@ -24,7 +25,8 @@ export const MAX_AGE = 7 * DAY_IN_HOURS * HOUR_IN_MS;
function getInitialServerState() {
// Bootstrapped state from a server-render
if ( typeof window === 'object' && window.initialReduxState ) {
return window.initialReduxState;
const serverState = reducer( window.initialReduxState, { type: SERVER_DESERIALIZE } );
return pick( serverState, Object.keys( window.initialReduxState ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pick here? Related, if there's a need to trim reduced state to reflect that of the global object, is there not a concern about nested structures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't, server state will override persisted state with default initial state.

@seear which sections of the tree do you see us bootstrapping, and do we need to be more precise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the state tree being bootstrapped is defined by the pick on the server. This works fine for now, but perhaps once the server code becomes more modularized, we can remove the server pick and change this client code to use a formally-defined bootstrap tree.

A reducer that did not return any default state for the SERVER_DESERIALIZE action type would be great for that. Not sure if that is possible.

@@ -50,6 +50,7 @@ export const RECEIPT_FETCH_FAILED = 'RECEIPT_FETCH_FAILED';
export const REMOVE_NOTICE = 'REMOVE_NOTICE';
export const SELECTED_SITE_SET = 'SELECTED_SITE_SET';
export const SERIALIZE = 'SERIALIZE';
export const SERVER_DESERIALIZE = 'SERVER_DESERIALIZE';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say that BOOTSTRAP may give more clue as to what this is for, but I checked back, and that term is not used at all in the server-rendering section of the Redux docs, so I think it is fine as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not attached to the name, so I'd be happy to open up another PR if we find that another term is more clear.

@seear
Copy link
Contributor

seear commented Feb 19, 2016

This is working fine for the server state currently in usage. Good to merge 👍

@seear seear added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 19, 2016
@gwwar
Copy link
Contributor Author

gwwar commented Feb 19, 2016

Thanks for the reviews @seear & @aduth. Going to squash commits.

@gwwar gwwar force-pushed the try/hydrate-server-state branch from 1f9e867 to cf10763 Compare February 19, 2016 17:55
@gwwar gwwar added this to the Calypso Core: Offline 5 milestone Feb 19, 2016
gwwar added a commit that referenced this pull request Feb 19, 2016
Framework: add separate server state hydration
@gwwar gwwar merged commit 4708a56 into master Feb 19, 2016
@gwwar gwwar deleted the try/hydrate-server-state branch February 19, 2016 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants