Unverified Commit c7acd118 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Dedupe ComponentRes type (#16148)

This PR dedupes the `ComponentRes` type to now align with the `loadPage` return type.
parent bdc46509
import type { ComponentType } from 'react'
import type { ClientSsgManifest } from '../build' import type { ClientSsgManifest } from '../build'
import type { ClientBuildManifest } from '../build/webpack/plugins/build-manifest-plugin' import type { ClientBuildManifest } from '../build/webpack/plugins/build-manifest-plugin'
import mitt from '../next-server/lib/mitt' import mitt from '../next-server/lib/mitt'
...@@ -68,7 +69,7 @@ function appendLink( ...@@ -68,7 +69,7 @@ function appendLink(
}) })
} }
export type GoodPageCache = { page: any; mod: any } export type GoodPageCache = { page: ComponentType; mod: any }
export type PageCacheEntry = { error: any } | GoodPageCache export type PageCacheEntry = { error: any } | GoodPageCache
export default class PageLoader { export default class PageLoader {
......
...@@ -3,25 +3,26 @@ ...@@ -3,25 +3,26 @@
import { ParsedUrlQuery } from 'querystring' import { ParsedUrlQuery } from 'querystring'
import { ComponentType } from 'react' import { ComponentType } from 'react'
import { UrlObject } from 'url' import { UrlObject } from 'url'
import {
normalizePathTrailingSlash,
removePathTrailingSlash,
} from '../../../client/normalize-trailing-slash'
import type { GoodPageCache } from '../../../client/page-loader'
import mitt, { MittEmitter } from '../mitt' import mitt, { MittEmitter } from '../mitt'
import { import {
AppContextType, AppContextType,
formatWithValidation, formatWithValidation,
getLocationOrigin,
getURL, getURL,
loadGetInitialProps, loadGetInitialProps,
NextPageContext, NextPageContext,
ST, ST,
getLocationOrigin,
} from '../utils' } from '../utils'
import { isDynamicRoute } from './utils/is-dynamic' import { isDynamicRoute } from './utils/is-dynamic'
import { parseRelativeUrl } from './utils/parse-relative-url'
import { searchParamsToUrlQuery } from './utils/querystring'
import { getRouteMatcher } from './utils/route-matcher' import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex' import { getRouteRegex } from './utils/route-regex'
import { searchParamsToUrlQuery } from './utils/querystring'
import { parseRelativeUrl } from './utils/parse-relative-url'
import {
removePathTrailingSlash,
normalizePathTrailingSlash,
} from '../../../client/normalize-trailing-slash'
interface TransitionOptions { interface TransitionOptions {
shallow?: boolean shallow?: boolean
...@@ -129,8 +130,6 @@ function tryParseRelativeUrl( ...@@ -129,8 +130,6 @@ function tryParseRelativeUrl(
} }
} }
type ComponentRes = { page: ComponentType; mod: any }
export type BaseRouter = { export type BaseRouter = {
route: string route: string
pathname: string pathname: string
...@@ -697,16 +696,13 @@ export default class Router implements BaseRouter { ...@@ -697,16 +696,13 @@ export default class Router implements BaseRouter {
return cachedRouteInfo return cachedRouteInfo
} }
const routeInfo = cachedRouteInfo const routeInfo: RouteInfo = cachedRouteInfo
? cachedRouteInfo ? cachedRouteInfo
: await this.fetchComponent(route).then( : await this.fetchComponent(route).then((res) => ({
(res) => Component: res.page,
({ __N_SSG: res.mod.__N_SSG,
Component: res.page, __N_SSP: res.mod.__N_SSP,
__N_SSG: res.mod.__N_SSG, }))
__N_SSP: res.mod.__N_SSP,
} as RouteInfo)
)
const { Component, __N_SSG, __N_SSP } = routeInfo const { Component, __N_SSG, __N_SSP } = routeInfo
...@@ -853,7 +849,7 @@ export default class Router implements BaseRouter { ...@@ -853,7 +849,7 @@ export default class Router implements BaseRouter {
]) ])
} }
async fetchComponent(route: string): Promise<ComponentRes> { async fetchComponent(route: string): Promise<GoodPageCache> {
let cancelled = false let cancelled = false
const cancel = (this.clc = () => { const cancel = (this.clc = () => {
cancelled = true cancelled = true
......
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