Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Cloudflare execution context to server components
Using the getEnv API for now until dai-shi#827 is resolved Example usage: ```ts const ctx = getEnv("ctx") as unknown as ExecutionContext | undefined; ctx?.waitUntil( new Promise<void>((resolve) => { console.log("Waiting for 5 seconds") setTimeout(() => { console.log("OK, done waiting") resolve() }, 5000) }), ) ``` Server console output: ``` Waiting for 5 seconds [wrangler:inf] GET /about 200 OK (30ms) [wrangler:inf] GET /assets/jsx-runtime-BjG_zV1W.js 304 Not Modified (6ms) [wrangler:inf] GET /assets/index-CbskofAj.js 304 Not Modified (7ms) [wrangler:inf] GET /assets/_layout-Shb4QlRw.css 304 Not Modified (9ms) [wrangler:inf] GET /assets/rsc2-c69df7b3e.js 200 OK (11ms) [wrangler:inf] GET /assets/client-kczTGGZ_.js 304 Not Modified (16ms) [wrangler:inf] GET /assets/indexHtml-DCalQi_d.js 304 Not Modified (18ms) [wrangler:inf] GET /assets/client-CMyJdxTj.js 304 Not Modified (21ms) [wrangler:inf] GET /assets/rsc0-ba005381c.js 304 Not Modified (4ms) [wrangler:inf] GET /images/favicon.png 304 Not Modified (3ms) OK, done waiting ``` The page was already sent to the client and loaded while the promise was still executing. It is necessary to cast the Cloudflare types for now. See https://developers.cloudflare.com/workers/languages/typescript/#generate-types-that-match-your-workers-configuration-experimental for info on generating types for your project.
- Loading branch information