mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat(nuxt): add dev warnings when setPageLayout
is used incorrectly (#8464)
This commit is contained in:
parent
12c8949af9
commit
91eab1b312
@ -119,9 +119,15 @@ export const abortNavigation = (err?: string | Partial<NuxtError>) => {
|
|||||||
|
|
||||||
export const setPageLayout = (layout: string) => {
|
export const setPageLayout = (layout: string) => {
|
||||||
if (process.server) {
|
if (process.server) {
|
||||||
|
if (process.dev && getCurrentInstance() && useState('_layout').value !== layout) {
|
||||||
|
console.warn('[warn] [nuxt] `setPageLayout` should not be called to change the layout on the server within a component as this will cause hydration errors.')
|
||||||
|
}
|
||||||
useState('_layout').value = layout
|
useState('_layout').value = layout
|
||||||
}
|
}
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
|
if (process.dev && nuxtApp.isHydrating && useState('_layout').value !== layout) {
|
||||||
|
console.warn('[warn] [nuxt] `setPageLayout` should not be called to change the layout during hydration as this will cause hydration errors.')
|
||||||
|
}
|
||||||
const inMiddleware = isProcessingMiddleware()
|
const inMiddleware = isProcessingMiddleware()
|
||||||
if (inMiddleware || process.server || nuxtApp.isHydrating) {
|
if (inMiddleware || process.server || nuxtApp.isHydrating) {
|
||||||
const unsubscribe = useRouter().beforeResolve((to) => {
|
const unsubscribe = useRouter().beforeResolve((to) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user