fix(nuxt3): don't mock server-only properties on client-side (#2376)

This commit is contained in:
Daniel Roe 2021-12-14 13:28:43 +00:00 committed by GitHub
parent 3e82f0f2cb
commit c87c692ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,6 +114,12 @@ const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
'beforeSerialize' 'beforeSerialize'
]) ])
const serverProperties = new Set<keyof LegacyContext['ssrContext'] | keyof LegacyContext>([
'req',
'res',
'ssrContext'
])
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query'] const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
const staticFlags = { const staticFlags = {
@ -159,6 +165,10 @@ export const legacyPlugin = (nuxtApp: NuxtApp) => {
return staticFlags[p] return staticFlags[p]
} }
if (process.client && serverProperties.has(p)) {
return undefined
}
if (p === 'ssrContext') { if (p === 'ssrContext') {
return nuxt._legacyContext return nuxt._legacyContext
} }