Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-weeks-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

global `setTimeout`, `setInterval` and `setImmediate` now use the one from node
7 changes: 7 additions & 0 deletions examples/playground15/instrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ export function register() {
// variable as recommended in the official docs:
// https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation#importing-runtime-specific-code

const timeout = setTimeout(() => {
console.log("This is a delayed log from the instrumentation register callback");
}, 0);

if (process.env.NEXT_RUNTIME === "nodejs") {
globalThis["__NODEJS_INSTRUMENTATION_SETUP"] =
"this value has been set by calling the instrumentation `register` callback in the nodejs runtime";
// This is to test that we have access to the node version of setTimeout
timeout.unref();
clearTimeout(timeout);
}

if (process.env.NEXT_RUNTIME === "edge") {
Expand Down
4 changes: 4 additions & 0 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
// This define should be safe to use for Next 14.2+, earlier versions (13.5 and less) will cause trouble
"process.env.__NEXT_EXPERIMENTAL_REACT": `${needsExperimentalReact(nextConfig)}`,
},
banner: {
// We need to import them here, assigning them to `globalThis` does not work because node:timers use `globalThis` and thus create an infinite loop
js: `import {setInterval, clearInterval, setTimeout, clearTimeout, setImmediate, clearImmediate} from "node:timers"`,
},
platform: "node",
});

Expand Down