Add experimental prerenderWorker option#11697
Conversation
🦋 Changeset detectedLatest commit: a740392 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
bae5826 to
8033489
Compare
|
We have this working in withastro/astro#15077 This change works for us. |
8033489 to
8e303f7
Compare
|
Claude finished @jamesopstad's task —— View job Changeset Review✅ All changesets look good The changeset in
|
8e303f7 to
a6a6539
Compare
| @@ -76,6 +79,8 @@ export function createBuildApp( | |||
| return; | |||
| } | |||
|
|
|||
| // TODO: move static assets from the prerender environment to the client environment | |||
There was a problem hiding this comment.
I started working on this but it is quite complex and is not currently needed so I decided to leave it for now.
| @@ -166,6 +166,7 @@ function readWorkerConfig( | |||
| }; | |||
| } | |||
|
|
|||
| // TODO: separate prerender Worker warnings from auxiliary Worker warnings | |||
There was a problem hiding this comment.
This can also be left for now I think as in Astro the concept of a pre-render Worker will be invisible to the user.
| // This environment variable is used to indicate to the preview server that it is being run during a build | ||
| // We need to delete it here as, during testing, preview also runs in the same process after the build completes | ||
| // eslint-disable-next-line turbo/no-undeclared-env-vars | ||
| delete process.env.CLOUDFLARE_VITE_BUILD; |
There was a problem hiding this comment.
Just thinking out loud, would it be safer to clean up the env var through the vite plugin? Just in case our users run into the same problem?
There was a problem hiding this comment.
I would like to do that but I'm not sure how. Any suggestions?
There was a problem hiding this comment.
I can't figure out a reliable way to clean it up in the right timing as well :(
There was a problem hiding this comment.
A brittle way to handle this would be setting the env var only if prerenderWorker is configured, then monkey-patching previewServer.close() to clean that up. 😅
There was a problem hiding this comment.
Yeah, that is an option. The downside is that it relies on the preview server only being run once for pre-rendering. That's probably a safe assumption to make but I'm not sure. Let's leave for now and revisit.
edmundhung
left a comment
There was a problem hiding this comment.
Looking good. Just some nits.
…un during the build
a12560b to
a740392
Compare
Adds an experimental
prerenderWorkeroption for defining a dedicated Worker for pre-rendering.Example:
Internally, the plugin now sets an environment variable during the build that indicates to the preview server that the prerender Worker should be used as the entry. This means that the Vite preview server can be used during the build to send requests to the prerender Worker.
A picture of a cute animal (not mandatory, but encouraged)