-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Component Module Types #56454
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
Component Module Types #56454
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
// @ts-ignore this need to be imported from next/dist to be external | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this not valid anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the import hits the ".js" |
||
import * as module from 'next/dist/server/future/route-modules/pages/module.compiled' | ||
import { PagesRouteModule } from '../../server/future/route-modules/pages/module.compiled' | ||
import { RouteKind } from '../../server/future/route-kind' | ||
import { hoist } from './helpers' | ||
|
||
// Import the app and document modules. | ||
// @ts-expect-error - replaced by webpack/turbopack loader | ||
import Document from 'VAR_MODULE_DOCUMENT' | ||
// @ts-expect-error - replaced by webpack/turbopack loader | ||
import App from 'VAR_MODULE_APP' | ||
|
||
// Import the userland code. | ||
// @ts-expect-error - replaced by webpack/turbopack loader | ||
import * as userland from 'VAR_USERLAND' | ||
|
||
const PagesRouteModule = | ||
module.PagesRouteModule as unknown as typeof import('../../server/future/route-modules/pages/module').PagesRouteModule | ||
|
||
Comment on lines
-16
to
-18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can go away now 😌 |
||
// Re-export the component (should be the default export). | ||
export default hoist(userland, 'default') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,6 @@ import type { | |
RenderOpts, | ||
Segment, | ||
} from './types' | ||
import type { StaticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage.external' | ||
import type { StaticGenerationBailout } from '../../client/components/static-generation-bailout' | ||
import type { RequestAsyncStorage } from '../../client/components/request-async-storage.external' | ||
|
||
import React from 'react' | ||
import { createServerComponentRenderer } from './create-server-components-renderer' | ||
|
@@ -237,6 +234,7 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
}) | ||
|
||
patchFetch(ComponentMod) | ||
|
||
/** | ||
* Rules of Static & Dynamic HTML: | ||
* | ||
|
@@ -252,12 +250,25 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
*/ | ||
const generateStaticHTML = supportsDynamicHTML !== true | ||
|
||
const staticGenerationAsyncStorage: StaticGenerationAsyncStorage = | ||
ComponentMod.staticGenerationAsyncStorage | ||
const requestAsyncStorage: RequestAsyncStorage = | ||
ComponentMod.requestAsyncStorage | ||
const staticGenerationBailout: StaticGenerationBailout = | ||
ComponentMod.staticGenerationBailout | ||
// Pull out the hooks/references from the component. | ||
const { | ||
staticGenerationAsyncStorage, | ||
requestAsyncStorage, | ||
staticGenerationBailout, | ||
LayoutRouter, | ||
RenderFromTemplateContext, | ||
createSearchParamsBailoutProxy, | ||
StaticGenerationSearchParamsBailoutProvider, | ||
serverHooks: { DynamicServerError }, | ||
NotFoundBoundary, | ||
renderToReadableStream, | ||
AppRouter, | ||
GlobalError, | ||
tree: loaderTree, | ||
preloadFont, | ||
preconnect, | ||
preloadStyle, | ||
} = ComponentMod | ||
|
||
// we wrap the render in an AsyncLocalStorage context | ||
const wrappedRender = async () => { | ||
|
@@ -294,11 +305,6 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
) | ||
: undefined | ||
|
||
/** | ||
* The tree created in next-app-loader that holds component segments and modules | ||
*/ | ||
const loaderTree: LoaderTree = ComponentMod.tree | ||
|
||
/** | ||
* The metadata items array created in next-app-loader with all relevant information | ||
* that we need to resolve the final metadata. | ||
|
@@ -312,15 +318,6 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
requestId = require('next/dist/compiled/nanoid').nanoid() | ||
} | ||
|
||
const LayoutRouter = | ||
ComponentMod.LayoutRouter as typeof import('../../client/components/layout-router').default | ||
const RenderFromTemplateContext = | ||
ComponentMod.RenderFromTemplateContext as typeof import('../../client/components/render-from-template-context').default | ||
const createSearchParamsBailoutProxy = | ||
ComponentMod.createSearchParamsBailoutProxy as typeof import('../../client/components/searchparams-bailout-proxy').createSearchParamsBailoutProxy | ||
const StaticGenerationSearchParamsBailoutProvider = | ||
ComponentMod.StaticGenerationSearchParamsBailoutProvider as typeof import('../../client/components/static-generation-searchparams-bailout-provider').default | ||
|
||
Comment on lines
-315
to
-323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes mean that we don't need to do type assertions anymore 😎 |
||
const isStaticGeneration = staticGenerationStore.isStaticGeneration | ||
// During static generation we need to call the static generation bailout when reading searchParams | ||
const providedSearchParams = isStaticGeneration | ||
|
@@ -511,16 +508,16 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFilename)![1] | ||
const type = `font/${ext}` | ||
const href = `${assetPrefix}/_next/${fontFilename}` | ||
ComponentMod.preloadFont(href, type, renderOpts.crossOrigin) | ||
preloadFont(href, type, renderOpts.crossOrigin) | ||
} | ||
} else { | ||
try { | ||
let url = new URL(assetPrefix) | ||
ComponentMod.preconnect(url.origin, 'anonymous') | ||
preconnect(url.origin, 'anonymous') | ||
} catch (error) { | ||
// assetPrefix must not be a fully qualified domain name. We assume | ||
// we should preconnect to same origin instead | ||
ComponentMod.preconnect('/', 'anonymous') | ||
preconnect('/', 'anonymous') | ||
} | ||
} | ||
} | ||
|
@@ -546,7 +543,7 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
const precedence = | ||
process.env.NODE_ENV === 'development' ? 'next_' + href : 'next' | ||
|
||
ComponentMod.preloadStyle(fullHref, renderOpts.crossOrigin) | ||
preloadStyle(fullHref, renderOpts.crossOrigin) | ||
|
||
return ( | ||
<link | ||
|
@@ -732,9 +729,6 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
staticGenerationStore.isStaticGeneration && | ||
defaultRevalidate === 0 | ||
) { | ||
const { DynamicServerError } = | ||
ComponentMod.serverHooks as typeof import('../../client/components/hooks-server-context') | ||
|
||
const dynamicUsageDescription = `revalidate: 0 configured ${segment}` | ||
staticGenerationStore.dynamicUsageDescription = | ||
dynamicUsageDescription | ||
|
@@ -759,8 +753,6 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
const hasSlotKey = parallelKeys.length > 1 | ||
|
||
if (hasSlotKey && rootLayoutAtThisLevel) { | ||
const NotFoundBoundary = | ||
ComponentMod.NotFoundBoundary as typeof import('../../client/components/not-found-boundary').NotFoundBoundary | ||
Component = (componentProps: any) => { | ||
const NotFoundComponent = NotFound | ||
const RootLayoutComponent = LayoutOrPage | ||
|
@@ -1287,7 +1279,7 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
|
||
// For app dir, use the bundled version of Flight server renderer (renderToReadableStream) | ||
// which contains the subset React. | ||
const flightReadableStream = ComponentMod.renderToReadableStream( | ||
const flightReadableStream = renderToReadableStream( | ||
options | ||
? [options.actionResult, buildIdFlightDataPair] | ||
: buildIdFlightDataPair, | ||
|
@@ -1305,16 +1297,6 @@ export const renderToHTMLOrFlight: AppPageRender = ( | |
return generateFlight() | ||
} | ||
|
||
// Below this line is handling for rendering to HTML. | ||
|
||
// AppRouter is provided by next-app-loader | ||
const AppRouter = | ||
ComponentMod.AppRouter as typeof import('../../client/components/app-router').default | ||
|
||
const GlobalError = | ||
/** GlobalError can be either the default error boundary or the overwritten app/global-error.js **/ | ||
ComponentMod.GlobalError as typeof import('../../client/components/error-boundary').GlobalError | ||
|
||
// Get the nonce from the incoming request if it has one. | ||
const csp = req.headers['content-security-policy'] | ||
let nonce: string | undefined | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative imports are possible because the
.js
file references the compiled dist runtime, thereby ensuring it remains external