From 4760101431f51034ab75e69091f6f70316c6248a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 12 Jun 2024 12:37:10 +0100 Subject: [PATCH] fix: do not try to access private runtime config on client --- src/runtime/nitro/routes/__schema-org__/debug.ts | 3 ++- src/runtime/nuxt/imports/useSchemaOrg.ts | 3 ++- src/runtime/nuxt/plugin/defaults.ts | 3 ++- src/runtime/nuxt/plugin/init.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runtime/nitro/routes/__schema-org__/debug.ts b/src/runtime/nitro/routes/__schema-org__/debug.ts index a704394..6fbae3b 100644 --- a/src/runtime/nitro/routes/__schema-org__/debug.ts +++ b/src/runtime/nitro/routes/__schema-org__/debug.ts @@ -3,7 +3,8 @@ import type { ModuleRuntimeConfig } from '../../../types' import { useNitroOrigin, useRuntimeConfig } from '#imports' export default defineEventHandler(async (e) => { - const runtimeConfig = (useRuntimeConfig()['nuxt-schema-org'] || useRuntimeConfig().public['nuxt-schema-org']) as any as ModuleRuntimeConfig + const _config = useRuntimeConfig() + const runtimeConfig = (import.meta.client ? _config.public['nuxt-schema-org'] : (_config['nuxt-schema-org'] || _config.public['nuxt-schema-org'])) as any as ModuleRuntimeConfig const nitroOrigin = useNitroOrigin(e) return { nitroOrigin, diff --git a/src/runtime/nuxt/imports/useSchemaOrg.ts b/src/runtime/nuxt/imports/useSchemaOrg.ts index 65487d5..bc693d6 100644 --- a/src/runtime/nuxt/imports/useSchemaOrg.ts +++ b/src/runtime/nuxt/imports/useSchemaOrg.ts @@ -5,7 +5,8 @@ import { useHead, useRuntimeConfig, useServerHead } from '#imports' type Input = Parameters[0] export function useSchemaOrg(input: T): ActiveHeadEntry> | void { - const config = (useRuntimeConfig()['nuxt-schema-org'] || useRuntimeConfig().public['nuxt-schema-org']) as ModuleRuntimeConfig + const _config = useRuntimeConfig() + const config = (import.meta.client ? _config.public['nuxt-schema-org'] : (_config['nuxt-schema-org'] || _config.public['nuxt-schema-org'])) as ModuleRuntimeConfig const script = { type: 'application/ld+json', key: 'schema-org-graph', diff --git a/src/runtime/nuxt/plugin/defaults.ts b/src/runtime/nuxt/plugin/defaults.ts index c62a109..d5fe20d 100644 --- a/src/runtime/nuxt/plugin/defaults.ts +++ b/src/runtime/nuxt/plugin/defaults.ts @@ -14,7 +14,8 @@ import { export default defineNuxtPlugin({ name: 'nuxt-schema-org:defaults', setup() { - const runtimeConfig = useRuntimeConfig()['nuxt-schema-org'] || useRuntimeConfig().public['nuxt-schema-org'] + const _config = useRuntimeConfig() + const runtimeConfig = import.meta.client ? _config.public['nuxt-schema-org'] : (_config['nuxt-schema-org'] || _config.public['nuxt-schema-org']) // get the head instance const siteConfig = useSiteConfig() diff --git a/src/runtime/nuxt/plugin/init.ts b/src/runtime/nuxt/plugin/init.ts index 16cf6e4..e36fc65 100644 --- a/src/runtime/nuxt/plugin/init.ts +++ b/src/runtime/nuxt/plugin/init.ts @@ -10,7 +10,8 @@ export default defineNuxtPlugin({ enforce: 'post', setup(nuxtApp) { const head = injectHead() - const config = (useRuntimeConfig()['nuxt-schema-org'] || useRuntimeConfig().public['nuxt-schema-org']) as ModuleRuntimeConfig + const _config = useRuntimeConfig() + const config = (import.meta.client ? _config.public['nuxt-schema-org'] : (_config['nuxt-schema-org'] || _config.public['nuxt-schema-org'])) as ModuleRuntimeConfig const route = useRoute() const siteConfig = useSiteConfig()