Skip to content

Commit

Permalink
Remove process auto polyfill in edge runtime (vercel#65751)
Browse files Browse the repository at this point in the history
### 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 vercel#65692
  • Loading branch information
huozhi authored and panteliselef committed May 20, 2024
1 parent 80f4367 commit f6c4441
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export default async function getBaseWebpackConfig(
reactProductionProfiling,
hasRewrites,
}),
...(isClient || isEdgeServer
...(isClient
? {
fallback: {
process: require.resolve('./polyfills/process'),
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-edge/app-edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/app-dir/app-edge/app/edge-apis/process/page.tsx
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit f6c4441

Please sign in to comment.