forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turbopack: improve edge runtime checker (vercel#70184)
Closes PACK-3254 1. Previously, guards were never removed, so a single if statement containing `if(clearImmediate)` would mean that it's valid in the whole file to use `clearImmediate` anywhere. Now it's only valid inside the bodies of conditional. I haven't seen any additional lints caused by this. 2. `if(process.env.NEXT_RUNTIME === 'edge')` guards are now respected There are new test cases for each of these. One new warning from this is the following from `react/cjs/react.development.js` where the unrelated `typeof` doesn't silence the error for `new MessageChannel()` anymore ``` function enqueueTask(task) { if (null === enqueueTaskImpl) try { var requireString = ("require" + Math.random()).slice(0, 7); enqueueTaskImpl = (module && module[requireString]).call( module, "timers" ).setImmediate; } catch (_err) { enqueueTaskImpl = function (callback) { !1 === didWarnAboutMessageChannel && ((didWarnAboutMessageChannel = !0), "undefined" === typeof MessageChannel && console.error( "This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning." )); var channel = new MessageChannel(); /// <--------- channel.port1.onmessage = callback; channel.port2.postMessage(void 0); }; } return enqueueTaskImpl(task); } ```
- Loading branch information
Showing
6 changed files
with
95 additions
and
20 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
5 changes: 5 additions & 0 deletions
5
crates/next-custom-transforms/tests/fixture/edge-assert/guarded-runtime-process/input.js
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,5 @@ | ||
if (process.env.NEXT_RUNTIME === 'edge') { | ||
setTimeout(cb, 0) | ||
} else { | ||
setImmediate(cb) | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/next-custom-transforms/tests/fixture/edge-assert/guarded-runtime-process/output.js
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,5 @@ | ||
if (process.env.NEXT_RUNTIME === 'edge') { | ||
setTimeout(cb, 0); | ||
} else { | ||
setImmediate(cb); | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/next-custom-transforms/tests/fixture/edge-assert/mixed-process-api/input.js
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,7 @@ | ||
if (typeof process.loadEnvFile === 'function') { | ||
console.log(process.loadEnvFile()) | ||
} | ||
|
||
typeof process.loadEnvFile === 'function' && process.loadEnvFile() | ||
|
||
console.log(process.loadEnvFile()) |
5 changes: 5 additions & 0 deletions
5
crates/next-custom-transforms/tests/fixture/edge-assert/mixed-process-api/output.js
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,5 @@ | ||
if (typeof process.loadEnvFile === 'function') { | ||
console.log(process.loadEnvFile()); | ||
} | ||
typeof process.loadEnvFile === 'function' && process.loadEnvFile(); | ||
console.log(process.loadEnvFile()); |
7 changes: 7 additions & 0 deletions
7
crates/next-custom-transforms/tests/fixture/edge-assert/mixed-process-api/output.stderr
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,7 @@ | ||
x A Node.js API is used (process.loadEnvFile at line: 7) which is not supported in the Edge Runtime. | ||
| Learn more: https://nextjs.org/docs/api-reference/edge-runtime | ||
,-[input.js:7:1] | ||
6 | | ||
7 | console.log(process.loadEnvFile()) | ||
: ^^^^^^^^^^^^^^^^^^^ | ||
`---- |