Skip to content

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.

3 participants