feat(core): add cloudflare flushing logic to core util #18330
Closed
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.