Skip to content

Server runtime optimizer turns on prebundling in Vite's unused Node ssr environment #412

Closed

Description

@Brooooooklyn

Summary

In apps where Void owns the workerd runtime, #407's optimizeDeps.include: ['void > email-validator'] goes to every non-client environment. In default (no-framework) mode that includes Vite's built-in Node ssr environment, which these apps never use, because the app runs in void_worker.

Cause

Vite turns off the dep optimizer for server environments only when noDiscovery && !include.length. A non-empty include therefore starts an optimizer for ssr, and DevEnvironment.listen() waits for it to finish. The result is an extra optimizer pass at dev startup and an extra node_modules/.vite/deps_ssr cache directory.

This contradicts the comment in createServerRuntimeOptimizerPlugin, which says forcing an include on a Node environment "turns on SSR prebundling the framework did not ask for".

Impact is small: nothing breaks. React pages mode already turns on the ssr optimizer, so this mainly affects other no-framework apps.

Reproduction

On playground/spa (or any API-only app), run rm -rf node_modules/.vite && vp dev. node_modules/.vite/deps_ssr/_metadata.json now exists and lists void > email-validator. Before #407 there was no deps_ssr.

Suggested fix

Add the include only to the environments the Cloudflare plugin runs in workerd: void_worker in default mode, the configured viteEnvironment and its child environments for class-a frameworks, and auxiliary workers. Every other non-client environment keeps just exclude: ['void']. Add a unit case asserting the default-mode ssr environment resolves to { optimizeDeps: { exclude: ['void'] } }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions