mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix: properly serialize undefined in vuex store (#3913)
* allow to serialize undefined variable in vuex store * test properly * fix test * lock
This commit is contained in:
parent
55a153c7d0
commit
df148a896e
@ -172,7 +172,7 @@ function resolveComponents(router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function callMiddleware (Components, context, layout) {
|
function callMiddleware (Components, context, layout) {
|
||||||
let midd = <%= serialize(router.middleware, { isJSON: true }) %>
|
let midd = <%= devalue(router.middleware) %>
|
||||||
let unknownMiddleware = false
|
let unknownMiddleware = false
|
||||||
|
|
||||||
// If layout is undefined, only call global middleware
|
// If layout is undefined, only call global middleware
|
||||||
|
@ -8,6 +8,7 @@ import fsExtra from 'fs-extra'
|
|||||||
import hash from 'hash-sum'
|
import hash from 'hash-sum'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import serialize from 'serialize-javascript'
|
import serialize from 'serialize-javascript'
|
||||||
|
import devalue from 'devalue'
|
||||||
import MFS from 'memory-fs'
|
import MFS from 'memory-fs'
|
||||||
import webpackDevMiddleware from 'webpack-dev-middleware'
|
import webpackDevMiddleware from 'webpack-dev-middleware'
|
||||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||||
@ -398,6 +399,7 @@ export default class Builder {
|
|||||||
const template = _.template(fileContent, {
|
const template = _.template(fileContent, {
|
||||||
imports: {
|
imports: {
|
||||||
serialize,
|
serialize,
|
||||||
|
devalue,
|
||||||
hash,
|
hash,
|
||||||
r,
|
r,
|
||||||
wp,
|
wp,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
|
|
||||||
import serialize from 'serialize-javascript'
|
import devalue from 'devalue'
|
||||||
import serveStatic from 'serve-static'
|
import serveStatic from 'serve-static'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
@ -361,9 +361,7 @@ export default class Renderer {
|
|||||||
|
|
||||||
await this.nuxt.callHook('render:routeContext', context.nuxt)
|
await this.nuxt.callHook('render:routeContext', context.nuxt)
|
||||||
|
|
||||||
const serializedSession = `window.__NUXT__=${serialize(context.nuxt, {
|
const serializedSession = `window.__NUXT__=${devalue(context.nuxt)};`
|
||||||
isJSON: true
|
|
||||||
})};`
|
|
||||||
|
|
||||||
const cspScriptSrcHashSet = new Set()
|
const cspScriptSrcHashSet = new Set()
|
||||||
if (this.options.render.csp) {
|
if (this.options.render.csp) {
|
||||||
|
@ -86,6 +86,7 @@
|
|||||||
"css-loader": "^1.0.0",
|
"css-loader": "^1.0.0",
|
||||||
"cssnano": "^4.0.5",
|
"cssnano": "^4.0.5",
|
||||||
"debug": "^4.0.1",
|
"debug": "^4.0.1",
|
||||||
|
"devalue": "^1.0.4",
|
||||||
"esm": "^3.0.84",
|
"esm": "^3.0.84",
|
||||||
"etag": "^1.8.1",
|
"etag": "^1.8.1",
|
||||||
"file-loader": "^2.0.0",
|
"file-loader": "^2.0.0",
|
||||||
|
3
test/fixtures/ssr/store/index.js
vendored
3
test/fixtures/ssr/store/index.js
vendored
@ -3,7 +3,8 @@ import { nextId } from '@/lib/db'
|
|||||||
export const state = () => {
|
export const state = () => {
|
||||||
return {
|
return {
|
||||||
id: nextId(),
|
id: nextId(),
|
||||||
id2: 0
|
id2: 0,
|
||||||
|
idUndefined: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ describe('basic ssr', () => {
|
|||||||
|
|
||||||
test('/meta', async () => {
|
test('/meta', async () => {
|
||||||
const { html } = await nuxt.renderRoute('/meta')
|
const { html } = await nuxt.renderRoute('/meta')
|
||||||
expect(html.includes('"meta":[{"works":true}]')).toBe(true)
|
expect(/<pre>.*"works": true.*<\/pre>/s.test(html)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('/fn-midd', async () => {
|
test('/fn-midd', async () => {
|
||||||
|
@ -97,6 +97,12 @@ describe('ssr', () => {
|
|||||||
await uniqueTest('/fetch')
|
await uniqueTest('/fetch')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('store undefined variable response', async () => {
|
||||||
|
const window = await nuxt.renderAndGetWindow(url('/store'))
|
||||||
|
expect('idUndefined' in window.__NUXT__.state).toBe(true)
|
||||||
|
expect(window.__NUXT__.state.idUndefined).toEqual(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
test('stress test with asyncData', async () => {
|
test('stress test with asyncData', async () => {
|
||||||
await stressTest('/asyncData')
|
await stressTest('/asyncData')
|
||||||
})
|
})
|
||||||
|
@ -2484,6 +2484,10 @@ detect-newline@^2.1.0:
|
|||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2"
|
resolved "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2"
|
||||||
|
|
||||||
|
devalue@^1.0.4:
|
||||||
|
version "1.0.4"
|
||||||
|
resolved "https://registry.npmjs.org/devalue/-/devalue-1.0.4.tgz#d1f1a0e5d3799b805e1ee2d67f5c741a5d7812a7"
|
||||||
|
|
||||||
diff@^3.2.0:
|
diff@^3.2.0:
|
||||||
version "3.5.0"
|
version "3.5.0"
|
||||||
resolved "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
|
resolved "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
|
||||||
@ -7848,7 +7852,7 @@ vue-loader@^15.4.2:
|
|||||||
vue-hot-reload-api "^2.3.0"
|
vue-hot-reload-api "^2.3.0"
|
||||||
vue-style-loader "^4.1.0"
|
vue-style-loader "^4.1.0"
|
||||||
|
|
||||||
vue-meta@^1.5.3:
|
vue-meta@^1.5.4:
|
||||||
version "1.5.4"
|
version "1.5.4"
|
||||||
resolved "https://registry.npmjs.org/vue-meta/-/vue-meta-1.5.4.tgz#966e37a58c0eff43411eac5894ebc6836a451744"
|
resolved "https://registry.npmjs.org/vue-meta/-/vue-meta-1.5.4.tgz#966e37a58c0eff43411eac5894ebc6836a451744"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user