Skip to content

Commit 0b261f0

Browse files
authored
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
1 parent 0840d52 commit 0b261f0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig(
664664
reactProductionProfiling,
665665
hasRewrites,
666666
}),
667-
...(isClient || isEdgeServer
667+
...(isClient
668668
? {
669669
fallback: {
670670
process: require.resolve('./polyfills/process'),

test/e2e/app-dir/app-edge/app-edge.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('app-dir edge SSR', () => {
2424
expect(await res.text()).toInclude('Hello')
2525
})
2626

27+
it('should treat process as object without polyfill in edge runtime', async () => {
28+
const $ = await next.render$('/edge-apis/process')
29+
expect(await $('#process').text()).toContain('object')
30+
})
31+
2732
it('should handle /index routes correctly', async () => {
2833
const appHtml = await next.render('/index')
2934
expect(appHtml).toContain('the /index route')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
3+
export default function Page() {
4+
return (
5+
<>
6+
<p id="process">
7+
{typeof process === 'object'
8+
? typeof process.emit === 'function'
9+
? 'emit'
10+
: 'object'
11+
: 'undefined'}
12+
</p>
13+
</>
14+
)
15+
}
16+
17+
export const runtime = 'edge'

0 commit comments

Comments
 (0)