fix(nuxt): don't warn for definePageMeta in client-only pages (#28246)

This commit is contained in:
Julien Huang 2024-07-21 21:04:06 +02:00 committed by GitHub
parent 3a72b9d1a4
commit 4d730545a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -4,7 +4,13 @@ import ClientOnly from '#app/components/client-only'
/* @__NO_SIDE_EFFECTS__ */
export const createClientPage = (loader: AsyncComponentLoader) => {
const page = defineAsyncComponent(loader)
const page = defineAsyncComponent(import.meta.dev
? () => loader().then((m) => {
// mark component as client-only for `definePageMeta`
(m.default || m).__clientOnlyPage = true
return m.default || m
})
: loader)
return defineComponent({
inheritAttrs: false,

View File

@ -60,7 +60,7 @@ export const definePageMeta = (meta: PageMeta): void => {
try {
const isRouteComponent = component && useRoute().matched.some(p => Object.values(p.components || {}).includes(component))
const isRenderingServerPage = import.meta.server && useNuxtApp().ssrContext?.islandContext
if (isRouteComponent || isRenderingServerPage) {
if (isRouteComponent || isRenderingServerPage || ((component as any)?.__clientOnlyPage)) {
// don't warn if it's being used in a route component (or server page)
return
}