feat(core): add cloudflare flushing logic to core util#18330
Closed
feat(core): add cloudflare flushing logic to core util#18330
Conversation
Member
Author
|
Opened this too early, I will need to first investigate if this is available in all cloudflare workers environments or just opennext's because it seems like so which didn't occur to me. Will re-open if that is the case, sorry for pinging reviews too early. |
Contributor
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
logaretm
added a commit
that referenced
this pull request
Nov 26, 2025
This is part of the work done for supporting Next.js on cloudflare workers in #14931, one of the issues is our flusher didn't take cloudflare into account and the events were being cut off due to early shutdowns by the worker environment. We cannot use our core's `flushIfServerless` because it requires explicit `cloudflareWaitUntil` to be passed down to it. Also The symbol we are grabbing here is [specific to opennext](https://github.com/opennextjs/opennextjs-cloudflare/blob/b53a046bd5c30e94a42e36b67747cefbf7785f9a/packages/cloudflare/src/cli/templates/init.ts#L17) and isn't something that is globally available on the worker environment. I had initially created #18330 because I mistook it for a worker environment API thing. So this PR adds that detection to Next.js since it is relevant here and will use it if available, local tests show flushing is done correctly and events aren't being cut off.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was working on investigating Next.js support on Cloudflare workers, and we aren't getting any traces or errors for a few reasons. One of the issues relevant to this PR is our flushing did not handle Cloudflare’s
waitUntilunless passed explicitly.This is not feasible within some platforms due to them abstracting away the handler entry away from the user (e.g: opennext).
So I dug around the runtime and found that it was possible to grab it via a symbol similar to
VercelWaitUntil. The implementation here checks if it is available, and if it is, then it uses it.This can be useful for many other SDKs as previously it was always required to pass the Cloudflare from the context around.
Note: that this doesn't fix the Next.js issues support completely as I still need to do some other fixes on the SDK level.
What I considered
waitUntilfrom thecloudflare:workers, but it is tricky to include at the core level as an external, and also very weird to include in other SDKs.