Architectural Invariant Design: Vite 6 Heterogeneous SSR Runtime Isolation via Environment API
Vite 6 Heterogeneous SSR Runtime Isolation via Environment API defines an industrial-grade behavioral standard for frontend engineering. Enforces strict runtime-agnostic module separation and module graph isolation across Node.js, WinterCG (Edge), and Browser environments utilizing Vite 6's Environment API. Prevents cross-environment global pollution, host-specific built-in leakage, and shared runtime singleton corruption during multi-target SSR compilation and hydration. 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 | Monolithic SSR Module Graph and Cross-Contaminating Host Primitives | 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 declare explicit isolated environment profiles under `environments` in `vite.config.ts` (e.g., `client`, `ssrNode`, `ssrEdge`) rather than relying on legacy top-level `ssr` configurations.
Engineers MUST ALWAYS declare explicit isolated environment profiles under `environments` in `vite.config.ts` (e.g., `client`, `ssrNode`, `ssrEdge`) rather than relying on legacy top-level `ssr` configurations.
Engineers MUST NOT leak Node.js core built-ins (e.g., `node
Engineers MUST NOT leak Node.js core built-ins (e.g., `node:fs`, `node:crypto`, `node:path`) into modules resolved within WinterCG, Edge, or Browser environment targets.
Code targeting heterogeneous runtimes MUST decouple environment-specific side-effects behind explicit dependency injection interfaces or runtime capabilities checks, never top-level un-guarded global references (`process`, `Deno`, or `WebSocketPair`).
Code targeting heterogeneous runtimes MUST decouple environment-specific side-effects behind explicit dependency injection interfaces or runtime capabilities checks, never top-level un-guarded global references (`process`, `Deno`, or `WebSocketPair`).
Module runners MUST be instantiated uniquely per environment using Vite 6's `ModuleRunner` or specialized `DevEnvironment` runners to eliminate shared module cache pollution between Edge and Node targets during local development.
Module runners MUST be instantiated uniquely per environment using Vite 6's `ModuleRunner` or specialized `DevEnvironment` runners to eliminate shared module cache pollution between Edge and Node targets during local development.
Vite configuration MUST explicitly declare discrete `resolve.conditions` per environment (e.g., `['node', 'import']` vs `['workerd', 'worker', 'import']` vs `['browser', 'import']`).
Vite configuration MUST explicitly declare discrete `resolve.conditions` per environment (e.g., `['node', 'import']` vs `['workerd', 'worker', 'import']` vs `['browser', 'import']`).
Shared route modules and components NEVER evaluate runtime-specific singletons at module scope
Shared route modules and components NEVER evaluate runtime-specific singletons at module scope; any platform-specific persistence or state MUST be bound to request-scoped context.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Vite 6 Heterogeneous SSR Runtime Isolation via Environment API critical for AI coding assistants?
Enforces strict runtime-agnostic module separation and module graph isolation across Node.js, WinterCG (Edge), and Browser environments utilizing Vite 6's Environment API. Prevents cross-environment global pollution, host-specific built-in leakage, and shared runtime singleton corruption during multi-target SSR compilation and hydration. 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 (Monolithic SSR Module Graph and Cross-Contaminating Host Primitives) 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.