mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): use destr
in more places over JSON.parse
(#22997)
This commit is contained in:
parent
b27740cf50
commit
1a08079710
@ -2,6 +2,7 @@ import { parseURL } from 'ufo'
|
||||
import { defineComponent, h } from 'vue'
|
||||
import { parseQuery } from 'vue-router'
|
||||
import { resolve } from 'pathe'
|
||||
import destr from 'destr'
|
||||
// @ts-expect-error virtual file
|
||||
import { devRootDir } from '#build/nuxt.config.mjs'
|
||||
|
||||
@ -10,7 +11,7 @@ export default (url: string) => defineComponent({
|
||||
|
||||
async setup (props, { attrs }) {
|
||||
const query = parseQuery(parseURL(url).search)
|
||||
const urlProps = query.props ? JSON.parse(query.props as string) : {}
|
||||
const urlProps = query.props ? destr<Record<string, any>>(query.props as string) : {}
|
||||
const path = resolve(query.path as string)
|
||||
if (!path.startsWith(devRootDir)) {
|
||||
throw new Error(`[nuxt] Cannot access path outside of project root directory: \`${path}\`.`)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import destr from 'destr'
|
||||
import { useNuxtApp } from '#app/nuxt'
|
||||
|
||||
export interface ReloadNuxtAppOptions {
|
||||
@ -34,7 +35,7 @@ export function reloadNuxtApp (options: ReloadNuxtAppOptions = {}) {
|
||||
|
||||
let handledPath: Record<string, any> = {}
|
||||
try {
|
||||
handledPath = JSON.parse(sessionStorage.getItem('nuxt:reload') || '{}')
|
||||
handledPath = destr(sessionStorage.getItem('nuxt:reload') || '{}')
|
||||
} catch {}
|
||||
|
||||
if (options.force || handledPath?.path !== path || handledPath?.expires < Date.now()) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import destr from 'destr'
|
||||
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
||||
|
||||
export default defineNuxtPlugin({
|
||||
@ -9,7 +10,7 @@ export default defineNuxtPlugin({
|
||||
const state = sessionStorage.getItem('nuxt:reload:state')
|
||||
if (state) {
|
||||
sessionStorage.removeItem('nuxt:reload:state')
|
||||
Object.assign(nuxtApp.payload.state, JSON.parse(state)?.state)
|
||||
Object.assign(nuxtApp.payload.state, destr<Record<string, any>>(state)?.state)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { reactive, ref, shallowReactive, shallowRef } from 'vue'
|
||||
import destr from 'destr'
|
||||
import { definePayloadReviver, getNuxtClientPayload } from '#app/composables/payload'
|
||||
import { createError } from '#app/composables/error'
|
||||
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
||||
@ -8,8 +9,8 @@ import { componentIslands } from '#build/nuxt.config.mjs'
|
||||
|
||||
const revivers: Record<string, (data: any) => any> = {
|
||||
NuxtError: data => createError(data),
|
||||
EmptyShallowRef: data => shallowRef(data === '_' ? undefined : data === '0n' ? BigInt(0) : JSON.parse(data)),
|
||||
EmptyRef: data => ref(data === '_' ? undefined : data === '0n' ? BigInt(0) : JSON.parse(data)),
|
||||
EmptyShallowRef: data => shallowRef(data === '_' ? undefined : data === '0n' ? BigInt(0) : destr(data)),
|
||||
EmptyRef: data => ref(data === '_' ? undefined : data === '0n' ? BigInt(0) : destr(data)),
|
||||
ShallowRef: data => shallowRef(data),
|
||||
ShallowReactive: data => shallowReactive(data),
|
||||
Ref: data => ref(data),
|
||||
|
Loading…
Reference in New Issue
Block a user