Repository: nuxt/nuxt
File: packages/nuxt/src/app/components/nuxt-layout.ts (TypeScript)

Code before:
// this avoids type loss/simplification resulting in things like MaybeRef<string | false>, keeping type hints for layout names
const nuxtLayoutProps = {
  name: {
    type: [String, Boolean, Object] as PropType<unknown extends PageMeta['layout'] ? MaybeRef<string | false> : PageMeta['layout']>,
    default: null,
  },
  fallback: {
    type: [String, Object] as PropType<unknown extends PageMeta['layout'] ? MaybeRef<string> : PageMeta['layout']>,
    default: null,
  },
}

export default defineComponent({
  name: 'NuxtLayout',
  inheritAttrs: false,
  props: nuxtLayoutProps,
  setup (props, context) {
    const nuxtApp = useNuxtApp()
    // Need to ensure (if we are not a child of `<NuxtPage>`) that we use synchronous route (not deferred)
    const injectedRoute = inject(PageRouteSymbol)
    const shouldUseEagerRoute = !injectedRoute /* this should never be true */
      || injectedRoute === useRoute() /* this is only true if we are not within `<NuxtPage>` */
    const route = shouldUseEagerRoute ? useVueRouterRoute() as ReturnType<typeof useRoute> : injectedRoute

    const layout = computed(() => {
      let layout = unref(props.name) ?? route!.meta.layout as string ?? 'default'
      if (layout && !(layout in layouts)) {
        if (import.meta.dev && layout !== 'default') {
          console.warn(`Invalid layout \`${layout}\` selected.`)
        }
        if (props.fallback) {
          layout = unref(props.fallback)
        }
      }
      return layout
    })

    const layoutRef = ref()
    context.expose({ layoutRef })

    const done = nuxtApp.deferHydration()
    if (import.meta.client && nuxtApp.isHydrating) {
      const removeErrorHook = nuxtApp.hooks.hookOnce('app:error', done)
      useRouter().beforeEach(removeErrorHook)
    }

    if (import.meta.dev) {
      nuxtApp._isNuxtLayoutUsed = true
    }

    let lastLayout: string | boolean | undefined

Review comment (suggestion):
```suggestion
      let layout = unref(props.name) ?? route?.meta.layout as string ?? 'default'
```

Code after:
// this avoids type loss/simplification resulting in things like MaybeRef<string | false>, keeping type hints for layout names
const nuxtLayoutProps = {
  name: {
    type: [String, Boolean, Object] as PropType<unknown extends PageMeta['layout'] ? MaybeRef<string | false> : PageMeta['layout']>,
    default: null,
  },
  fallback: {
    type: [String, Object] as PropType<unknown extends PageMeta['layout'] ? MaybeRef<string> : PageMeta['layout']>,
    default: null,
  },
}

export default defineComponent({
  name: 'NuxtLayout',
  inheritAttrs: false,
  props: nuxtLayoutProps,
  setup (props, context) {
    const nuxtApp = useNuxtApp()
    // Need to ensure (if we are not a child of `<NuxtPage>`) that we use synchronous route (not deferred)
    const injectedRoute = inject(PageRouteSymbol)
    const shouldUseEagerRoute = !injectedRoute /* this should never be true */
      || injectedRoute === useRoute() /* this is only true if we are not within `<NuxtPage>` */
    const route = shouldUseEagerRoute ? useVueRouterRoute() as ReturnType<typeof useRoute> : injectedRoute

    const layout = computed(() => {
      let layout = unref(props.name) ?? route?.meta.layout as string ?? 'default'
      if (layout && !(layout in layouts)) {
        if (import.meta.dev && layout !== 'default') {
          console.warn(`Invalid layout \`${layout}\` selected.`)
        }
        if (props.fallback) {
          layout = unref(props.fallback)
        }
      }
      return layout
    })

    const layoutRef = ref()
    context.expose({ layoutRef })

    const done = nuxtApp.deferHydration()
    if (import.meta.client && nuxtApp.isHydrating) {
      const removeErrorHook = nuxtApp.hooks.hookOnce('app:error', done)
      useRouter().beforeEach(removeErrorHook)
    }

    if (import.meta.dev) {
      nuxtApp._isNuxtLayoutUsed = true
    }

    let lastLayout: string | boolean | undefined