Open
Conversation
🦋 Changeset detectedLatest commit: a5507cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This was
linked to
issues
Mar 20, 2026
This was
linked to
issues
Mar 20, 2026
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
teemingc
commented
Apr 25, 2026
| }); | ||
|
|
||
| test('skips optimizing +page.server.js dependencies', async ({ page }) => { | ||
| test('optimizes +page.server.js dependencies', async ({ page }) => { |
Member
Author
There was a problem hiding this comment.
These tests are now flipped around because they were only there when Vite was still using esbuild and it didn't play well with CJS deps. This is no longer an issue now that optimizeDeps uses Rolldown and resolves the CJS -> ESM conversion
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
teemingc
commented
Apr 26, 2026
| import 'vite/types/customEvent.d.ts'; | ||
| import type { PageOptions } from './static_analysis/index.js'; | ||
|
|
||
| declare module 'vite/types/customEvent.d.ts' { |
Member
Author
There was a problem hiding this comment.
Types the import.meta.hot and environments.ssr.hot APIs
teemingc
commented
Apr 27, 2026
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.
This PR changes the dev, preview, build analysis and prerender to run inside of the configured Vite SSR environment. This required the following fundamental changes:
1. Avoiding Node.js imports in the runtime
node:fsis a requirement but we import it in the main process instead and communicate the results back to the Vite SSR environment.AsyncLocalStorage.enterWithbecause it's a Node.js-only experimental API2. Replacing Vite's
ssrLoadModuleThe Vite docs recommendation is to create a
ModuleRunneror theRunnableDevEnvironmentinstance to achieve a similar functionality but these don't work with Cloudflare's environment. There's also no strict contract for environments to make these available to us so they can't be relied on. We solve this in two different ways:import.meta.hot.onin the SSR environment to listen for events from the main process, compute the result, and send it back.Serverclass from the build output in the main process, we spin up a Vite development server with the build output but proxy theServerclass by intercepting module resolution with Vite'sresolveIdhook. Starting a dev server and sending a request or HMR event seems to be the only way to run a module in the environment.3. Communication between the main process (where Vite runs) and the SSR environment (where user code runs)
The two points before this makes this a requirement. Now we'll detail the different types of communication that exist as a result:
One way communication
environments.ssr.hot.send. This helps us retain synchronous access to the filesystem from a non-Node environment such as checking if a filename exists as a key in the server assets map. We can also construct virtual modules with serialised data that the can be imported and accessed in the environment.import.meta.hot.sendso that the main process can then create a Vite error overlay in the browser. This replaces ourloudSsrLoadModuleutility.Two way communication
ssrLoadModuleto run some code in Vite's pipeline and get a result back. Now, we have to ensure the SSR environment has animport.meta.hot.onevent listener attached, emit an event, compute in the environment, and receive the results back in the main process throughenvironments.ssr.hot.onandPromise.withResolversto await the result. This is used for retrieving remote function info, etc. Alternatively, we can also proxy theServerclass during analysis and prerendering to respond with our environment computed result as mentioned earlier.import.meta.hotapproach above because Cloudflare's workerd doesn't like responding to requests from a context created byimport.meta.hot.on. Therefore, we usefetchto send a request to the running Vite dev server, configure the Vite dev server using theconfigureServerhook to intercept the request viavite.middlewares.use, and respond with the computed result. This is primarily used for getting CSS to inline to avoid FOUC during dev, finding out which param matchers exist from the filesystem, or even checking if a feature should be allowed by theadapter.supportsfunction which we can't serialise.Most of the
import.meta.hotandfetchstyle communication requires serialising and deserialising data usingdevalue.Future PRs
sirvon the build output instead of running the SSR serverPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits