Unverified Commit b16fcccf authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

remove legacy transform code (#40966)

* Remove legacy `__next_rsc__` transform
* Fix `staticGenerationAsyncStorage` is null during rendering
parent 0f41a48f
...@@ -20,25 +20,15 @@ export default async function transformSource(this: any): Promise<string> { ...@@ -20,25 +20,15 @@ export default async function transformSource(this: any): Promise<string> {
} }
const requests = modules as string[] const requests = modules as string[]
const code = const code = requests
requests
// Filter out css files on the server // Filter out css files on the server
.filter((request) => (isServer ? !request.endsWith('.css') : true)) .filter((request) => (isServer ? !request.endsWith('.css') : true))
.map((request) => .map((request) =>
request.endsWith('.css') request.endsWith('.css')
? `(() => import(/* webpackMode: "lazy" */ ${JSON.stringify( ? `(() => import(/* webpackMode: "lazy" */ ${JSON.stringify(request)}))`
request
)}))`
: `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})` : `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
) )
.join(';\n') + .join(';\n')
`
export const __next_rsc__ = {
server: false,
__webpack_require__
};
export default function RSC() {};
`
const buildInfo = getModuleBuildInfo(this._module) const buildInfo = getModuleBuildInfo(this._module)
const resolve = this.getResolve() const resolve = this.getResolve()
......
import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants' import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants'
import { getRSCModuleType } from '../../../analysis/get-page-static-info' import { getRSCModuleType } from '../../../analysis/get-page-static-info'
import { parse } from '../../../swc'
import { getModuleBuildInfo } from '../get-module-build-info' import { getModuleBuildInfo } from '../get-module-build-info'
function transformServer(source: string, isESModule: boolean) {
return (
source +
(isESModule ? `export const __next_rsc__` : `exports.__next_rsc__`) +
` = { __webpack_require__, server: true }\n`
)
}
export default async function transformSource( export default async function transformSource(
this: any, this: any,
source: string, source: string,
...@@ -21,14 +12,8 @@ export default async function transformSource( ...@@ -21,14 +12,8 @@ export default async function transformSource(
throw new Error('Expected source to have been transformed to a string.') throw new Error('Expected source to have been transformed to a string.')
} }
const { resourcePath } = this
const callback = this.async() const callback = this.async()
const buildInfo = getModuleBuildInfo(this._module) const buildInfo = getModuleBuildInfo(this._module)
const swcAST = await parse(source, {
filename: resourcePath,
isModule: 'unknown',
})
const rscType = getRSCModuleType(source) const rscType = getRSCModuleType(source)
// Assign the RSC meta information to buildInfo. // Assign the RSC meta information to buildInfo.
...@@ -39,7 +24,5 @@ export default async function transformSource( ...@@ -39,7 +24,5 @@ export default async function transformSource(
return callback(null, source, sourceMap) return callback(null, source, sourceMap)
} }
const isModule = swcAST.type === 'Module' return callback(null, source, sourceMap)
const code = transformServer(source, isModule)
return callback(null, code, sourceMap)
} }
...@@ -317,9 +317,6 @@ function createServerComponentRenderer( ...@@ -317,9 +317,6 @@ function createServerComponentRenderer(
ComponentMod: { ComponentMod: {
renderToReadableStream: any renderToReadableStream: any
__next_app_webpack_require__?: any __next_app_webpack_require__?: any
__next_rsc__?: {
__webpack_require__?: any
}
}, },
{ {
transformStream, transformStream,
...@@ -339,11 +336,9 @@ function createServerComponentRenderer( ...@@ -339,11 +336,9 @@ function createServerComponentRenderer(
): () => JSX.Element { ): () => JSX.Element {
// We need to expose the `__webpack_require__` API globally for // We need to expose the `__webpack_require__` API globally for
// react-server-dom-webpack. This is a hack until we find a better way. // react-server-dom-webpack. This is a hack until we find a better way.
if (ComponentMod.__next_app_webpack_require__ || ComponentMod.__next_rsc__) { if (ComponentMod.__next_app_webpack_require__) {
// @ts-ignore // @ts-ignore
globalThis.__next_require__ = globalThis.__next_require__ = ComponentMod.__next_app_webpack_require__
ComponentMod.__next_app_webpack_require__ ||
ComponentMod.__next_rsc__?.__webpack_require__
// @ts-ignore // @ts-ignore
globalThis.__next_chunk_load__ = () => Promise.resolve() globalThis.__next_chunk_load__ = () => Promise.resolve()
...@@ -639,6 +634,7 @@ export async function renderToHTMLOrFlight( ...@@ -639,6 +634,7 @@ export async function renderToHTMLOrFlight(
const requestAsyncStorage = ComponentMod.requestAsyncStorage const requestAsyncStorage = ComponentMod.requestAsyncStorage
if ( if (
staticGenerationAsyncStorage &&
!('getStore' in staticGenerationAsyncStorage) && !('getStore' in staticGenerationAsyncStorage) &&
staticGenerationAsyncStorage.inUse staticGenerationAsyncStorage.inUse
) { ) {
......
...@@ -963,15 +963,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -963,15 +963,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
let hasStaticPaths = !!components.getStaticPaths let hasStaticPaths = !!components.getStaticPaths
const hasGetInitialProps = !!components.Component?.getInitialProps const hasGetInitialProps = !!components.Component?.getInitialProps
const isServerComponent = !!components.ComponentMod?.__next_rsc__ let isSSG = !!components.getStaticProps
let isSSG =
!!components.getStaticProps ||
// For static server component pages, we currently always consider them
// as SSG since we also need to handle the next data (flight JSON).
(isServerComponent &&
!hasServerProps &&
!hasGetInitialProps &&
process.env.NEXT_RUNTIME !== 'edge')
// Toggle whether or not this is a Data request // Toggle whether or not this is a Data request
const isDataReq = const isDataReq =
...@@ -980,7 +972,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -980,7 +972,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
(req.headers['x-nextjs-data'] && (req.headers['x-nextjs-data'] &&
(this.serverOptions as any).webServerConfig) (this.serverOptions as any).webServerConfig)
) && ) &&
(isSSG || hasServerProps || isServerComponent) (isSSG || hasServerProps)
delete query.__nextDataReq delete query.__nextDataReq
...@@ -1027,7 +1019,6 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1027,7 +1019,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} }
if ( if (
!isServerComponent &&
!!req.headers['x-nextjs-data'] && !!req.headers['x-nextjs-data'] &&
(!res.statusCode || res.statusCode === 200) (!res.statusCode || res.statusCode === 200)
) { ) {
......
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