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

New global state methods to support SSR rehydration #2

Merged
merged 4 commits into from
Sep 2, 2018

Conversation

deamme
Copy link
Owner

@deamme deamme commented Sep 1, 2018

Right now there is no way to rehydrate your server-side state changes to the client. I've added new global state methods to solve this issue so we can use Laco with server-side rendering. I've also added the new methods to the documentation with a new rehydration section.

@jhsware
Copy link

jhsware commented Sep 1, 2018

Most people won't realise that you need the following to avoid potential JS-injection attacks:

const hydratedState = JSON.stringify(encodeURIComponent(JSON.stringify(storeState)))

Then you assign that string to a variable in your template and decode it like this:

const rehydratedState = JSON.parse(decodeURIComponent(hydratedState))

So perhaps it is a good idea to create specific hydrate/rehydrate methods that enforce this?

@deamme
Copy link
Owner Author

deamme commented Sep 1, 2018

@jhsware Thanks for the feedback! I think it's a good idea - although I don't want to bloat the library - the Redux SSR guide mentions the security implications and solves it by doing JSON.stringify(preloadedState).replace(/</g, '\\u003c'). I can warn the user though in the documentation

@deamme deamme merged commit 723fde1 into master Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants