-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip build-time dynamic code checks for specific polyfills in the Edg…
…e runtime (#52009) As discussed in https://vercel.slack.com/archives/C03ENM5HB4K/p1687999628589119 and #51910, it makes sense to have a known list for packages (mostly polyfills) that we know are having dynamic code (`eval`, `new Function`) but are safe to run in the Edge Runtime because that dynamic code will never be executed.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["function-bind"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createNext } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
|
||
// This test is basically for https://github.com/vercel/next.js/discussions/51910 | ||
// to make sure that some libs that we know are using `eval` but don't break | ||
// because it will never run into that condition, but still can't to be DCE'd. | ||
|
||
describe('Edge safe dynamic code', () => { | ||
let next: NextInstance | ||
|
||
afterAll(() => next.destroy()) | ||
|
||
it('should not fail when "function-bind" package is used', async () => { | ||
next = await createNext({ | ||
skipStart: true, | ||
dependencies: { | ||
'function-bind': 'latest', | ||
}, | ||
files: { | ||
'pages/index.js': ` | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} | ||
`, | ||
'middleware.js': ` | ||
import { NextResponse } from 'next/server' | ||
import * as bind from 'function-bind' | ||
console.log(bind) | ||
export default async function middleware(request) { | ||
return NextResponse.next() | ||
} | ||
`, | ||
}, | ||
}) | ||
await next.start() | ||
|
||
expect(next.cliOutput).not.toContain( | ||
`Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime` | ||
) | ||
}) | ||
}) |