Skip to content

Commit

Permalink
Merge branch 'nuxt:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JonikUl authored Jun 12, 2024
2 parents d05e784 + b17aa3f commit 6f6bffe
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 101 deletions.
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"unbuild": "latest",
"vite": "5.2.13",
"vitest": "1.6.0",
"webpack": "5.91.0"
"webpack": "5.92.0"
},
"engines": {
"node": "^14.18.0 || >=16.10.0"
Expand Down
8 changes: 5 additions & 3 deletions packages/nuxt/src/app/composables/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parse } from 'devalue'
import { useHead } from '@unhead/vue'
import { getCurrentInstance, onServerPrefetch } from 'vue'
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
import type { NuxtPayload } from '../nuxt'

import { useRoute } from './router'
import { getAppManifest, getRouteRules } from './manifest'
Expand Down Expand Up @@ -95,19 +96,20 @@ export async function isPrerendered (url = useRoute().path) {
return !!rules.prerender && !rules.redirect
}

let payloadCache: any = null
let payloadCache: NuxtPayload | null = null

/** @since 3.4.0 */
export async function getNuxtClientPayload () {
if (import.meta.server) {
return
return null
}
if (payloadCache) {
return payloadCache
}

const el = document.getElementById('__NUXT_DATA__')
if (!el) {
return {}
return {} as Partial<NuxtPayload>
}

const inlineData = await parsePayload(el.textContent || '')
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface NuxtSSRContext extends SSRContext {
/** whether we are rendering an SSR error */
error?: boolean
nuxt: _NuxtApp
payload: NuxtPayload
payload: Partial<NuxtPayload>
head: VueHeadClient<MergeHead>
/** This is used solely to render runtime config with SPA renderer. */
config?: Pick<RuntimeConfig, 'public' | 'app'>
Expand Down
4 changes: 0 additions & 4 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ const getSPARenderer = lazyCachedFunction(async () => {
const config = useRuntimeConfig(ssrContext.event)
ssrContext.modules = ssrContext.modules || new Set<string>()
ssrContext!.payload = {
_errors: {},
serverRendered: false,
data: {},
state: {},
once: new Set<string>(),
}
ssrContext.config = {
public: config.public,
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"vue-bundle-renderer": "2.1.0",
"vue-loader": "17.4.2",
"vue-router": "4.3.3",
"webpack": "5.91.0",
"webpack": "5.92.0",
"webpack-dev-middleware": "7.2.1"
},
"dependencies": {
Expand Down
12 changes: 11 additions & 1 deletion packages/schema/src/config/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync } from 'node:fs'
import { readdir } from 'node:fs/promises'
import { defineUntypedSchema } from 'untyped'
import { join, relative, resolve } from 'pathe'
import { isDebug, isDevelopment, isTest } from 'std-env'
Expand Down Expand Up @@ -117,7 +118,16 @@ export default defineUntypedSchema({
}

const srcDir = resolve(rootDir, 'app')
if (!existsSync(srcDir)) {
const srcDirFiles = new Set<string>()
if (existsSync(srcDir)) {
const files = await readdir(srcDir).catch(() => [])
for (const file of files) {
if (file !== 'spa-loading-template.html' && !file.startsWith('router.options')) {
srcDirFiles.add(file)
}
}
}
if (srcDirFiles.size === 0) {
for (const file of ['app.vue', 'App.vue']) {
if (existsSync(resolve(rootDir, file))) {
return rootDir
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export interface AppConfigInput extends CustomAppConfig {
server?: never
}

type Serializable<T> = T extends Function ? never : T extends Promise<infer U> ? Serializable<U> : T extends Record<string, any> ? { [K in keyof T]: Serializable<T[K]> } : T
type Serializable<T> = T extends Function ? never : T extends Promise<infer U> ? Serializable<U> : T extends string & {} ? T : T extends Record<string, any> ? { [K in keyof T]: Serializable<T[K]> } : T

export interface NuxtAppConfig {
head: Serializable<AppHeadMetaObject>
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"url-loader": "^4.1.1",
"vue-bundle-renderer": "^2.1.0",
"vue-loader": "^17.4.2",
"webpack": "^5.91.0",
"webpack": "^5.92.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-dev-middleware": "^7.2.1",
"webpack-hot-middleware": "^2.26.1",
Expand Down
185 changes: 97 additions & 88 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/fixtures/basic-types/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export default defineNuxtConfig({
title: Promise.resolve('Nuxt Fixture'),
// @ts-expect-error Functions are not allowed
titleTemplate: title => 'test',
meta: [
{
// Allows unknown property
property: 'og:thing',
content: '1234567890',
},
],
},
pageTransition: {
// @ts-expect-error Functions are not allowed
Expand Down

0 comments on commit 6f6bffe

Please sign in to comment.