Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(nuxt): add dev warnings when setPageLayout is used incorrectly (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 25, 2022
1 parent 12c8949 commit 91eab1b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/nuxt/src/app/composables/router.ts
Expand Up @@ -119,9 +119,15 @@ export const abortNavigation = (err?: string | Partial<NuxtError>) => {

export const setPageLayout = (layout: string) => {
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
}
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()
if (inMiddleware || process.server || nuxtApp.isHydrating) {
const unsubscribe = useRouter().beforeResolve((to) => {
Expand Down

0 comments on commit 91eab1b

Please sign in to comment.