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

Add handling of _ssr_ prefix state fields #71

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-ssr-build",
"version": "4.6.1",
"version": "4.7.0",
"description": "Vue.js SSR Build Helper",
"author": "matt@brophy.org",
"license": "MIT",
Expand Down
24 changes: 18 additions & 6 deletions src/entry-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,24 @@ export default function initializeServer(createApp, serverOpts) {
// https://v8.dev/blog/cost-of-javascript-2019#json
initialState: JSON.stringify(JSON.stringify(
store.state,
// Convert all undefined values to null's during stringification.
// Default behavior of JSON.stringify is to strip undefined values,
// which breaks client side hydration because Vue won't make the
// property reactive. See:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description
(k, v) => (v === undefined ? null : v),
// Custom JSON.stringify replacer function to do 2 things:
// * Convert any `_ssr_` prefixed keys to undefined values so
// they get stripped. These properties are strictly for SSR
// memoization of non-reactive expensive getter methods
// * Convert all undefined values to null's during stringification.
// Default behavior of JSON.stringify is to strip undefined values,
// which breaks client side hydration because Vue won't make the
// property reactive. See:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description
(k, v) => {
if (k.startsWith('_ssr_')) {
return undefined;
}
if (v === undefined) {
return null;
}
return v;
},
)),
}))
.then(() => resolve(app))
Expand Down