-
Notifications
You must be signed in to change notification settings - Fork 392
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
Update README about more Vuejs SSR hydration caveats #142
Comments
Update: Unforchunately this means you need to also implement your own comment removal logic which bloats the JS bundle a little. Example ...
window.snapSaveState = () => {
// enable client-side hydration once the page has been prerendered
document.querySelector('#app').setAttribute('data-server-rendered', 'true');
// remove scripts added to head by webpack; fix async race condition issue
const scripts = document.head.getElementsByTagName('script');
for (let i = 0; i < scripts.length; i += 1) { // forEach didn't work for some bizarre reason
const el = scripts[i];
if (el.async && el.charset === 'utf-8') {
// console.warn('REMOVING:', el.src); // eslint-disable-line no-console
el.remove();
}
}
// remove comments (react-snap config can't take RegExp so do it custom)
const html = document.documentElement;
const noComments = html.innerHTML.replace(/<!--(?!\[if|-->)[\s\S]*?-->/g, '');
html.innerHTML = noComments;
}; I've made a separate issue about allowing a JS config which would allow using |
because
To use
This case should be handled by Thanks for tips. I'm not an expert in Vue. I want to experiment with it a bit and add notes to Readme |
Normally when dealing with a NodeList or HTMLCollection I do something like I've opened another issue for the webpack bundle issue: #145 |
Once I have some free time I'll try to put together a PR with the proposed docs updates. |
Fixed in #172 |
When using
react-snap
withvue
andwebpack
+vue-loader
there's an extra client side hydration caveat worth adding to the readme.When using react-snap with the
minifyHtml.collapseWhitespace = true
option vue client side hydration will fail because, by default, vue-loader includes whitespace when creating its virtual DOM representation. Since the VDOM and the real DOM are different (VDOM has extra whitespace textNodes), hydration fails.Took me a while to work out what was going on but it turns out there's an easy solution. In the vue-loader configuration just add
preserveWhitespace: false
. In the official templates this is found in thevue-loader.conf.js
file. Info in the vue-loader docs.If that doesn't make sense please let me know and I'll try to explain better or create an example repo.
The text was updated successfully, but these errors were encountered: