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

Fix: disable script worker in edge and fix rsc loader and runtime (#35604)

* Disable script worker for edge runtime (could lead to build error)
* Fix rsc loader CJS detection
* Fix pagePath searching for per-page runtime

test through rsc notes demo, successful deployment: https://next-rsc-notes-9bix7l1nu.vercel.sh/
parent 24c0fc01
...@@ -960,8 +960,10 @@ export default async function build( ...@@ -960,8 +960,10 @@ export default async function build(
let ssgPageRoutes: string[] | null = null let ssgPageRoutes: string[] | null = null
let isMiddlewareRoute = !!page.match(MIDDLEWARE_ROUTE) let isMiddlewareRoute = !!page.match(MIDDLEWARE_ROUTE)
const pagePath = pagePaths.find((_path) => const pagePath = pagePaths.find(
_path.startsWith(actualPage + '.') (p) =>
p.startsWith(actualPage + '.') ||
p.startsWith(actualPage + '/index.')
) )
const pageRuntime = const pageRuntime =
hasConcurrentFeatures && pagePath hasConcurrentFeatures && pagePath
...@@ -974,7 +976,7 @@ export default async function build( ...@@ -974,7 +976,7 @@ export default async function build(
if ( if (
!isMiddlewareRoute && !isMiddlewareRoute &&
!isReservedPage(page) && !isReservedPage(page) &&
// We currently don't support staic optimization in the Edge runtime. // We currently don't support static optimization in the Edge runtime.
pageRuntime !== 'edge' pageRuntime !== 'edge'
) { ) {
try { try {
......
...@@ -981,6 +981,7 @@ export default async function getBaseWebpackConfig( ...@@ -981,6 +981,7 @@ export default async function getBaseWebpackConfig(
...(isEdgeRuntime ...(isEdgeRuntime
? [ ? [
{ {
'@builder.io/partytown': '{}',
'next/dist/compiled/etag': '{}', 'next/dist/compiled/etag': '{}',
'next/dist/compiled/chalk': '{}', 'next/dist/compiled/chalk': '{}',
'react-dom': '{}', 'react-dom': '{}',
......
...@@ -14,6 +14,7 @@ export function buildExports(moduleExports: any, isESM: boolean) { ...@@ -14,6 +14,7 @@ export function buildExports(moduleExports: any, isESM: boolean) {
const esmNodeTypes = [ const esmNodeTypes = [
'ImportDeclaration', 'ImportDeclaration',
'ExportDeclaration',
'ExportNamedDeclaration', 'ExportNamedDeclaration',
'ExportDefaultExpression', 'ExportDefaultExpression',
'ExportDefaultDeclaration', 'ExportDefaultDeclaration',
......
...@@ -79,7 +79,8 @@ function hasComponentProps(child: any): child is React.ReactElement { ...@@ -79,7 +79,8 @@ function hasComponentProps(child: any): child is React.ReactElement {
function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) { function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) {
const { assetPrefix, scriptLoader, crossOrigin, nextScriptWorkers } = context const { assetPrefix, scriptLoader, crossOrigin, nextScriptWorkers } = context
if (!nextScriptWorkers) return null // disable `nextScriptWorkers` in edge runtime
if (!nextScriptWorkers || process.browser) return null
try { try {
let { let {
......
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