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

server: require hook hotfix #55146

Merged
merged 5 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,15 +1248,14 @@ export default async function build(
forkOptions: {
env: {
...process.env,
__NEXT_PRIVATE_RENDER_RUNTIME: type,
__NEXT_INCREMENTAL_CACHE_IPC_PORT: ipcPort + '',
__NEXT_INCREMENTAL_CACHE_IPC_KEY: ipcValidationKey,
__NEXT_PRIVATE_PREBUNDLED_REACT:
type === 'app'
? config.experimental.serverActions
? 'experimental'
: 'next'
: '',
: undefined,
},
},
enableWorkerThreads: config.experimental.workerThreads,
Expand Down
7 changes: 5 additions & 2 deletions packages/next/src/server/lib/server-ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ export const createWorker = async (
__NEXT_PRIVATE_STANDALONE_CONFIG:
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG,
NODE_ENV: process.env.NODE_ENV,
__NEXT_PRIVATE_RENDER_RUNTIME: type,
__NEXT_PRIVATE_PREBUNDLED_REACT:
type === 'app' ? (useServerActions ? 'experimental' : 'next') : '',
type === 'app'
? useServerActions
? 'experimental'
: 'next'
: undefined,
...(process.env.NEXT_CPU_PROF
? { __NEXT_PRIVATE_CPU_PROFILE: `CPU.${type}-renderer` }
: {}),
Expand Down
20 changes: 9 additions & 11 deletions packages/next/src/server/require-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const hookPropertyMap = new Map()

let aliasedPrebundledReact = false

// that env var is only set in app router
ijjk marked this conversation as resolved.
Show resolved Hide resolved
const isApp = !!process.env.__NEXT_PRIVATE_PREBUNDLED_REACT
const currentRuntime = `${
isApp
? 'next/dist/compiled/next-server/app-page.runtime'
: 'next/dist/compiled/next-server/pages.runtime'
}.prod`
ijjk marked this conversation as resolved.
Show resolved Hide resolved

const resolve = process.env.NEXT_MINIMAL
? // @ts-ignore
__non_webpack_require__.resolve
Expand Down Expand Up @@ -122,17 +130,7 @@ mod._resolveFilename = function (
// that needs to point to the rendering runtime version, it will point to the correct one.
// This can happen on `pages` when a user requires a dependency that uses next/image for example.
// This is only needed in production as in development we fallback to the external version.
if (
process.env.NODE_ENV !== 'development' &&
process.env.__NEXT_PRIVATE_RENDER_RUNTIME &&
!process.env.TURBOPACK
) {
const currentRuntime = `${
process.env.__NEXT_PRIVATE_RENDER_RUNTIME === 'pages'
? 'next/dist/compiled/next-server/pages.runtime'
: 'next/dist/compiled/next-server/app-page.runtime'
}.prod`

if (process.env.NODE_ENV !== 'development' && !process.env.TURBOPACK) {
mod.prototype.require = function (request: string) {
if (request.endsWith('.shared-runtime')) {
const base = path.basename(request, '.shared-runtime')
Expand Down