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

fix(nuxt): don't try to override computed layouts in definePageMeta #9161

Merged
merged 7 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>((nuxtApp) => {
nuxtApp.hooks.hookOnce('app:created', async () => {
router.beforeEach(async (to, from) => {
to.meta = reactive(to.meta || {})
if (nuxtApp.isHydrating) {
to.meta.layout = initialLayout.value ?? to.meta.layout
if (nuxtApp.isHydrating && initialLayout.value !== undefined && initialLayout.value !== null) {
danielroe marked this conversation as resolved.
Show resolved Hide resolved
to.meta.layout = initialLayout.value
}
nuxtApp._processingMiddleware = true

Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/pages/runtime/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
const initialLayout = useState('_layout')
router.beforeEach(async (to, from) => {
to.meta = reactive(to.meta)
if (nuxtApp.isHydrating) {
to.meta.layout = initialLayout.value ?? to.meta.layout
if (nuxtApp.isHydrating && initialLayout.value !== undefined && initialLayout.value !== null) {
danielroe marked this conversation as resolved.
Show resolved Hide resolved
to.meta.layout = initialLayout.value
}
nuxtApp._processingMiddleware = true

Expand Down
10 changes: 10 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@ describe('layouts', () => {
expect(html).toContain('Custom Layout:')
await expectNoClientErrors('/with-dynamic-layout')
})
it('should work with a computed layout', async () => {
const html = await $fetch('/with-computed-layout')

// Snapshot
// expect(html).toMatchInlineSnapshot()

expect(html).toContain('with-computed-layout')
expect(html).toContain('Custom Layout')
await expectNoClientErrors('/with-computed-layout')
})
})

describe('reactivity transform', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/basic/pages/with-computed-layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup>
definePageMeta({
layout: computed(() => 'custom')
})
</script>

<template>
<div>
<div>with-computed-layout.vue</div>
</div>
</template>