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
This commit is contained in:
Jiachi Liu 2024-05-15 12:19:47 +02:00 committed by GitHub
parent 0840d521d5
commit 0b261f0919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View file

@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig(
reactProductionProfiling,
hasRewrites,
}),
...(isClient || isEdgeServer
...(isClient
? {
fallback: {
process: require.resolve('./polyfills/process'),

View file

@ -24,6 +24,11 @@ describe('app-dir edge SSR', () => {
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 () => {
const appHtml = await next.render('/index')
expect(appHtml).toContain('the /index route')

View file

@ -0,0 +1,17 @@
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'