Unverified Commit 0b261f09 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Remove process auto polyfill in edge runtime (#65751)

### What

Disable auto polyfill for process in edge runtime.

### Why

React uses process.emit behind a typeof guard now. This leads to process
being bundled and process.emit being called which triggers build
warnings since we stub process APIs since they're not supported in Edge
runtime.

There's condition like `"object" === typeof process && "function" ===
typeof process.emit` in the react build now where the 2nd condition is
falsy. Stop polyfilling to skip that condition since it's mainly for
Node.js runtime

Related to #65692
parent 0840d521
...@@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig( ...@@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig(
reactProductionProfiling, reactProductionProfiling,
hasRewrites, hasRewrites,
}), }),
...(isClient || isEdgeServer ...(isClient
? { ? {
fallback: { fallback: {
process: require.resolve('./polyfills/process'), process: require.resolve('./polyfills/process'),
......
...@@ -24,6 +24,11 @@ describe('app-dir edge SSR', () => { ...@@ -24,6 +24,11 @@ describe('app-dir edge SSR', () => {
expect(await res.text()).toInclude('Hello') expect(await res.text()).toInclude('Hello')
}) })
it('should treat process as object without polyfill in edge runtime', async () => {
const $ = await next.render$('/edge-apis/process')
expect(await $('#process').text()).toContain('object')
})
it('should handle /index routes correctly', async () => { it('should handle /index routes correctly', async () => {
const appHtml = await next.render('/index') const appHtml = await next.render('/index')
expect(appHtml).toContain('the /index route') expect(appHtml).toContain('the /index route')
......
import React from 'react'
export default function Page() {
return (
<>
<p id="process">
{typeof process === 'object'
? typeof process.emit === 'function'
? 'emit'
: 'object'
: 'undefined'}
</p>
</>
)
}
export const runtime = 'edge'
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