spatie/server-side-rendering

Data hydration between node process and client

mercs600 opened this issue · 0 comments

First of all, great job! I would like to ask is there any way to hydrate data between Vue App and PHP environment ?
Now we can pass context and environment data to application, so we can get data from PHP to VueJS app and this is ok.
What in case when I'm getting data from serverPrefetch (ssr hook) and I want to pass them to the client - in that case we should share our context from node process to PHP. When it comes to node environment only there is no issue, but is it possible to do this together with PHP ?

EDIT:
I have done something like this. It does not look like much, but it works...

Is there better way ?

if (typeof dispatch !== 'undefined') {
    renderToString(app, (err, html) => {
        if (err) {
            throw new Error(err)
        }
        html = `
        <script type="text/javascript">
        var __CONTEXT__ = ${JSON.stringify(app.$store.state)};
        </script>
        ${html}`
        // eslint-disable-next-line no-undef
        dispatch(html)
    })
}