Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: opt in to import.meta.* properties #2597

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions src/runtime/composables/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useContentHead = (
const title = head.title || data?.title
if (title) {
head.title = title
if (process.server && !head.meta.some(m => m.property === 'og:title')) {
if (import.meta.server && !head.meta.some(m => m.property === 'og:title')) {
head.meta.push({
property: 'og:title',
content: title as string
Expand All @@ -35,14 +35,14 @@ export const useContentHead = (
}

const host = config.public.content.host
// if (process.server && !host) {
// if (import.meta.server && !host) {
// const req = useRequestEvent().node?.req
// if (req && req.headers.host !== 'localhost') {
// const protocol = req.headers['x-forwarded-proto'] || req.connection.encrypted ? 'https' : 'http'
// host = `${protocol}://${req.headers.host}`
// }
// }
if (process.server && host) {
if (import.meta.server && host) {
const _url = joinURL(host ?? '/', config.app.baseURL, to.fullPath)
const url = config.public.content.trailingSlash ? withTrailingSlash(_url) : withoutTrailingSlash(_url)
if (!head.meta.some(m => m.property === 'og:url')) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export const useContentHead = (
content: description
})
}
if (process.server && description && !head.meta.some(m => m.property === 'og:description')) {
if (import.meta.server && description && !head.meta.some(m => m.property === 'og:description')) {
head.meta.push({
property: 'og:description',
content: description
Expand All @@ -82,7 +82,7 @@ export const useContentHead = (
const image = head?.image || data?.image

// Shortcut for head.image to og:image in meta
if (process.server && image && head.meta.filter(m => m.property === 'og:image').length === 0) {
if (import.meta.server && image && head.meta.filter(m => m.property === 'og:image').length === 0) {
// Handles `image: '/image/src.jpg'`
if (typeof image === 'string') {
head.meta.push({
Expand Down Expand Up @@ -125,7 +125,7 @@ export const useContentHead = (
}

// @ts-ignore
if (process.client) { nextTick(() => useHead(head)) } else { useHead(head) }
if (import.meta.client) { nextTick(() => useHead(head)) } else { useHead(head) }
}

watch(() => unref(_content), refreshHead, { immediate: true })
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const fetchContentNavigation = async (queryBuilder?: QueryBuilder | Query
: withContentBase(process.dev ? `/navigation/${hash(params)}` : `/navigation/${hash(params)}.${content.integrity}.json`)

// Add `prefetch` to `<head>` in production
if (!process.dev && process.server) {
if (!process.dev && import.meta.server) {
addPrerenderPath(apiPath)
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/composables/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let showWarning = true
export const useContentPreview = () => {
const getPreviewToken = () => {
return useCookie('previewToken').value ||
(process.client && sessionStorage.getItem('previewToken')) ||
(import.meta.client && sessionStorage.getItem('previewToken')) ||
undefined
}

Expand All @@ -14,7 +14,7 @@ export const useContentPreview = () => {

useRoute().query.preview = token || ''

if (process.client) {
if (import.meta.client) {
if (token) {
sessionStorage.setItem('previewToken', token)
} else {
Expand Down Expand Up @@ -42,7 +42,7 @@ export const useContentPreview = () => {
return true
}

if (process.client && sessionStorage.getItem('previewToken')) {
if (import.meta.client && sessionStorage.getItem('previewToken')) {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const createQueryFetch = <T = ParsedContent>() => async (query: ContentQu
: withContentBase(process.dev ? '/query' : `/query/${hash(params)}.${content.integrity}.json`)

// Prefetch the query
if (!process.dev && process.server) {
if (!process.dev && import.meta.server) {
addPrerenderPath(apiPath)
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const addPrerenderPath = (path: string) => {

export const shouldUseClientDB = () => {
const { experimental } = useRuntimeConfig().public.content
if (process.server) { return false }
if (import.meta.server) { return false }
if (experimental.clientDB) { return true }

return useContentPreview().isEnabled()
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/legacy/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const fetchContentNavigation = async (queryBuilder?: QueryBuilder | Query
: withContentBase(process.dev ? `/navigation/${hash(params)}` : `/navigation/${hash(params)}.${content.integrity}.json`)

// Add `prefetch` to `<head>` in production
if (!process.dev && process.server) {
if (!process.dev && import.meta.server) {
addPrerenderPath(apiPath)
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/legacy/composables/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const createQueryFetch = <T = ParsedContent>() => async (query: QueryBuil
: withContentBase(process.dev ? '/query' : `/query/${hash(params)}.${content.integrity}.json`)

// Prefetch the query
if (!process.dev && process.server) {
if (!process.dev && import.meta.server) {
addPrerenderPath(apiPath)
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/legacy/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default defineNuxtPlugin((nuxt) => {
}

// Prefetch page content
if (process.client) {
if (import.meta.client) {
const router = useRouter()
nuxt.hook('link:prefetch', (link) => {
if (!(link in pages.value) && !hasProtocol(link)) {
Expand All @@ -275,7 +275,7 @@ export default defineNuxtPlugin((nuxt) => {
// Route middleware
addRouteMiddleware(async (to, from) => {
// Avoid calling on hash change
if (process.client && !isClientDBEnabled && to.path === from.path) {
if (import.meta.client && !isClientDBEnabled && to.path === from.path) {
if (!to.meta.layout) {
const _path = withoutTrailingSlash(to.path)
if (pages.value[_path]) {
Expand All @@ -297,7 +297,7 @@ export default defineNuxtPlugin((nuxt) => {
})

// @ts-ignore - Refresh on client-side
nuxt.hook('app:data:refresh', async () => process.client && await refresh(useRoute(), true))
nuxt.hook('app:data:refresh', async () => import.meta.client && await refresh(useRoute(), true))
})

function prefetchBodyComponents (nodes: MarkdownNode[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { contentHead } = useRuntimeConfig().public.content
const { page, layout } = useContent()

// Page not found, set correct status code on SSR
if (!(page as any).value && process.server) {
if (!(page as any).value && import.meta.server) {
const event = useRequestEvent()
event.res.statusCode = 404
}
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default defineNuxtPlugin((nuxt) => {
}

// Prefetch page content
if (process.client) {
if (import.meta.client) {
const router = useRouter()
nuxt.hook('link:prefetch', (link) => {
if (!(link in pages.value) && !hasProtocol(link)) {
Expand All @@ -256,7 +256,7 @@ export default defineNuxtPlugin((nuxt) => {
// Route middleware
addRouteMiddleware(async (to, from) => {
// Avoid calling on hash change
if (process.client && !isClientDBEnabled && to.path === from.path) {
if (import.meta.client && !isClientDBEnabled && to.path === from.path) {
if (!to.meta.layout) {
const _path = withoutTrailingSlash(to.path)
if (pages.value[_path]) {
Expand All @@ -278,7 +278,7 @@ export default defineNuxtPlugin((nuxt) => {
})

// @ts-ignore - Refresh on client-side
nuxt.hook('app:data:refresh', async () => process.client && await refresh(useRoute(), true))
nuxt.hook('app:data:refresh', async () => import.meta.client && await refresh(useRoute(), true))
})

function prefetchBodyComponents (nodes: MarkdownNode[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/plugins/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
export default defineNuxtPlugin(() => {
const publicConfig = useRuntimeConfig().public

if (process.client && publicConfig.content.wsUrl) {
if (import.meta.client && publicConfig.content.wsUrl) {
// Connect to websocket
import('../composables/web-socket').then(({ useContentWebSocket }) => useContentWebSocket())
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/transformers/component-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineTransformer({
name: 'component-resolver',
extensions: ['.*'],
async transform (content, options = {}) {
if (process.server) {
if (import.meta.server) {
// This transformer is only needed on client side to resolve components
return content
}
Expand Down
Loading