Skip to content
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

remove legacy transform code #40966

Merged
merged 2 commits into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,25 +20,15 @@ export default async function transformSource(this: any): Promise<string> {
}

const requests = modules as string[]
const code =
requests
// Filter out css files on the server
.filter((request) => (isServer ? !request.endsWith('.css') : true))
.map((request) =>
request.endsWith('.css')
? `(() => import(/* webpackMode: "lazy" */ ${JSON.stringify(
request
)}))`
: `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
)
.join(';\n') +
`
export const __next_rsc__ = {
server: false,
__webpack_require__
};
export default function RSC() {};
`
const code = requests
// Filter out css files on the server
.filter((request) => (isServer ? !request.endsWith('.css') : true))
.map((request) =>
request.endsWith('.css')
? `(() => import(/* webpackMode: "lazy" */ ${JSON.stringify(request)}))`
: `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
)
.join(';\n')

const buildInfo = getModuleBuildInfo(this._module)
const resolve = this.getResolve()
Expand Down
@@ -1,16 +1,7 @@
import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants'
import { getRSCModuleType } from '../../../analysis/get-page-static-info'
import { parse } from '../../../swc'
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(
this: any,
source: string,
Expand All @@ -21,14 +12,8 @@ export default async function transformSource(
throw new Error('Expected source to have been transformed to a string.')
}

const { resourcePath } = this
const callback = this.async()
const buildInfo = getModuleBuildInfo(this._module)
const swcAST = await parse(source, {
filename: resourcePath,
isModule: 'unknown',
})

const rscType = getRSCModuleType(source)

// Assign the RSC meta information to buildInfo.
Expand All @@ -39,7 +24,5 @@ export default async function transformSource(
return callback(null, source, sourceMap)
}

const isModule = swcAST.type === 'Module'
const code = transformServer(source, isModule)
return callback(null, code, sourceMap)
return callback(null, source, sourceMap)
}
10 changes: 3 additions & 7 deletions packages/next/server/app-render.tsx
Expand Up @@ -317,9 +317,6 @@ function createServerComponentRenderer(
ComponentMod: {
renderToReadableStream: any
__next_app_webpack_require__?: any
__next_rsc__?: {
__webpack_require__?: any
}
},
{
transformStream,
Expand All @@ -339,11 +336,9 @@ function createServerComponentRenderer(
): () => JSX.Element {
// We need to expose the `__webpack_require__` API globally for
// 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
globalThis.__next_require__ =
ComponentMod.__next_app_webpack_require__ ||
ComponentMod.__next_rsc__?.__webpack_require__
globalThis.__next_require__ = ComponentMod.__next_app_webpack_require__

// @ts-ignore
globalThis.__next_chunk_load__ = () => Promise.resolve()
Expand Down Expand Up @@ -639,6 +634,7 @@ export async function renderToHTMLOrFlight(
const requestAsyncStorage = ComponentMod.requestAsyncStorage

if (
staticGenerationAsyncStorage &&
!('getStore' in staticGenerationAsyncStorage) &&
staticGenerationAsyncStorage.inUse
) {
Expand Down
13 changes: 2 additions & 11 deletions packages/next/server/base-server.ts
Expand Up @@ -963,15 +963,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
let hasStaticPaths = !!components.getStaticPaths

const hasGetInitialProps = !!components.Component?.getInitialProps
const isServerComponent = !!components.ComponentMod?.__next_rsc__
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')
let isSSG = !!components.getStaticProps

// Toggle whether or not this is a Data request
const isDataReq =
Expand All @@ -980,7 +972,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
(req.headers['x-nextjs-data'] &&
(this.serverOptions as any).webServerConfig)
) &&
(isSSG || hasServerProps || isServerComponent)
(isSSG || hasServerProps)

delete query.__nextDataReq

Expand Down Expand Up @@ -1027,7 +1019,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}

if (
!isServerComponent &&
!!req.headers['x-nextjs-data'] &&
(!res.statusCode || res.statusCode === 200)
) {
Expand Down