Architectural Invariant Design: Vite 6 Environment API Multi-Runtime SSR Isolation Protocol
Vite 6 Environment API Multi-Runtime SSR Isolation Protocol defines an industrial-grade behavioral standard for frontend engineering. Enforces strict isolated execution boundaries and per-runtime ModuleRunner instances when leveraging the Vite 6 Environment API across heterogeneous targets (e.g., Client, Node.js SSR, and Cloudflare Workers). Eliminates cross-environment state leaks, shared module graph contamination, and illegal global namespace access between isolated worker runtimes and host processes. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
Hazard Analysis: What Breaks Without This Rule
The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:
| Failure Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Global Module Graph Bleed and Shared ModuleRunner Execution Across Heterogeneous Runtimes | Critical | Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production. Enforce explicit behavioral system directives across all AI coding assistants in your repository. |
| Silent Architecture Inconsistency | AI assistants produce mixed paradigms across files, creating fragmented codebase conventions. | Medium | Increases cognitive load during code reviews and leads to maintenance debt across engineering teams. Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS configure explicit named environments (`client`, `ssr`, `workerd`, etc.) under `environments` in `vite.config.ts` rather than relying on legacy SSR booleans.
Engineers MUST ALWAYS configure explicit named environments (`client`, `ssr`, `workerd`, etc.) under `environments` in `vite.config.ts` rather than relying on legacy SSR booleans.
Engineers MUST instantiate separate, dedicated `ModuleRunner` or `createRunnableDevEnvironment` consumers for each runtime environment target to prevent module cache pollution.
Engineers MUST instantiate separate, dedicated `ModuleRunner` or `createRunnableDevEnvironment` consumers for each runtime environment target to prevent module cache pollution.
Engineers MUST NOT reference Node-specific globals (`process.env`, `fs`, `path`) inside non-Node runtime environments such as edge workers or browser modules without conditional compile-time isolation.
Engineers MUST NOT reference Node-specific globals (`process.env`, `fs`, `path`) inside non-Node runtime environments such as edge workers or browser modules without conditional compile-time isolation.
Code executing in edge environments MUST resolve dependencies using `resolve.conditions` configured explicitly for that target environment (e.g., `['worker', 'workerd']`).
Code executing in edge environments MUST resolve dependencies using `resolve.conditions` configured explicitly for that target environment (e.g., `['worker', 'workerd']`).
Services MUST communicate across Vite 6 environments exclusively via structured `hot.send` or decoupled communication channels, NEVER by passing mutable in-memory module graph nodes.
Services MUST communicate across Vite 6 environments exclusively via structured `hot.send` or decoupled communication channels, NEVER by passing mutable in-memory module graph nodes.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Vite 6 Environment API Multi-Runtime SSR Isolation Protocol critical for AI coding assistants?
Enforces strict isolated execution boundaries and per-runtime ModuleRunner instances when leveraging the Vite 6 Environment API across heterogeneous targets (e.g., Client, Node.js SSR, and Cloudflare Workers). Eliminates cross-environment state leaks, shared module graph contamination, and illegal global namespace access between isolated worker runtimes and host processes. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.
Q:How does adopting this rule prevent AI hallucinations?
This rule explicitly declares what the AI must avoid (Global Module Graph Bleed and Shared ModuleRunner Execution Across Heterogeneous Runtimes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.
Q:Which AI coding environments are supported?
This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).
Q:Can I combine this rule with other technology stacks?
Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.