Unverified Commit a56066c5 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Pages Route Module (#50070)

This exports the named exports from the user's page route file and
exports a new `routeModule` stub. This stub will be the new rendering
mechanism used for pages within `pages/` and will serve to allow us to
deprecate large chunks of the server code to instead live within the
pages entrypoints.

TLDR;

- Route Modules now accept a `definition` so that they have their full
route definition
- Exports are now hoisted from the userland module by name to prevent
name collisions
- A new `PagesRouteModule` stub was added that will in the future
contain all the pages rendering logic

---------
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent 2aa68ae2
...@@ -2,12 +2,19 @@ import { EdgeRouteModuleWrapper } from 'next/dist/server/web/edge-route-module-w ...@@ -2,12 +2,19 @@ import { EdgeRouteModuleWrapper } from 'next/dist/server/web/edge-route-module-w
import RouteModule from 'ROUTE_MODULE' import RouteModule from 'ROUTE_MODULE'
import * as userland from 'ENTRY' import * as userland from 'ENTRY'
import { PAGE, PATHNAME } from 'BOOTSTRAP_CONFIG' import { PAGE, PATHNAME, KIND } from 'BOOTSTRAP_CONFIG'
// TODO: (wyattjoh) - perform the option construction in Rust to allow other modules to accept different options // TODO: (wyattjoh) - perform the option construction in Rust to allow other modules to accept different options
const routeModule = new RouteModule({ const routeModule = new RouteModule({
userland, userland,
definition: {
page: PAGE,
kind: KIND,
pathname: PATHNAME, pathname: PATHNAME,
// The following aren't used in production.
filename: '',
bundlePath: '',
},
resolvedPagePath: `app/${PAGE}`, resolvedPagePath: `app/${PAGE}`,
nextConfigOutput: undefined, nextConfigOutput: undefined,
}) })
......
...@@ -18,11 +18,18 @@ import { attachRequestMeta } from '../../internal/next-request-helpers' ...@@ -18,11 +18,18 @@ import { attachRequestMeta } from '../../internal/next-request-helpers'
import RouteModule from 'ROUTE_MODULE' import RouteModule from 'ROUTE_MODULE'
import * as userland from 'ENTRY' import * as userland from 'ENTRY'
import { PAGE, PATHNAME } from 'BOOTSTRAP_CONFIG' import { PAGE, PATHNAME, KIND } from 'BOOTSTRAP_CONFIG'
const routeModule = new RouteModule({ const routeModule = new RouteModule({
userland, userland,
definition: {
page: PAGE,
kind: KIND,
pathname: PATHNAME, pathname: PATHNAME,
// The following aren't used in production.
filename: '',
bundlePath: '',
},
resolvedPagePath: `app/${PAGE}`, resolvedPagePath: `app/${PAGE}`,
nextConfigOutput: undefined, nextConfigOutput: undefined,
}) })
......
...@@ -72,9 +72,12 @@ declare module 'ROUTE_MODULE' { ...@@ -72,9 +72,12 @@ declare module 'ROUTE_MODULE' {
} }
declare module 'BOOTSTRAP_CONFIG' { declare module 'BOOTSTRAP_CONFIG' {
import type { RouteKind } from 'next/dist/server/future/route-kind'
export const NAME: string export const NAME: string
export const PAGE: string export const PAGE: string
export const PATHNAME: string export const PATHNAME: string
export const KIND: RouteKind
} }
declare module 'CLIENT_MODULE' { declare module 'CLIENT_MODULE' {
......
...@@ -104,6 +104,7 @@ pub async fn bootstrap( ...@@ -104,6 +104,7 @@ pub async fn bootstrap(
let mut config = config.await?.clone_value(); let mut config = config.await?.clone_value();
config.insert("PAGE".to_string(), path.to_string()); config.insert("PAGE".to_string(), path.to_string());
config.insert("PATHNAME".to_string(), pathname); config.insert("PATHNAME".to_string(), pathname);
config.insert("KIND".to_string(), "APP_ROUTE".to_string());
let config_asset = as_es_module_asset( let config_asset = as_es_module_asset(
VirtualAssetVc::new( VirtualAssetVc::new(
......
...@@ -1193,16 +1193,20 @@ export default async function build( ...@@ -1193,16 +1193,20 @@ export default async function build(
? [ ? [
'hasCustomGetInitialProps', 'hasCustomGetInitialProps',
'isPageStatic', 'isPageStatic',
'getNamedExports', 'getDefinedNamedExports',
'exportPage', 'exportPage',
] ]
: ['hasCustomGetInitialProps', 'isPageStatic', 'getNamedExports'], : [
'hasCustomGetInitialProps',
'isPageStatic',
'getDefinedNamedExports',
],
}) as Worker & }) as Worker &
Pick< Pick<
typeof import('./worker'), typeof import('./worker'),
| 'hasCustomGetInitialProps' | 'hasCustomGetInitialProps'
| 'isPageStatic' | 'isPageStatic'
| 'getNamedExports' | 'getDefinedNamedExports'
| 'exportPage' | 'exportPage'
> >
} }
...@@ -1275,7 +1279,7 @@ export default async function build( ...@@ -1275,7 +1279,7 @@ export default async function build(
true true
) )
const namedExportsPromise = pagesStaticWorkers.getNamedExports( const namedExportsPromise = pagesStaticWorkers.getDefinedNamedExports(
appPageToCheck, appPageToCheck,
distDir, distDir,
runtimeEnvConfig runtimeEnvConfig
......
...@@ -1677,11 +1677,11 @@ export async function hasCustomGetInitialProps( ...@@ -1677,11 +1677,11 @@ export async function hasCustomGetInitialProps(
return mod.getInitialProps !== mod.origGetInitialProps return mod.getInitialProps !== mod.origGetInitialProps
} }
export async function getNamedExports( export async function getDefinedNamedExports(
page: string, page: string,
distDir: string, distDir: string,
runtimeEnvConfig: any runtimeEnvConfig: any
): Promise<Array<string>> { ): Promise<ReadonlyArray<string>> {
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig) require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
const components = await loadComponents({ const components = await loadComponents({
distDir, distDir,
...@@ -1689,9 +1689,10 @@ export async function getNamedExports( ...@@ -1689,9 +1689,10 @@ export async function getNamedExports(
hasServerComponents: false, hasServerComponents: false,
isAppPath: false, isAppPath: false,
}) })
let mod = components.ComponentMod
return Object.keys(mod) return Object.keys(components.ComponentMod).filter((key) => {
return typeof components.ComponentMod[key] !== 'undefined'
})
} }
export function detectConflictingPaths( export function detectConflictingPaths(
......
...@@ -19,6 +19,9 @@ import { isAppRouteRoute } from '../../../lib/is-app-route-route' ...@@ -19,6 +19,9 @@ import { isAppRouteRoute } from '../../../lib/is-app-route-route'
import { isMetadataRoute } from '../../../lib/metadata/is-metadata-route' import { isMetadataRoute } from '../../../lib/metadata/is-metadata-route'
import { NextConfig } from '../../../server/config-shared' import { NextConfig } from '../../../server/config-shared'
import { AppPathnameNormalizer } from '../../../server/future/normalizers/built/app/app-pathname-normalizer' import { AppPathnameNormalizer } from '../../../server/future/normalizers/built/app/app-pathname-normalizer'
import { RouteKind } from '../../../server/future/route-kind'
import { AppRouteRouteModuleOptions } from '../../../server/future/route-modules/app-route/module'
import { AppBundlePathNormalizer } from '../../../server/future/normalizers/built/app/app-bundle-path-normalizer'
export type AppLoaderOptions = { export type AppLoaderOptions = {
name: string name: string
...@@ -107,21 +110,24 @@ async function createAppRouteCode({ ...@@ -107,21 +110,24 @@ async function createAppRouteCode({
// References the route handler file to load found in `./routes/${kind}.ts`. // References the route handler file to load found in `./routes/${kind}.ts`.
// TODO: allow switching to the different kinds of routes // TODO: allow switching to the different kinds of routes
const kind = 'app-route' const kind = 'app-route'
const normalizer = new AppPathnameNormalizer() const pathname = new AppPathnameNormalizer().normalize(page)
const pathname = normalizer.normalize(page) const bundlePath = new AppBundlePathNormalizer().normalize(page)
// This is providing the options defined by the route options type found at // This is providing the options defined by the route options type found at
// ./routes/${kind}.ts. This is stringified here so that the literal for // ./routes/${kind}.ts. This is stringified here so that the literal for
// `userland` can reference the variable for `userland` that's in scope for // `userland` can reference the variable for `userland` that's in scope for
// the loader code. // the loader code.
const options = `{ const options: Omit<AppRouteRouteModuleOptions, 'userland'> = {
userland, definition: {
pathname: ${JSON.stringify(pathname)}, kind: RouteKind.APP_ROUTE,
resolvedPagePath: ${JSON.stringify(resolvedPagePath)}, page,
nextConfigOutput: ${ pathname,
nextConfigOutput ? JSON.stringify(nextConfigOutput) : 'undefined' filename,
bundlePath,
}, },
}` resolvedPagePath,
nextConfigOutput,
}
return ` return `
import 'next/dist/server/node-polyfill-headers' import 'next/dist/server/node-polyfill-headers'
...@@ -130,7 +136,11 @@ async function createAppRouteCode({ ...@@ -130,7 +136,11 @@ async function createAppRouteCode({
import * as userland from ${JSON.stringify(resolvedPagePath)} import * as userland from ${JSON.stringify(resolvedPagePath)}
const routeModule = new RouteModule(${options}) const options = ${JSON.stringify(options)}
const routeModule = new RouteModule({
...options,
userland,
})
// Pull out the exports that we need to expose from the module. This should // Pull out the exports that we need to expose from the module. This should
// be eliminated when we've moved the other routes to the new format. These // be eliminated when we've moved the other routes to the new format. These
......
/**
* Hoists a name from a module or promised module.
*
* @param module the module to hoist the name from
* @param name the name to hoist
* @returns the value on the module (or promised module)
*/
export function hoist(module: any, name: string) {
// If the name is available in the module, return it.
if (name in module) {
return module[name]
}
// If a property called `then` exists, assume it's a promise and
// return a promise that resolves to the name.
if ('then' in module && typeof module.then === 'function') {
return module.then((mod: any) => hoist(mod, name))
}
// If we're trying to hoise the default export, and the module is a function,
// return the module itself.
if (typeof module === 'function' && name === 'default') {
return module
}
// Otherwise, return undefined.
return undefined
}
import type { webpack } from 'next/dist/compiled/webpack/webpack' import type { webpack } from 'next/dist/compiled/webpack/webpack'
import { stringify } from 'querystring' import { stringify } from 'querystring'
import { getModuleBuildInfo } from './get-module-build-info' import { getModuleBuildInfo } from '../get-module-build-info'
import { PagesRouteModuleOptions } from '../../../../server/future/route-modules/pages/module'
import { RouteKind } from '../../../../server/future/route-kind'
import { normalizePagePath } from '../../../../shared/lib/page-path/normalize-page-path'
/** /**
* The options for the route loader. * The options for the route loader.
...@@ -54,10 +57,47 @@ const loader: webpack.LoaderDefinitionFunction<RouteLoaderOptions> = ...@@ -54,10 +57,47 @@ const loader: webpack.LoaderDefinitionFunction<RouteLoaderOptions> =
preferredRegion, preferredRegion,
} }
const options: Omit<PagesRouteModuleOptions, 'userland'> = {
definition: {
kind: RouteKind.PAGES,
page: normalizePagePath(page),
pathname: page,
// The following aren't used in production.
bundlePath: '',
filename: '',
},
}
return ` return `
// Next.js Route Loader // Next.js Route Loader
export * from ${JSON.stringify(absolutePagePath)} import RouteModule from "next/dist/server/future/route-modules/pages/module"
export { default } from ${JSON.stringify(absolutePagePath)} import { hoist } from "next/dist/build/webpack/loaders/next-route-loader/helpers"
// Import the userland code.
import * as userland from ${JSON.stringify(absolutePagePath)}
// Re-export the component (should be the default export).
export default hoist(userland, "default")
// Re-export methods.
export const getStaticProps = hoist(userland, "getStaticProps")
export const getStaticPaths = hoist(userland, "getStaticPaths")
export const getServerSideProps = hoist(userland, "getServerSideProps")
export const config = hoist(userland, "config")
export const reportWebVitals = hoist(userland, "reportWebVitals")
// Re-export legacy methods.
export const unstable_getStaticProps = hoist(userland, "unstable_getStaticProps")
export const unstable_getStaticPaths = hoist(userland, "unstable_getStaticPaths")
export const unstable_getStaticParams = hoist(userland, "unstable_getStaticParams")
export const unstable_getServerProps = hoist(userland, "unstable_getServerProps")
export const unstable_getServerSideProps = hoist(userland, "unstable_getServerSideProps")
// Create and export the route module that will be consumed.
const options = ${JSON.stringify(options)}
const routeModule = new RouteModule({ ...options, userland })
export { routeModule }
` `
} }
......
...@@ -139,6 +139,7 @@ export async function getNotFoundError( ...@@ -139,6 +139,7 @@ export async function getNotFoundError(
!/next-(app|middleware|client-pages|route|flight-(client|server|client-entry))-loader\.js/.test( !/next-(app|middleware|client-pages|route|flight-(client|server|client-entry))-loader\.js/.test(
name name
) && ) &&
!/next-route-loader\/index\.js/.test(name) &&
!/css-loader.+\.js/.test(name) !/css-loader.+\.js/.test(name)
) )
if (moduleTrace.length === 0) return '' if (moduleTrace.length === 0) return ''
......
...@@ -44,6 +44,7 @@ import getRouteFromEntrypoint from '../get-route-from-entrypoint' ...@@ -44,6 +44,7 @@ import getRouteFromEntrypoint from '../get-route-from-entrypoint'
import { fileExists } from '../../lib/file-exists' import { fileExists } from '../../lib/file-exists'
import { import {
difference, difference,
isInstrumentationHookFile,
isMiddlewareFile, isMiddlewareFile,
isMiddlewareFilename, isMiddlewareFilename,
} from '../../build/utils' } from '../../build/utils'
...@@ -855,7 +856,8 @@ export default class HotReloader { ...@@ -855,7 +856,8 @@ export default class HotReloader {
} else if ( } else if (
!isAPIRoute(page) && !isAPIRoute(page) &&
!isMiddlewareFile(page) && !isMiddlewareFile(page) &&
!isInternalPathname(relativeRequest) !isInternalPathname(relativeRequest) &&
!isInstrumentationHookFile(page)
) { ) {
value = getRouteLoaderEntry({ value = getRouteLoaderEntry({
page, page,
......
...@@ -2,6 +2,7 @@ import type { NextConfig } from '../../../config-shared' ...@@ -2,6 +2,7 @@ import type { NextConfig } from '../../../config-shared'
import type { AppRouteRouteDefinition } from '../../route-definitions/app-route-route-definition' import type { AppRouteRouteDefinition } from '../../route-definitions/app-route-route-definition'
import type { AppConfig } from '../../../../build/utils' import type { AppConfig } from '../../../../build/utils'
import type { NextRequest } from '../../../web/spec-extension/request' import type { NextRequest } from '../../../web/spec-extension/request'
import type { PrerenderManifest } from '../../../../build'
import { import {
RouteModule, RouteModule,
...@@ -27,13 +28,28 @@ import { AppRouteRouteHandlersSpan } from '../../../lib/trace/constants' ...@@ -27,13 +28,28 @@ import { AppRouteRouteHandlersSpan } from '../../../lib/trace/constants'
import { getPathnameFromAbsolutePath } from './helpers/get-pathname-from-absolute-path' import { getPathnameFromAbsolutePath } from './helpers/get-pathname-from-absolute-path'
import { proxyRequest } from './helpers/proxy-request' import { proxyRequest } from './helpers/proxy-request'
import { resolveHandlerError } from './helpers/resolve-handler-error' import { resolveHandlerError } from './helpers/resolve-handler-error'
import { RouteKind } from '../../route-kind'
import * as Log from '../../../../build/output/log' import * as Log from '../../../../build/output/log'
import { autoImplementMethods } from './helpers/auto-implement-methods' import { autoImplementMethods } from './helpers/auto-implement-methods'
import { getNonStaticMethods } from './helpers/get-non-static-methods' import { getNonStaticMethods } from './helpers/get-non-static-methods'
import { PrerenderManifest } from '../../../../build'
import { appendMutableCookies } from '../../../web/spec-extension/adapters/request-cookies' import { appendMutableCookies } from '../../../web/spec-extension/adapters/request-cookies'
// These are imported weirdly like this because of the way that the bundling
// works. We need to import the built files from the dist directory, but we
// can't do that directly because we need types from the source files. So we
// import the types from the source files and then import the built files.
const { requestAsyncStorage } =
require('next/dist/client/components/request-async-storage') as typeof import('../../../../client/components/request-async-storage')
const { staticGenerationAsyncStorage } =
require('next/dist/client/components/static-generation-async-storage') as typeof import('../../../../client/components/static-generation-async-storage')
const serverHooks =
require('next/dist/client/components/hooks-server-context') as typeof import('../../../../client/components/hooks-server-context')
const headerHooks =
require('next/dist/client/components/headers') as typeof import('../../../../client/components/headers')
const { staticGenerationBailout } =
require('next/dist/client/components/static-generation-bailout') as typeof import('../../../../client/components/static-generation-bailout')
const { actionAsyncStorage } =
require('next/dist/client/components/action-async-storage') as typeof import('../../../../client/components/action-async-storage')
/** /**
* AppRouteRouteHandlerContext is the context that is passed to the route * AppRouteRouteHandlerContext is the context that is passed to the route
* handler for app routes. * handler for app routes.
...@@ -89,8 +105,7 @@ export type AppRouteUserlandModule = AppRouteHandlers & ...@@ -89,8 +105,7 @@ export type AppRouteUserlandModule = AppRouteHandlers &
* module from the bundled code. * module from the bundled code.
*/ */
export interface AppRouteRouteModuleOptions export interface AppRouteRouteModuleOptions
extends RouteModuleOptions<AppRouteUserlandModule> { extends RouteModuleOptions<AppRouteRouteDefinition, AppRouteUserlandModule> {
readonly pathname: string
readonly resolvedPagePath: string readonly resolvedPagePath: string
readonly nextConfigOutput: NextConfig['output'] readonly nextConfigOutput: NextConfig['output']
} }
...@@ -102,8 +117,40 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -102,8 +117,40 @@ export class AppRouteRouteModule extends RouteModule<
AppRouteRouteDefinition, AppRouteRouteDefinition,
AppRouteUserlandModule AppRouteUserlandModule
> { > {
public readonly definition: AppRouteRouteDefinition /**
public readonly pathname: string * A reference to the request async storage.
*/
public readonly requestAsyncStorage = requestAsyncStorage
/**
* A reference to the static generation async storage.
*/
public readonly staticGenerationAsyncStorage = staticGenerationAsyncStorage
/**
* An interface to call server hooks which interact with the underlying
* storage.
*/
public readonly serverHooks = serverHooks
/**
* An interface to call header hooks which interact with the underlying
* request storage.
*/
public readonly headerHooks = headerHooks
/**
* An interface to call static generation bailout hooks which interact with
* the underlying static generation storage.
*/
public readonly staticGenerationBailout = staticGenerationBailout
/**
* A reference to the mutation related async storage, such as mutations of
* cookies.
*/
public readonly actionAsyncStorage = actionAsyncStorage
public readonly resolvedPagePath: string public readonly resolvedPagePath: string
public readonly nextConfigOutput: NextConfig['output'] | undefined public readonly nextConfigOutput: NextConfig['output'] | undefined
...@@ -113,22 +160,12 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -113,22 +160,12 @@ export class AppRouteRouteModule extends RouteModule<
constructor({ constructor({
userland, userland,
pathname, definition,
resolvedPagePath, resolvedPagePath,
nextConfigOutput, nextConfigOutput,
}: AppRouteRouteModuleOptions) { }: AppRouteRouteModuleOptions) {
super({ userland }) super({ userland, definition })
this.definition = {
kind: RouteKind.APP_ROUTE,
pathname,
// The following aren't needed for the route handler.
page: '',
bundlePath: '',
filename: '',
}
this.pathname = pathname
this.resolvedPagePath = resolvedPagePath this.resolvedPagePath = resolvedPagePath
this.nextConfigOutput = nextConfigOutput this.nextConfigOutput = nextConfigOutput
...@@ -146,7 +183,7 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -146,7 +183,7 @@ export class AppRouteRouteModule extends RouteModule<
this.dynamic = 'error' this.dynamic = 'error'
} else if (this.dynamic === 'force-dynamic') { } else if (this.dynamic === 'force-dynamic') {
throw new Error( throw new Error(
`export const dynamic = "force-dynamic" on page "${pathname}" cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export` `export const dynamic = "force-dynamic" on page "${definition.pathname}" cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export`
) )
} }
} }
......
import type {
GetServerSideProps,
GetStaticPaths,
GetStaticProps,
NextComponentType,
PageConfig,
} from '../../../../../types'
import type { PagesRouteDefinition } from '../../route-definitions/pages-route-definition'
import { RouteModule, type RouteModuleOptions } from '../route-module'
/**
* The userland module for a page. This is the module that is exported from the
* page file that contains the page component, page config, and any page data
* fetching functions.
*/
export type PagesUserlandModule = {
/**
* The exported page component.
*/
readonly default: NextComponentType
/**
* The exported page config.
*/
readonly config?: PageConfig
/**
* The exported `getStaticProps` function.
*/
readonly getStaticProps?: GetStaticProps
/**
* The exported `getStaticPaths` function.
*/
readonly getStaticPaths?: GetStaticPaths
/**
* The exported `getServerSideProps` function.
*/
readonly getServerSideProps?: GetServerSideProps
}
export type PagesRouteModuleOptions = RouteModuleOptions<
PagesRouteDefinition,
PagesUserlandModule
>
class PagesRouteModule extends RouteModule<
PagesRouteDefinition,
PagesUserlandModule
> {
public setup(): Promise<void> {
throw new Error('Method not implemented.')
}
public handle(): Promise<Response> {
throw new Error('Method not implemented.')
}
}
export default PagesRouteModule
import type { RouteDefinition } from '../route-definitions/route-definition' import type { RouteDefinition } from '../route-definitions/route-definition'
import type { NextRequest } from '../../web/spec-extension/request' import type { NextRequest } from '../../web/spec-extension/request'
// These are imported weirdly like this because of the way that the bundling
// works. We need to import the built files from the dist directory, but we
// can't do that directly because we need types from the source files. So we
// import the types from the source files and then import the built files.
const { requestAsyncStorage } =
require('next/dist/client/components/request-async-storage') as typeof import('../../../client/components/request-async-storage')
const { staticGenerationAsyncStorage } =
require('next/dist/client/components/static-generation-async-storage') as typeof import('../../../client/components/static-generation-async-storage')
const serverHooks =
require('next/dist/client/components/hooks-server-context') as typeof import('../../../client/components/hooks-server-context')
const headerHooks =
require('next/dist/client/components/headers') as typeof import('../../../client/components/headers')
const { staticGenerationBailout } =
require('next/dist/client/components/static-generation-bailout') as typeof import('../../../client/components/static-generation-bailout')
const { actionAsyncStorage } =
require('next/dist/client/components/action-async-storage') as typeof import('../../../client/components/action-async-storage')
/** /**
* RouteModuleOptions is the options that are passed to the route module, other * RouteModuleOptions is the options that are passed to the route module, other
* route modules should extend this class to add specific options for their * route modules should extend this class to add specific options for their
* route. * route.
*/ */
export interface RouteModuleOptions<U = unknown> { export interface RouteModuleOptions<
D extends RouteDefinition = RouteDefinition,
U = unknown
> {
readonly definition: Readonly<D>
readonly userland: Readonly<U> readonly userland: Readonly<U>
} }
...@@ -46,40 +33,6 @@ export abstract class RouteModule< ...@@ -46,40 +33,6 @@ export abstract class RouteModule<
D extends RouteDefinition = RouteDefinition, D extends RouteDefinition = RouteDefinition,
U = unknown U = unknown
> { > {
/**
* A reference to the request async storage.
*/
public readonly requestAsyncStorage = requestAsyncStorage
/**
* A reference to the static generation async storage.
*/
public readonly staticGenerationAsyncStorage = staticGenerationAsyncStorage
/**
* An interface to call server hooks which interact with the underlying
* storage.
*/
public readonly serverHooks = serverHooks
/**
* An interface to call header hooks which interact with the underlying
* request storage.
*/
public readonly headerHooks = headerHooks
/**
* An interface to call static generation bailout hooks which interact with
* the underlying static generation storage.
*/
public readonly staticGenerationBailout = staticGenerationBailout
/**
* A reference to the mutation related async storage, such as mutations of
* cookies.
*/
public readonly actionAsyncStorage = actionAsyncStorage
/** /**
* The userland module. This is the module that is exported from the user's * The userland module. This is the module that is exported from the user's
* code. This is marked as readonly to ensure that the module is not mutated * code. This is marked as readonly to ensure that the module is not mutated
...@@ -90,7 +43,7 @@ export abstract class RouteModule< ...@@ -90,7 +43,7 @@ export abstract class RouteModule<
/** /**
* The definition of the route. * The definition of the route.
*/ */
public abstract readonly definition: D public readonly definition: Readonly<D>
/** /**
* Setup will setup the route handler. This could patch any globals or perform * Setup will setup the route handler. This could patch any globals or perform
...@@ -107,7 +60,8 @@ export abstract class RouteModule< ...@@ -107,7 +60,8 @@ export abstract class RouteModule<
context: RouteModuleHandleContext context: RouteModuleHandleContext
): Promise<Response> ): Promise<Response>
constructor({ userland }: RouteModuleOptions<U>) { constructor({ userland, definition }: RouteModuleOptions<D, U>) {
this.userland = userland this.userland = userland
this.definition = definition
} }
} }
...@@ -96,5 +96,6 @@ Caused by: ...@@ -96,5 +96,6 @@ Caused by:
Syntax Error Syntax Error
Import trace for requested module: Import trace for requested module:
./index.js" ./index.js
./pages/index.js"
`; `;
...@@ -28,7 +28,8 @@ Caused by: ...@@ -28,7 +28,8 @@ Caused by:
Syntax Error Syntax Error
Import trace for requested module: Import trace for requested module:
./index.js" ./index.js
./pages/index.js"
`; `;
exports[`ReactRefreshLogBox default syntax > runtime error 3`] = ` exports[`ReactRefreshLogBox default syntax > runtime error 3`] = `
...@@ -47,5 +48,6 @@ Caused by: ...@@ -47,5 +48,6 @@ Caused by:
Syntax Error Syntax Error
Import trace for requested module: Import trace for requested module:
./index.js" ./index.js
./pages/index.js"
`; `;
...@@ -766,7 +766,8 @@ describe.each([[''], ['/docs']])( ...@@ -766,7 +766,8 @@ describe.each([[''], ['/docs']])(
| js | js
Import trace for requested module: Import trace for requested module:
./components/parse-error.xyz" ./components/parse-error.xyz
./pages/hmr/about8.js"
`) `)
await next.patchFile(aboutPage, aboutContent) await next.patchFile(aboutPage, aboutContent)
......
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