Unverified Commit b1cbb4c4 authored by Steven's avatar Steven Committed by GitHub

fix: improve type of `ExportPathMap` (#47676)

This is a new PR with only the typescript changes from previous closed
PR #47628
parent 0a94e222
import type { RemotePattern } from '../shared/lib/image-config' import type { RemotePattern } from '../shared/lib/image-config'
import type { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin' import type { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin'
import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import type { NextConfigComplete } from '../server/config-shared' import type { ExportPathMap, NextConfigComplete } from '../server/config-shared'
import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin' import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin'
...@@ -2341,7 +2341,7 @@ export default async function build( ...@@ -2341,7 +2341,7 @@ export default async function build(
// pages and incremental pages. // pages and incremental pages.
// n.b. we cannot handle this above in combinedPages because the dynamic // n.b. we cannot handle this above in combinedPages because the dynamic
// page must be in the `pages` array, but not in the mapping. // page must be in the `pages` array, but not in the mapping.
exportPathMap: (defaultMap: any) => { exportPathMap: (defaultMap: ExportPathMap) => {
// Dynamically routed pages should be prerendered to be used as // Dynamically routed pages should be prerendered to be used as
// a client-side skeleton (fallback) while data is being fetched. // a client-side skeleton (fallback) while data is being fetched.
// This ensures the end-user never sees a 500 or slow response from the // This ensures the end-user never sees a 500 or slow response from the
...@@ -2358,12 +2358,12 @@ export default async function build( ...@@ -2358,12 +2358,12 @@ export default async function build(
if (i18n) { if (i18n) {
defaultMap[`/${i18n.defaultLocale}${page}`] = { defaultMap[`/${i18n.defaultLocale}${page}`] = {
page, page,
query: { __nextFallback: true }, query: { __nextFallback: 'true' },
} }
} else { } else {
defaultMap[page] = { defaultMap[page] = {
page, page,
query: { __nextFallback: true }, query: { __nextFallback: 'true' },
} }
} }
} else { } else {
...@@ -2432,11 +2432,10 @@ export default async function build( ...@@ -2432,11 +2432,10 @@ export default async function build(
defaultMap[outputPath] = { defaultMap[outputPath] = {
page: defaultMap[page]?.page || page, page: defaultMap[page]?.page || page,
query: { __nextLocale: locale }, query: {
} __nextLocale: locale,
__nextFallback: isFallback ? 'true' : undefined,
if (isFallback) { },
defaultMap[outputPath].query.__nextFallback = true
} }
} }
......
...@@ -3,9 +3,11 @@ import type { ...@@ -3,9 +3,11 @@ import type {
AppRouteRouteHandlerContext, AppRouteRouteHandlerContext,
} from '../server/future/route-handlers/app-route-route-handler' } from '../server/future/route-handlers/app-route-route-handler'
import type { FontManifest, FontConfig } from '../server/font-utils' import type { FontManifest, FontConfig } from '../server/font-utils'
import type { DomainLocale, NextConfigComplete } from '../server/config-shared' import type {
DomainLocale,
import { NextParsedUrlQuery } from '../server/request-meta' ExportPathMap,
NextConfigComplete,
} from '../server/config-shared'
// `NEXT_PREBUNDLED_REACT` env var is inherited from parent process, // `NEXT_PREBUNDLED_REACT` env var is inherited from parent process,
// then override react packages here for export worker. // then override react packages here for export worker.
...@@ -64,10 +66,7 @@ interface AmpValidation { ...@@ -64,10 +66,7 @@ interface AmpValidation {
} }
} }
interface PathMap { type PathMap = ExportPathMap[keyof ExportPathMap]
page: string
query?: NextParsedUrlQuery
}
interface ExportPageInput { interface ExportPageInput {
path: string path: string
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
import { ServerRuntime } from 'next/types' import { ServerRuntime } from 'next/types'
import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin' import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
import { WEB_VITALS } from '../shared/lib/utils' import { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta'
export type NextConfigComplete = Required<NextConfig> & { export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete> images: Required<ImageConfigComplete>
...@@ -241,8 +242,9 @@ export interface ExperimentalConfig { ...@@ -241,8 +242,9 @@ export interface ExperimentalConfig {
export type ExportPathMap = { export type ExportPathMap = {
[path: string]: { [path: string]: {
page: string page: string
query?: Record<string, string | string[]> query?: NextParsedUrlQuery
_isAppDir?: boolean _isAppDir?: boolean
_isDynamicError?: boolean
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment