diff --git a/docs/1.getting-started/7.state-management.md b/docs/1.getting-started/7.state-management.md index 249971fa2b9f..3a0ea00d1bb7 100644 --- a/docs/1.getting-started/7.state-management.md +++ b/docs/1.getting-started/7.state-management.md @@ -74,12 +74,12 @@ export const useLocale = () => useState('locale', () => useDefaultLocale export const useDefaultLocale = (fallback = 'en-US') => { const locale = ref(fallback) - if (process.server) { + if (import.meta.server) { const reqLocale = useRequestHeaders()['accept-language']?.split(',')[0] if (reqLocale) { locale.value = reqLocale } - } else if (process.client) { + } else if (import.meta.client) { const navLang = navigator.language if (navLang) { locale.value = navLang diff --git a/docs/2.guide/2.directory-structure/1.middleware.md b/docs/2.guide/2.directory-structure/1.middleware.md index 5520b4eaa966..4b98ba506a9f 100644 --- a/docs/2.guide/2.directory-structure/1.middleware.md +++ b/docs/2.guide/2.directory-structure/1.middleware.md @@ -125,12 +125,12 @@ However, if you want to avoid this behaviour you can do so: ```js export default defineNuxtRouteMiddleware(to => { // skip middleware on server - if (process.server) return + if (import.meta.server) return // skip middleware on client side entirely - if (process.client) return + if (import.meta.client) return // or only skip middleware on initial client load const nuxtApp = useNuxtApp() - if (process.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) return + if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) return }) ``` diff --git a/docs/2.guide/2.directory-structure/1.plugins.md b/docs/2.guide/2.directory-structure/1.plugins.md index f265646ff96b..62ac4a043d9c 100644 --- a/docs/2.guide/2.directory-structure/1.plugins.md +++ b/docs/2.guide/2.directory-structure/1.plugins.md @@ -62,7 +62,7 @@ export default defineNuxtPlugin({ ``` ::alert -If you are using an object-syntax plugin, the properties may be statically analyzed in future to produce a more optimized build. So you should not define them at runtime. For example, setting `enforce: process.server ? 'pre' : 'post'` would defeat any future optimization Nuxt is able to do for your plugins. +If you are using an object-syntax plugin, the properties may be statically analyzed in future to produce a more optimized build. So you should not define them at runtime. For example, setting `enforce: import.meta.server ? 'pre' : 'post'` would defeat any future optimization Nuxt is able to do for your plugins. :: ## Plugin Registration Order diff --git a/docs/2.guide/3.going-further/10.runtime-config.md b/docs/2.guide/3.going-further/10.runtime-config.md index 268b5dd945a6..08d161d2ef4d 100644 --- a/docs/2.guide/3.going-further/10.runtime-config.md +++ b/docs/2.guide/3.going-further/10.runtime-config.md @@ -94,7 +94,7 @@ The entire runtime config is available on the server-side, but it is read-only t diff --git a/docs/2.guide/3.going-further/8.custom-routing.md b/docs/2.guide/3.going-further/8.custom-routing.md index 3adc6ee72c69..ce62e09f306b 100644 --- a/docs/2.guide/3.going-further/8.custom-routing.md +++ b/docs/2.guide/3.going-further/8.custom-routing.md @@ -138,6 +138,6 @@ import { createMemoryHistory } from 'vue-router' // https://router.vuejs.org/api/interfaces/routeroptions.html export default { - history: base => process.client ? createMemoryHistory(base) : null /* default */ + history: base => import.meta.client ? createMemoryHistory(base) : null /* default */ } ``` diff --git a/docs/3.api/1.composables/use-nuxt-app.md b/docs/3.api/1.composables/use-nuxt-app.md index f12d562a75b4..1a5694aa3f35 100644 --- a/docs/3.api/1.composables/use-nuxt-app.md +++ b/docs/3.api/1.composables/use-nuxt-app.md @@ -45,7 +45,7 @@ export default defineNuxtPlugin((nuxtApp) => { }) nuxtApp.hook('vue:error', (..._args) => { console.log('vue:error') - // if (process.client) { + // if (import.meta.client) { // console.log(..._args) // } }) @@ -105,7 +105,7 @@ When accessing the same `payload.data` from [ssrcontext](#ssrcontext), you can a export const useColor = () => useState('color', () => 'pink') export default defineNuxtPlugin((nuxtApp) => { - if (process.server) { + if (import.meta.server) { const color = useColor() } }) @@ -137,7 +137,7 @@ export default defineComponent({ setup (_props, { slots, emit }) { const nuxtApp = useNuxtApp() onErrorCaptured((err) => { - if (process.client && !nuxtApp.isHydrating) { + if (import.meta.client && !nuxtApp.isHydrating) { // ... } }) diff --git a/packages/kit/src/template.ts b/packages/kit/src/template.ts index 87eaa2b855e7..96cf22b57c16 100644 --- a/packages/kit/src/template.ts +++ b/packages/kit/src/template.ts @@ -128,7 +128,6 @@ export async function writeTypes (nuxt: Nuxt) { noEmit: true, resolveJsonModule: true, allowSyntheticDefaultImports: true, - types: ['node'], paths: {} }, include: [ diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index b95ade290b43..c7ce27a73acd 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -122,6 +122,9 @@ "peerDependenciesMeta": { "@parcel/watcher": { "optional": true + }, + "@types/node": { + "optional": true } }, "engines": { diff --git a/packages/nuxt/src/app/compat/idle-callback.ts b/packages/nuxt/src/app/compat/idle-callback.ts index cc28a2b1a2be..01779dc1febe 100644 --- a/packages/nuxt/src/app/compat/idle-callback.ts +++ b/packages/nuxt/src/app/compat/idle-callback.ts @@ -1,6 +1,6 @@ // Polyfills for Safari support // https://caniuse.com/requestidlecallback -export const requestIdleCallback: Window['requestIdleCallback'] = process.server +export const requestIdleCallback: Window['requestIdleCallback'] = import.meta.server ? (() => {}) as any : (globalThis.requestIdleCallback || ((cb) => { const start = Date.now() @@ -11,6 +11,6 @@ export const requestIdleCallback: Window['requestIdleCallback'] = process.server return setTimeout(() => { cb(idleDeadline) }, 1) })) -export const cancelIdleCallback: Window['cancelIdleCallback'] = process.server +export const cancelIdleCallback: Window['cancelIdleCallback'] = import.meta.server ? (() => {}) as any : (globalThis.cancelIdleCallback || ((id) => { clearTimeout(id) })) diff --git a/packages/nuxt/src/app/components/dev-only.ts b/packages/nuxt/src/app/components/dev-only.ts index 914ba6f6e445..6c8ec7c5e9e5 100644 --- a/packages/nuxt/src/app/components/dev-only.ts +++ b/packages/nuxt/src/app/components/dev-only.ts @@ -3,7 +3,7 @@ import { defineComponent } from 'vue' export default defineComponent({ name: 'DevOnly', setup (_, props) { - if (process.dev) { + if (import.meta.dev) { return () => props.slots.default?.() } return () => props.slots.fallback?.() diff --git a/packages/nuxt/src/app/components/nuxt-error-boundary.ts b/packages/nuxt/src/app/components/nuxt-error-boundary.ts index a58516c1ce82..cb8d2f67071a 100644 --- a/packages/nuxt/src/app/components/nuxt-error-boundary.ts +++ b/packages/nuxt/src/app/components/nuxt-error-boundary.ts @@ -12,7 +12,7 @@ export default defineComponent({ const nuxtApp = useNuxtApp() onErrorCaptured((err, target, info) => { - if (process.client && !nuxtApp.isHydrating) { + if (import.meta.client && !nuxtApp.isHydrating) { emit('error', err) nuxtApp.hooks.callHook('vue:error', err, target, info) error.value = err diff --git a/packages/nuxt/src/app/components/nuxt-error-page.vue b/packages/nuxt/src/app/components/nuxt-error-page.vue index 0976b1a2f3e5..cf32d26835a3 100644 --- a/packages/nuxt/src/app/components/nuxt-error-page.vue +++ b/packages/nuxt/src/app/components/nuxt-error-page.vue @@ -36,11 +36,11 @@ const is404 = statusCode === 404 const statusMessage = _error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error') const description = _error.message || _error.toString() -const stack = process.dev && !is404 ? _error.description || `
${stacktrace}
` : undefined +const stack = import.meta.dev && !is404 ? _error.description || `
${stacktrace}
` : undefined // TODO: Investigate side-effect issue with imports const _Error404 = defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-404.vue').then(r => r.default || r)) -const _Error = process.dev +const _Error = import.meta.dev ? defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-dev.vue').then(r => r.default || r)) : defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-500.vue').then(r => r.default || r)) diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index 9f609fc5f664..3955b8d8ef07 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -23,7 +23,7 @@ const SLOTNAME_RE = /nuxt-ssr-slot-name="([^"]*)"/g const SLOT_FALLBACK_RE = /
]*><\/div>(((?!
]*>)[\s\S])*)
]*><\/div>/g let id = 0 -const getId = process.client ? () => (id++).toString() : randomUUID +const getId = import.meta.client ? () => (id++).toString() : randomUUID export default defineComponent({ name: 'NuxtIsland', @@ -54,7 +54,7 @@ export default defineComponent({ const instance = getCurrentInstance()! const event = useRequestEvent() // TODO: remove use of `$fetch.raw` when nitro 503 issues on windows dev server are resolved - const eventFetch = process.server ? event.fetch : process.dev ? $fetch.raw : globalThis.fetch + const eventFetch = import.meta.server ? event.fetch : import.meta.dev ? $fetch.raw : globalThis.fetch const mounted = ref(false) onMounted(() => { mounted.value = true }) @@ -62,7 +62,7 @@ export default defineComponent({ nuxtApp.payload.data[key] = { __nuxt_island: { key, - ...(process.server && process.env.prerender) + ...(import.meta.server && import.meta.prerender) ? {} : { params: { ...props.context, props: props.props ? JSON.stringify(props.props) : undefined } } }, @@ -71,7 +71,7 @@ export default defineComponent({ } const ssrHTML = ref('') - if (process.client) { + if (import.meta.client) { const renderedHTML = getFragmentHTML(instance.vnode?.el ?? null).join('') if (renderedHTML && nuxtApp.isHydrating) { setPayload(`${props.name}_${hashId.value}`, { @@ -111,19 +111,19 @@ export default defineComponent({ const url = remoteComponentIslands && props.source ? new URL(`/__nuxt_island/${key}`, props.source).href : `/__nuxt_island/${key}` - if (process.server && process.env.prerender) { + if (import.meta.server && import.meta.prerender) { // Hint to Nitro to prerender the island component appendResponseHeader(event, 'x-nitro-prerender', url) } // TODO: Validate response // $fetch handles the app.baseURL in dev - const r = await eventFetch(withQuery(process.dev && process.client ? url : joinURL(config.app.baseURL ?? '', url), { + const r = await eventFetch(withQuery(import.meta.dev && import.meta.client ? url : joinURL(config.app.baseURL ?? '', url), { ...props.context, props: props.props ? JSON.stringify(props.props) : undefined })) - const result = process.server || !process.dev ? await r.json() : (r as FetchResponse)._data + const result = import.meta.server || !import.meta.dev ? await r.json() : (r as FetchResponse)._data // TODO: support passing on more headers - if (process.server && process.env.prerender) { + if (import.meta.server && import.meta.prerender) { const hints = r.headers.get('x-nitro-prerender') if (hints) { appendResponseHeader(event, 'x-nitro-prerender', hints) @@ -149,7 +149,7 @@ export default defineComponent({ }) key.value++ error.value = null - if (process.client) { + if (import.meta.client) { // must await next tick for Teleport to work correctly with static node re-rendering await nextTick() } @@ -165,13 +165,13 @@ export default defineComponent({ }) } - if (process.client) { + if (import.meta.client) { watch(props, debounce(() => fetchComponent(), 100)) } - if (process.client && !nuxtApp.isHydrating && props.lazy) { + if (import.meta.client && !nuxtApp.isHydrating && props.lazy) { fetchComponent() - } else if (process.server || !nuxtApp.isHydrating) { + } else if (import.meta.server || !nuxtApp.isHydrating) { await fetchComponent() } @@ -182,10 +182,10 @@ export default defineComponent({ const nodes = [createVNode(Fragment, { key: key.value }, [h(createStaticVNode(html.value || '
', 1))])] - if (uid.value && (mounted.value || nuxtApp.isHydrating || process.server)) { + if (uid.value && (mounted.value || nuxtApp.isHydrating || import.meta.server)) { for (const slot in slots) { if (availableSlots.value.includes(slot)) { - nodes.push(createVNode(Teleport, { to: process.client ? `[nuxt-ssr-component-uid='${uid.value}'] [nuxt-ssr-slot-name='${slot}']` : `uid=${uid.value};slot=${slot}` }, { + nodes.push(createVNode(Teleport, { to: import.meta.client ? `[nuxt-ssr-component-uid='${uid.value}'] [nuxt-ssr-slot-name='${slot}']` : `uid=${uid.value};slot=${slot}` }, { default: () => (slotProps.value[slot] ?? [undefined]).map((data: any) => slots[slot]?.(data)) })) } diff --git a/packages/nuxt/src/app/components/nuxt-layout.ts b/packages/nuxt/src/app/components/nuxt-layout.ts index 79053a735586..82c321479dd8 100644 --- a/packages/nuxt/src/app/components/nuxt-layout.ts +++ b/packages/nuxt/src/app/components/nuxt-layout.ts @@ -57,7 +57,7 @@ export default defineComponent({ return () => { const hasLayout = layout.value && layout.value in layouts - if (process.dev && layout.value && !hasLayout && layout.value !== 'default') { + if (import.meta.dev && layout.value && !hasLayout && layout.value !== 'default') { console.warn(`Invalid layout \`${layout.value}\` selected.`) } @@ -112,7 +112,7 @@ const LayoutProvider = defineComponent({ } let vnode: VNode | undefined - if (process.dev && process.client) { + if (import.meta.dev && import.meta.client) { onMounted(() => { nextTick(() => { if (['#comment', '#text'].includes(vnode?.el?.nodeName)) { @@ -128,14 +128,14 @@ const LayoutProvider = defineComponent({ return () => { if (!name || (typeof name === 'string' && !(name in layouts))) { - if (process.dev && process.client && props.hasTransition) { + if (import.meta.dev && import.meta.client && props.hasTransition) { vnode = context.slots.default?.() as VNode | undefined return vnode } return context.slots.default?.() } - if (process.dev && process.client && props.hasTransition) { + if (import.meta.dev && import.meta.client && props.hasTransition) { vnode = h( // @ts-expect-error seems to be an issue in vue types LayoutLoader, diff --git a/packages/nuxt/src/app/components/nuxt-link.ts b/packages/nuxt/src/app/components/nuxt-link.ts index 4e89cd042daf..dd65580a2476 100644 --- a/packages/nuxt/src/app/components/nuxt-link.ts +++ b/packages/nuxt/src/app/components/nuxt-link.ts @@ -51,7 +51,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { const componentName = options.componentName || 'NuxtLink' const checkPropConflicts = (props: NuxtLinkProps, main: keyof NuxtLinkProps, sub: keyof NuxtLinkProps): void => { - if (process.dev && props[main] !== undefined && props[sub] !== undefined) { + if (import.meta.dev && props[main] !== undefined && props[sub] !== undefined) { console.warn(`[${componentName}] \`${main}\` and \`${sub}\` cannot be used together. \`${sub}\` will be ignored.`) } } @@ -198,10 +198,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) { // Prefetching const prefetched = ref(false) - const el = process.server ? undefined : ref(null) - const elRef = process.server ? undefined : (ref: any) => { el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el } + const el = import.meta.server ? undefined : ref(null) + const elRef = import.meta.server ? undefined : (ref: any) => { el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el } - if (process.client) { + if (import.meta.client) { checkPropConflicts(props, 'prefetch', 'noPrefetch') const shouldPrefetch = props.prefetch !== false && props.noPrefetch !== true && props.target !== '_blank' && !isSlowConnection() if (shouldPrefetch) { @@ -329,7 +329,7 @@ type CallbackFn = () => void type ObserveFn = (element: Element, callback: CallbackFn) => () => void function useObserver (): { observe: ObserveFn } | undefined { - if (process.server) { return } + if (import.meta.server) { return } const nuxtApp = useNuxtApp() if (nuxtApp._observer) { @@ -370,7 +370,7 @@ function useObserver (): { observe: ObserveFn } | undefined { } function isSlowConnection () { - if (process.server) { return } + if (import.meta.server) { return } // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection const cn = (navigator as any).connection as { saveData: boolean, effectiveType: string } | null diff --git a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts index 104523e60100..011c2899b24b 100644 --- a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts +++ b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts @@ -101,7 +101,7 @@ function useLoadingIndicator (opts: { function start () { clear() progress.value = 0 - if (opts.throttle && process.client) { + if (opts.throttle && import.meta.client) { _throttle = setTimeout(() => { isLoading.value = true _startTimer() @@ -129,7 +129,7 @@ function useLoadingIndicator (opts: { function _hide () { clear() - if (process.client) { + if (import.meta.client) { setTimeout(() => { isLoading.value = false setTimeout(() => { progress.value = 0 }, 400) @@ -138,7 +138,7 @@ function useLoadingIndicator (opts: { } function _startTimer () { - if (process.client) { + if (import.meta.client) { _timer = setInterval(() => { _increase(step.value) }, 100) } } diff --git a/packages/nuxt/src/app/components/nuxt-root.vue b/packages/nuxt/src/app/components/nuxt-root.vue index c39c0d704196..80a9d38ac130 100644 --- a/packages/nuxt/src/app/components/nuxt-root.vue +++ b/packages/nuxt/src/app/components/nuxt-root.vue @@ -16,23 +16,23 @@ import { PageRouteSymbol } from '#app/components/injections' import AppComponent from '#build/app-component.mjs' import ErrorComponent from '#build/error-component.mjs' -const IslandRenderer = process.server +const IslandRenderer = import.meta.server ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r)) : () => null const nuxtApp = useNuxtApp() const onResolve = nuxtApp.deferHydration() -const url = process.server ? nuxtApp.ssrContext.url : window.location.pathname -const SingleRenderer = process.test && process.dev && process.server && url.startsWith('/__nuxt_component_test__/') && /* #__PURE__ */ defineAsyncComponent(() => import('#build/test-component-wrapper.mjs') - .then(r => r.default(process.server ? url : window.location.href))) +const url = import.meta.server ? nuxtApp.ssrContext.url : window.location.pathname +const SingleRenderer = import.meta.test && import.meta.dev && import.meta.server && url.startsWith('/__nuxt_component_test__/') && /* #__PURE__ */ defineAsyncComponent(() => import('#build/test-component-wrapper.mjs') + .then(r => r.default(import.meta.server ? url : window.location.href))) // Inject default route (outside of pages) as active route provide(PageRouteSymbol, useRoute()) // vue:setup hook const results = nuxtApp.hooks.callHookWith(hooks => hooks.map(hook => hook()), 'vue:setup') -if (process.dev && results && results.some(i => i && 'then' in i)) { +if (import.meta.dev && results && results.some(i => i && 'then' in i)) { console.error('[nuxt] Error in `vue:setup`. Callbacks must be synchronous.') } @@ -40,7 +40,7 @@ if (process.dev && results && results.some(i => i && 'then' in i)) { const error = useError() onErrorCaptured((err, target, info) => { nuxtApp.hooks.callHook('vue:error', err, target, info).catch(hookError => console.error('[nuxt] Error in `vue:error` hook', hookError)) - if (process.server || (isNuxtError(err) && (err.fatal || err.unhandled))) { + if (import.meta.server || (isNuxtError(err) && (err.fatal || err.unhandled))) { const p = nuxtApp.runWithContext(() => showError(err)) onServerPrefetch(() => p) return false // suppress error from breaking render @@ -48,5 +48,5 @@ onErrorCaptured((err, target, info) => { }) // Component islands context -const { islandContext } = process.server && nuxtApp.ssrContext +const islandContext = import.meta.server && nuxtApp.ssrContext.islandContext diff --git a/packages/nuxt/src/app/components/route-provider.ts b/packages/nuxt/src/app/components/route-provider.ts index d24b807aad49..5db44c3f7954 100644 --- a/packages/nuxt/src/app/components/route-provider.ts +++ b/packages/nuxt/src/app/components/route-provider.ts @@ -36,7 +36,7 @@ export const RouteProvider = defineComponent({ provide(PageRouteSymbol, shallowReactive(route)) let vnode: VNode - if (process.dev && process.client && props.trackRootNodes) { + if (import.meta.dev && import.meta.client && props.trackRootNodes) { onMounted(() => { nextTick(() => { if (['#comment', '#text'].includes(vnode?.el?.nodeName)) { @@ -48,7 +48,7 @@ export const RouteProvider = defineComponent({ } return () => { - if (process.dev && process.client) { + if (import.meta.dev && import.meta.client) { vnode = h(props.vnode, { ref: props.vnodeRef }) return vnode } diff --git a/packages/nuxt/src/app/components/utils.ts b/packages/nuxt/src/app/components/utils.ts index d95ed64f50e6..cc7c5e741cd9 100644 --- a/packages/nuxt/src/app/components/utils.ts +++ b/packages/nuxt/src/app/components/utils.ts @@ -73,7 +73,7 @@ export function vforToArray (source: any): any[] { } else if (isString(source)) { return source.split('') } else if (typeof source === 'number') { - if (process.dev && !Number.isInteger(source)) { + if (import.meta.dev && !Number.isInteger(source)) { console.warn(`The v-for range expect an integer value but got ${source}.`) } const array = [] diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index 817c7d0432b2..b086e705bc86 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -222,7 +222,7 @@ export function useAsyncData< const fetchOnServer = options.server !== false && nuxt.payload.serverRendered // Server side - if (process.server && fetchOnServer && options.immediate) { + if (import.meta.server && fetchOnServer && options.immediate) { const promise = initialFetch() if (getCurrentInstance()) { onServerPrefetch(() => promise) @@ -232,7 +232,7 @@ export function useAsyncData< } // Client side - if (process.client) { + if (import.meta.client) { // Setup hook callbacks once per instance const instance = getCurrentInstance() if (instance && !instance._nuxtOnBeforeMountCbs) { @@ -349,7 +349,7 @@ export function useNuxtData (key: string): { data: Ref { - if (process.server) { + if (import.meta.server) { return Promise.resolve() } diff --git a/packages/nuxt/src/app/composables/chunk.ts b/packages/nuxt/src/app/composables/chunk.ts index 1e0c1e4f1301..9bdb5ea34f84 100644 --- a/packages/nuxt/src/app/composables/chunk.ts +++ b/packages/nuxt/src/app/composables/chunk.ts @@ -29,7 +29,7 @@ export interface ReloadNuxtAppOptions { } export function reloadNuxtApp (options: ReloadNuxtAppOptions = {}) { - if (process.server) { return } + if (import.meta.server) { return } const path = options.path || window.location.pathname let handledPath: Record = {} diff --git a/packages/nuxt/src/app/composables/component.ts b/packages/nuxt/src/app/composables/component.ts index 175dabc83278..5bfcc992ea41 100644 --- a/packages/nuxt/src/app/composables/component.ts +++ b/packages/nuxt/src/app/composables/component.ts @@ -22,7 +22,7 @@ async function runLegacyAsyncData (res: Record | Promise (name: string, _opts?: const cookie = ref(cookies[name] as any ?? opts.default?.()) - if (process.client) { + if (import.meta.client) { const channel = typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(`nuxt:cookies:${name}`) if (getCurrentInstance()) { onUnmounted(() => { channel?.close() }) } @@ -61,7 +61,7 @@ export function useCookie (name: string, _opts?: } else { callback() } - } else if (process.server) { + } else if (import.meta.server) { const nuxtApp = useNuxtApp() const writeFinalCookieValue = () => { if (!isEqual(cookie.value, cookies[name])) { @@ -79,9 +79,9 @@ export function useCookie (name: string, _opts?: } function readRawCookies (opts: CookieOptions = {}): Record | undefined { - if (process.server) { + if (import.meta.server) { return parse(useRequestEvent()?.node.req.headers.cookie || '', opts) - } else if (process.client) { + } else if (import.meta.client) { return parse(document.cookie, opts) } } @@ -94,7 +94,7 @@ function serializeCookie (name: string, value: any, opts: CookieSerializeOptions } function writeClientCookie (name: string, value: any, opts: CookieSerializeOptions = {}) { - if (process.client) { + if (import.meta.client) { document.cookie = serializeCookie(name, value, opts) } } diff --git a/packages/nuxt/src/app/composables/error.ts b/packages/nuxt/src/app/composables/error.ts index b23fcd32ee57..4a59bc6a7a7c 100644 --- a/packages/nuxt/src/app/composables/error.ts +++ b/packages/nuxt/src/app/composables/error.ts @@ -14,7 +14,7 @@ export const showError = (_err: string | Error | Partial) => { try { const nuxtApp = useNuxtApp() const error = useError() - if (process.client) { + if (import.meta.client) { nuxtApp.hooks.callHook('app:error', err) } error.value = error.value || err diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index a2c84fbc5e51..e70a1d690778 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -134,7 +134,7 @@ export function useFetch< const isLocalFetch = typeof _request.value === 'string' && _request.value.startsWith('/') let _$fetch = opts.$fetch || globalThis.$fetch // Use fetch with request context and headers for server direct API calls - if (process.server && !opts.$fetch && isLocalFetch) { + if (import.meta.server && !opts.$fetch && isLocalFetch) { _$fetch = useRequestFetch() } diff --git a/packages/nuxt/src/app/composables/hydrate.ts b/packages/nuxt/src/app/composables/hydrate.ts index 447318d76a2b..3aa4053402c0 100644 --- a/packages/nuxt/src/app/composables/hydrate.ts +++ b/packages/nuxt/src/app/composables/hydrate.ts @@ -11,13 +11,13 @@ import type { NuxtPayload } from '#app' export const useHydration = (key: K, get: () => T, set: (value: T) => void) => { const nuxt = useNuxtApp() - if (process.server) { + if (import.meta.server) { nuxt.hooks.hook('app:rendered', () => { nuxt.payload[key] = get() }) } - if (process.client) { + if (import.meta.client) { nuxt.hooks.hook('app:created', () => { set(nuxt.payload[key] as T) }) diff --git a/packages/nuxt/src/app/composables/payload.ts b/packages/nuxt/src/app/composables/payload.ts index 219f03582f7e..1cff4e8a3678 100644 --- a/packages/nuxt/src/app/composables/payload.ts +++ b/packages/nuxt/src/app/composables/payload.ts @@ -13,7 +13,7 @@ interface LoadPayloadOptions { } export function loadPayload (url: string, opts: LoadPayloadOptions = {}): Record | Promise> | null { - if (process.server) { return null } + if (import.meta.server) { return null } const payloadURL = _getPayloadURL(url, opts) const nuxtApp = useNuxtApp() const cache = nuxtApp._payloadCache = nuxtApp._payloadCache || {} @@ -55,7 +55,7 @@ function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) { } async function _importPayload (payloadURL: string) { - if (process.server) { return null } + if (import.meta.server) { return null } try { return renderJsonPayloads ? parsePayload(await fetch(payloadURL).then(res => res.text())) @@ -74,7 +74,7 @@ export function isPrerendered () { let payloadCache: any = null export async function getNuxtClientPayload () { - if (process.server) { + if (import.meta.server) { return } if (payloadCache) { @@ -110,7 +110,7 @@ export function definePayloadReducer ( name: string, reduce: (data: any) => any ) { - if (process.server) { + if (import.meta.server) { useNuxtApp().ssrContext!._payloadReducers[name] = reduce } } @@ -124,10 +124,10 @@ export function definePayloadReviver ( name: string, revive: (data: string) => any | undefined ) { - if (process.dev && getCurrentInstance()) { + if (import.meta.dev && getCurrentInstance()) { console.warn('[nuxt] [definePayloadReviver] This function must be called in a Nuxt plugin that is `unshift`ed to the beginning of the Nuxt plugins array.') } - if (process.client) { + if (import.meta.client) { useNuxtApp()._payloadRevivers[name] = revive } } diff --git a/packages/nuxt/src/app/composables/preload.ts b/packages/nuxt/src/app/composables/preload.ts index 6710ae2b8210..b012accc51c8 100644 --- a/packages/nuxt/src/app/composables/preload.ts +++ b/packages/nuxt/src/app/composables/preload.ts @@ -9,7 +9,7 @@ import { useRouter } from './router' * @param components Pascal-cased name or names of components to prefetch */ export const preloadComponents = async (components: string | string[]) => { - if (process.server) { return } + if (import.meta.server) { return } const nuxtApp = useNuxtApp() components = Array.isArray(components) ? components : [components] @@ -35,7 +35,7 @@ function _loadAsyncComponent (component: Component) { } export async function preloadRouteComponents (to: RouteLocationRaw, router: Router & { _routePreloaded?: Set; _preloadPromises?: Array> } = useRouter()): Promise { - if (process.server) { return } + if (import.meta.server) { return } const { path, matched } = router.resolve(to) diff --git a/packages/nuxt/src/app/composables/ready.ts b/packages/nuxt/src/app/composables/ready.ts index 58143d18403d..a30d0d7cafef 100644 --- a/packages/nuxt/src/app/composables/ready.ts +++ b/packages/nuxt/src/app/composables/ready.ts @@ -2,7 +2,7 @@ import { useNuxtApp } from '../nuxt' import { requestIdleCallback } from '../compat/idle-callback' export const onNuxtReady = (callback: () => any) => { - if (process.server) { return } + if (import.meta.server) { return } const nuxtApp = useNuxtApp() if (nuxtApp.isHydrating) { diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index 126381ce496e..0ffead1cdd48 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -17,7 +17,7 @@ export const useRouter: typeof _useRouter = () => { } export const useRoute: typeof _useRoute = () => { - if (process.dev && isProcessingMiddleware()) { + if (import.meta.dev && isProcessingMiddleware()) { console.warn('[nuxt] Calling `useRoute` within middleware may lead to misleading results. Instead, use the (to, from) arguments passed to the middleware to access the new and old routes.') } if (hasInjectionContext()) { @@ -118,7 +118,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na // Early open handler if (options?.open) { - if (process.client) { + if (import.meta.client) { const { target = '_blank', windowFeatures = {} } = options.open const features = Object.entries(windowFeatures) @@ -146,7 +146,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na const inMiddleware = isProcessingMiddleware() // Early redirect on client-side - if (process.client && !isExternal && inMiddleware) { + if (import.meta.client && !isExternal && inMiddleware) { return to } @@ -154,7 +154,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na const nuxtApp = useNuxtApp() - if (process.server) { + if (import.meta.server) { if (nuxtApp.ssrContext) { const fullPath = typeof to === 'string' || isExternal ? toPath : router.resolve(to).fullPath || '/' const location = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, fullPath) @@ -206,7 +206,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na /** This will abort navigation within a Nuxt route middleware handler. */ export const abortNavigation = (err?: string | Partial) => { - if (process.dev && !isProcessingMiddleware()) { + if (import.meta.dev && !isProcessingMiddleware()) { throw new Error('abortNavigation() is only usable inside a route middleware handler.') } @@ -222,18 +222,18 @@ export const abortNavigation = (err?: string | Partial) => { } export const setPageLayout = (layout: unknown extends PageMeta['layout'] ? string : PageMeta['layout']) => { - if (process.server) { - if (process.dev && getCurrentInstance() && useState('_layout').value !== layout) { + if (import.meta.server) { + if (import.meta.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 && nuxtApp.payload.serverRendered && useState('_layout').value !== layout) { + if (import.meta.dev && nuxtApp.isHydrating && nuxtApp.payload.serverRendered && 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) { + if (inMiddleware || import.meta.server || nuxtApp.isHydrating) { const unsubscribe = useRouter().beforeResolve((to) => { to.meta.layout = layout as Exclude unsubscribe() diff --git a/packages/nuxt/src/app/composables/ssr.ts b/packages/nuxt/src/app/composables/ssr.ts index 14d4e1c67895..c72e3c137362 100644 --- a/packages/nuxt/src/app/composables/ssr.ts +++ b/packages/nuxt/src/app/composables/ssr.ts @@ -6,7 +6,7 @@ import { useNuxtApp } from '../nuxt' export function useRequestHeaders (include: K[]): { [key in Lowercase]?: string } export function useRequestHeaders (): Readonly> export function useRequestHeaders (include?: any[]) { - if (process.client) { return {} } + if (import.meta.client) { return {} } const headers = useNuxtApp().ssrContext?.event.node.req.headers ?? {} if (!include) { return headers } return Object.fromEntries(include.map(key => key.toLowerCase()).filter(key => headers[key]).map(key => [key, headers[key]])) @@ -17,7 +17,7 @@ export function useRequestEvent (nuxtApp: NuxtApp = useNuxtApp()): H3Event { } export function useRequestFetch (): typeof global.$fetch { - if (process.client) { + if (import.meta.client) { return globalThis.$fetch } const event = useNuxtApp().ssrContext?.event as H3Event @@ -28,7 +28,7 @@ export function setResponseStatus (event: H3Event, code?: number, message?: stri /** @deprecated Pass `event` as first option. */ export function setResponseStatus (code: number, message?: string): void export function setResponseStatus (arg1: H3Event | number | undefined, arg2?: number | string, arg3?: string) { - if (process.client) { return } + if (import.meta.client) { return } if (arg1 && typeof arg1 !== 'number') { return _setResponseStatus(arg1, arg2 as number | undefined, arg3) } diff --git a/packages/nuxt/src/app/composables/url.ts b/packages/nuxt/src/app/composables/url.ts index 4f43ba8481c3..784ef860cd35 100644 --- a/packages/nuxt/src/app/composables/url.ts +++ b/packages/nuxt/src/app/composables/url.ts @@ -4,7 +4,7 @@ import { useRequestEvent } from './ssr' import { useRuntimeConfig } from '#app' export function useRequestURL () { - if (process.server) { + if (import.meta.server) { const url = getRequestURL(useRequestEvent()) url.pathname = joinURL(useRuntimeConfig().app.baseURL, url.pathname) return url diff --git a/packages/nuxt/src/app/config.ts b/packages/nuxt/src/app/config.ts index 77efe98805a9..3b8a86a2bce4 100644 --- a/packages/nuxt/src/app/config.ts +++ b/packages/nuxt/src/app/config.ts @@ -38,7 +38,7 @@ function deepAssign (obj: any, newObj: any) { export function useAppConfig (): AppConfig { const nuxtApp = useNuxtApp() if (!nuxtApp._appConfig) { - nuxtApp._appConfig = (process.server ? klona(__appConfig) : reactive(__appConfig)) as AppConfig + nuxtApp._appConfig = (import.meta.server ? klona(__appConfig) : reactive(__appConfig)) as AppConfig } return nuxtApp._appConfig } @@ -54,7 +54,7 @@ export function updateAppConfig (appConfig: DeepPartial) { } // HMR Support -if (process.dev) { +if (import.meta.dev) { function applyHMR (newConfig: AppConfig) { const appConfig = useAppConfig() if (newConfig && appConfig) { diff --git a/packages/nuxt/src/app/entry.async.ts b/packages/nuxt/src/app/entry.async.ts index 4d5b6206ab06..783151a0628c 100644 --- a/packages/nuxt/src/app/entry.async.ts +++ b/packages/nuxt/src/app/entry.async.ts @@ -1,10 +1,10 @@ import type { CreateOptions } from '#app' -const entry = process.server +const entry = import.meta.server ? (ctx?: CreateOptions['ssrContext']) => import('#app/entry').then(m => m.default(ctx)) : () => import('#app/entry').then(m => m.default) -if (process.client) { +if (import.meta.client) { entry() } diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index be990030b9d5..610f1875ebea 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -26,7 +26,7 @@ if (!globalThis.$fetch) { let entry: Function -if (process.server) { +if (import.meta.server) { entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext']) { const vueApp = createApp(RootComponent) @@ -45,10 +45,10 @@ if (process.server) { } } -if (process.client) { +if (import.meta.client) { // TODO: temporary webpack 5 HMR fix // https://github.com/webpack-contrib/webpack-hot-middleware/issues/390 - if (process.dev && import.meta.webpackHot) { + if (import.meta.dev && import.meta.webpackHot) { import.meta.webpackHot.accept() } diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index 9a104a161325..93c5ebc9d83b 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -210,13 +210,13 @@ export function createNuxtApp (options: CreateOptions) { data: {}, state: {}, _errors: {}, - ...(process.client ? window.__NUXT__ ?? {} : { serverRendered: true }) + ...(import.meta.client ? window.__NUXT__ ?? {} : { serverRendered: true }) }), static: { data: {} }, runWithContext: (fn: any) => callWithNuxt(nuxtApp, fn), - isHydrating: process.client, + isHydrating: import.meta.client, deferHydration () { if (!nuxtApp.isHydrating) { return () => {} } @@ -244,7 +244,7 @@ export function createNuxtApp (options: CreateOptions) { nuxtApp.hooks = createHooks() nuxtApp.hook = nuxtApp.hooks.hook - if (process.server) { + if (import.meta.server) { async function contextCaller (hooks: HookCallback[], args: any[]) { for (const hook of hooks) { await nuxtApp.runWithContext(() => hook(...args)) @@ -267,7 +267,7 @@ export function createNuxtApp (options: CreateOptions) { defineGetter(nuxtApp.vueApp, '$nuxt', nuxtApp) defineGetter(nuxtApp.vueApp.config.globalProperties, '$nuxt', nuxtApp) - if (process.server) { + if (import.meta.server) { if (nuxtApp.ssrContext) { // Expose nuxt to the renderContext nuxtApp.ssrContext.nuxt = nuxtApp @@ -291,7 +291,7 @@ export function createNuxtApp (options: CreateOptions) { } // Listen to chunk load errors - if (process.client) { + if (import.meta.client) { window.addEventListener('nuxt.preloadError', (event) => { nuxtApp.callHook('app:chunkError', { error: (event as Event & { payload: Error }).payload }) }) @@ -305,7 +305,7 @@ export function createNuxtApp (options: CreateOptions) { } // Expose runtime config - const runtimeConfig = process.server ? options.ssrContext!.runtimeConfig : reactive(nuxtApp.payload.config!) + const runtimeConfig = import.meta.server ? options.ssrContext!.runtimeConfig : reactive(nuxtApp.payload.config!) nuxtApp.provide('config', runtimeConfig) return nuxtApp @@ -329,7 +329,7 @@ export async function applyPlugins (nuxtApp: NuxtApp, plugins: Array[] = [] const errors: Error[] = [] for (const plugin of plugins) { - if (process.server && nuxtApp.ssrContext?.islandContext && plugin.env?.islands === false) { continue } + if (import.meta.server && nuxtApp.ssrContext?.islandContext && plugin.env?.islands === false) { continue } const promise = applyPlugin(nuxtApp, plugin) if (plugin.parallel) { parallels.push(promise.catch(e => errors.push(e))) @@ -363,7 +363,7 @@ export function isNuxtPlugin (plugin: unknown) { */ export function callWithNuxt any> (nuxt: NuxtApp | _NuxtApp, setup: T, args?: Parameters) { const fn: () => ReturnType = () => args ? setup(...args as Parameters) : setup() - if (process.server) { + if (import.meta.server) { return nuxt.vueApp.runWithContext(() => nuxtAppCtx.callAsync(nuxt as NuxtApp, fn)) } else { // In client side we could assume nuxt app is singleton @@ -385,7 +385,7 @@ export function useNuxtApp (): NuxtApp { nuxtAppInstance = nuxtAppInstance || nuxtAppCtx.tryUse() if (!nuxtAppInstance) { - if (process.dev) { + if (import.meta.dev) { throw new Error('[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at `https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables`.') } else { throw new Error('[nuxt] instance unavailable') diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index ae4ba74952e9..06c5764c317f 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -99,7 +99,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ name: 'nuxt:router', enforce: 'pre', setup (nuxtApp) { - const initialURL = process.client + const initialURL = import.meta.client ? withoutBase(window.location.pathname, useRuntimeConfig().app.baseURL) + window.location.search + window.location.hash : nuxtApp.ssrContext!.url @@ -138,7 +138,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ } // Perform navigation Object.assign(route, to) - if (process.client) { + if (import.meta.client) { window.history[replace ? 'replaceState' : 'pushState']({}, '', joinURL(baseURL, to.fullPath)) if (!nuxtApp.isHydrating) { // Clear any existing errors @@ -150,7 +150,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ await middleware(to, route) } } catch (err) { - if (process.dev && !hooks.error.length) { + if (import.meta.dev && !hooks.error.length) { console.warn('No error handlers registered to handle middleware errors. You can register an error handler with `router.onError()`', err) } for (const handler of hooks.error) { @@ -211,7 +211,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ } }) - if (process.client) { + if (import.meta.client) { window.addEventListener('popstate', (event) => { const location = (event.target as Window).location router.replace(location.href.replace(location.origin, '')) @@ -235,12 +235,12 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ } nuxtApp._processingMiddleware = true - if (process.client || !nuxtApp.ssrContext?.islandContext) { + if (import.meta.client || !nuxtApp.ssrContext?.islandContext) { const middlewareEntries = new Set([...globalMiddleware, ...nuxtApp._middleware.global]) for (const middleware of middlewareEntries) { const result = await nuxtApp.runWithContext(() => middleware(to, from)) - if (process.server) { + if (import.meta.server) { if (result === false || result instanceof Error) { const error = result || createError({ statusCode: 404, diff --git a/packages/nuxt/src/app/types/augments.d.ts b/packages/nuxt/src/app/types/augments.d.ts index d93c85760c35..8a6c9c82d875 100644 --- a/packages/nuxt/src/app/types/augments.d.ts +++ b/packages/nuxt/src/app/types/augments.d.ts @@ -1,17 +1,20 @@ import type { NuxtApp, useNuxtApp } from '../nuxt' +interface NuxtStaticBuildFlags { + browser: boolean + client: boolean + dev: boolean + server: boolean + test: boolean +} + declare global { namespace NodeJS { - interface Process { - browser: boolean - client: boolean - dev: boolean - mode: 'spa' | 'universal' - server: boolean - static: boolean - } + interface Process extends NuxtStaticBuildFlags {} } + interface ImportMeta extends NuxtStaticBuildFlags {} + interface Window { __NUXT__?: Record useNuxtApp?: typeof useNuxtApp diff --git a/packages/nuxt/src/core/runtime/nitro/error.ts b/packages/nuxt/src/core/runtime/nitro/error.ts index 22d77781cde8..1a0fc620231f 100644 --- a/packages/nuxt/src/core/runtime/nitro/error.ts +++ b/packages/nuxt/src/core/runtime/nitro/error.ts @@ -15,7 +15,7 @@ export default async function errorhandler (error: H3Error, statusCode, statusMessage, message, - stack: process.dev && statusCode !== 404 + stack: import.meta.dev && statusCode !== 404 ? `
${stack.map(i => `${i.text}`).join('\n')}
` : '', data: error.data @@ -56,12 +56,12 @@ export default async function errorhandler (error: H3Error, // Fallback to static rendered error page if (!res) { - const { template } = process.dev + const { template } = import.meta.dev // @ts-expect-error TODO: add legacy type support for subpath imports ? await import('@nuxt/ui-templates/templates/error-dev.mjs') // @ts-expect-error TODO: add legacy type support for subpath imports : await import('@nuxt/ui-templates/templates/error-500.mjs') - if (process.dev) { + if (import.meta.dev) { // TODO: Support `message` in template (errorObject as any).description = errorObject.message } diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index da1bcbfd6e49..bec792f22f7b 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -108,7 +108,7 @@ const getSSRRenderer = lazyCachedFunction(async () => { async function renderToString (input: RenderToStringParams[0], context: RenderToStringParams[1]) { const html = await _renderToString(input, context) // In development with vite-node, the manifest is on-demand and will be available after rendering - if (process.dev && process.env.NUXT_VITE_NODE_OPTIONS) { + if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) { renderer.rendererContext.updateManifest(await getClientManifest()) } return `<${appRootTag} id="${appRootId}">${html}` @@ -155,14 +155,14 @@ const getSPARenderer = lazyCachedFunction(async () => { } }) -const payloadCache = process.env.prerender ? useStorage('internal:nuxt:prerender:payload') : null -const islandCache = process.env.prerender ? useStorage('internal:nuxt:prerender:island') : null -const islandPropCache = process.env.prerender ? useStorage('internal:nuxt:prerender:island-props') : null +const payloadCache = import.meta.prerender ? useStorage('internal:nuxt:prerender:payload') : null +const islandCache = import.meta.prerender ? useStorage('internal:nuxt:prerender:island') : null +const islandPropCache = import.meta.prerender ? useStorage('internal:nuxt:prerender:island-props') : null async function getIslandContext (event: H3Event): Promise { // TODO: Strict validation for url let url = event.node.req.url || '' - if (process.env.prerender && event.node.req.url && await islandPropCache!.hasItem(event.node.req.url)) { + if (import.meta.prerender && event.node.req.url && await islandPropCache!.hasItem(event.node.req.url)) { // rehydrate props from cache so we can rerender island if cache does not have it any more url = await islandPropCache!.getItem(event.node.req.url) as string } @@ -213,7 +213,7 @@ export default defineRenderHandler(async (event): Promise> } @@ -225,7 +225,7 @@ export default defineRenderHandler(async (event): Promise> } } @@ -245,7 +245,7 @@ export default defineRenderHandler(async (event): Promise { - if (process.dev) { + if (import.meta.dev) { const defaultSlot = slots.default?.() if (defaultSlot && (defaultSlot.length > 1 || typeof defaultSlot[0].children !== 'string')) { @@ -217,7 +217,7 @@ export const Style = defineComponent({ const style = { ...props } const textContent = slots.default?.()?.[0]?.children if (textContent) { - if (process.dev && typeof textContent !== 'string') { + if (import.meta.dev && typeof textContent !== 'string') { console.error('