mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt)!: remove __NUXT__
after hydration (#27745)
This commit is contained in:
parent
c628975efc
commit
5f819ab88e
@ -371,6 +371,25 @@ However, if you are a module author using the `builder:watch` hook and wishing t
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Removal of `window.__NUXT__` object
|
||||||
|
|
||||||
|
##### What Changed
|
||||||
|
|
||||||
|
We are removing the global `window.__NUXT__` object after the app finishes hydration.
|
||||||
|
|
||||||
|
##### Reasons for Change
|
||||||
|
|
||||||
|
This opens the way to multi-app patterns ([#21635](https://github.com/nuxt/nuxt/issues/21635)) and enables us to focus on a single way to access Nuxt app data - `useNuxtApp()`.
|
||||||
|
|
||||||
|
##### Migration Steps
|
||||||
|
|
||||||
|
The data is still available, but can be accessed with `useNuxtApp().payload`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- console.log(window.__NUXT__)
|
||||||
|
+ console.log(useNuxtApp().payload)
|
||||||
|
```
|
||||||
|
|
||||||
#### Directory index scanning
|
#### Directory index scanning
|
||||||
|
|
||||||
🚦 **Impact Level**: Medium
|
🚦 **Impact Level**: Medium
|
||||||
|
@ -49,7 +49,6 @@ export default defineNuxtPlugin({
|
|||||||
definePayloadReviver(reviver, revivers[reviver as keyof typeof revivers])
|
definePayloadReviver(reviver, revivers[reviver as keyof typeof revivers])
|
||||||
}
|
}
|
||||||
Object.assign(nuxtApp.payload, await nuxtApp.runWithContext(getNuxtClientPayload))
|
Object.assign(nuxtApp.payload, await nuxtApp.runWithContext(getNuxtClientPayload))
|
||||||
// For backwards compatibility - TODO: remove later
|
delete window.__NUXT__
|
||||||
window.__NUXT__ = nuxtApp.payload
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -267,7 +267,7 @@ declare module 'nitropack' {
|
|||||||
export const clientConfigTemplate: NuxtTemplate = {
|
export const clientConfigTemplate: NuxtTemplate = {
|
||||||
filename: 'nitro.client.mjs',
|
filename: 'nitro.client.mjs',
|
||||||
getContents: () => `
|
getContents: () => `
|
||||||
export const useRuntimeConfig = () => window?.__NUXT__?.config || {}
|
export const useRuntimeConfig = () => window?.__NUXT__?.config || window?.useNuxtApp?.().payload?.config || {}
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
|
|||||||
for (const outputDir of ['.output', '.output-inline']) {
|
for (const outputDir of ['.output', '.output-inline']) {
|
||||||
it('default client bundle size', async () => {
|
it('default client bundle size', async () => {
|
||||||
const clientStats = await analyzeSizes('**/*.js', join(rootDir, outputDir, 'public'))
|
const clientStats = await analyzeSizes('**/*.js', join(rootDir, outputDir, 'public'))
|
||||||
expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot(`"106k"`)
|
expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot(`"107k"`)
|
||||||
expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
"_nuxt/entry.js",
|
"_nuxt/entry.js",
|
||||||
|
@ -3,7 +3,7 @@ async function getData () { }
|
|||||||
await getData()
|
await getData()
|
||||||
|
|
||||||
// break server-side
|
// break server-side
|
||||||
const data = window.__NUXT__
|
const data = window.useNuxtApp().payload
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
// break server-side
|
// break server-side
|
||||||
const data = window.__NUXT__
|
const data = window.useNuxtApp().payload
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
Loading…
Reference in New Issue
Block a user