feat(rsc): add import.meta.viteRsc.import API#1063
Merged
Conversation
- Add architecture.md documenting build pipeline and data flow - Add bundler-comparison.md comparing RSC approaches across bundlers - Add implementation plan for new ergonomic import API - Stub import-environment.ts plugin file Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add import-environment plugin with transform/renderChunk hooks - Dev mode: rewrite to globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ - Build mode: emit marker, resolve in renderChunk to relative import - Auto-discover entries and inject into target environment's input - Handle empty SSR input case in buildApp orchestration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document the preferred implementation using static import functions in a manifest file, which supports custom entryFileNames and enables proper static analysis by bundlers. Key additions: - Manifest with static import functions (not dynamic lookups) - Bidirectional support (RSC → SSR and SSR → RSC) - Updated data flow showing entry injection after both scans - Per-environment manifest generation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…leNames Replace hardcoded output filenames with a manifest approach that supports custom entryFileNames config. The manifest uses static import functions for proper bundler analysis. Changes: - Transform emits manifest lookup instead of markers - resolveId marks manifest as external during build - generateBundle tracks resolvedId → outputFileName mapping - writeEnvironmentImportsManifest generates manifest after all builds - Split entry injection for bidirectional support (RSC↔SSR) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace direct rollupOptions.input mutation with: - Virtual scan placeholder for scan builds without configured entries - emitFile in buildStart for emitting discovered entries in real builds This follows the fullstack plugin pattern and provides cleaner separation between scan and real build phases. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use a placeholder in transform and replace with correct relative path in renderChunk, similar to how BUILD_ASSETS_MANIFEST_NAME is handled. This ensures manifest imports work correctly for nested chunk outputs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Let Rollup auto-name emitted chunks instead of deriving entry names from specifiers. The actual output filename is tracked via generateBundle anyway, so the explicit name was unnecessary. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tMetaMap Add fileName field to EnvironmentImportMeta instead of tracking output filenames in a separate map. This simplifies the data structure and removes the TODO about merging the maps. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use toRelativeId() for manifest keys instead of absolute paths. This ensures stable builds across different machines/environments. Before: "/home/user/.../entry.ssr.tsx" After: "src/framework/entry.ssr.tsx" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change from `Record<resolvedId, meta>` to `Record<sourceEnv, Record<resolvedId, meta>>`. This properly handles the case where the same module is imported from multiple source environments, avoiding overwrites. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
de75327 to
b2b877a
Compare
Add documentation for the new import.meta.viteRsc.import() API in both README.md and types/index.d.ts with JSDoc, examples, and type signatures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…esolution - Replace `rscBundle` with `bundles: Record<string, OutputBundle>` in RscPluginManager - Lookup fileName from bundles in writeEnvironmentImportsManifest instead of mutating meta - Remove generateBundle hook from import-environment plugin (no longer needed) - Remove unused fileName field from EnvironmentImportMeta type Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…nv][resolvedId] - Update type definition to add targetEnv as middle key - Update write logic in transform to use new structure - Update buildStart to lookup by targetEnv directly (more efficient) - Update writeEnvironmentImportsManifest to iterate by targetEnv Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
Add
import.meta.viteRsc.import()- a more ergonomic API for cross-environment module loading.Comparison
Before (
loadModule):After (
import):How it works
__VITE_ENVIRONMENT_RUNNER_IMPORT__(same asloadModule)__vite_rsc_env_imports_manifest.js)Side note: Removal of internal no-ssr build path
This PR removes the internal "no-ssr" build path (4-step pipeline) that was automatically triggered when
ssr.rollupOptions.inputwas not configured. This path was incompatible with auto-discovery—the decision to skip ssr build was made before scanning could discoverimport.meta.viteRsc.importcalls targeting ssr.This is not a breaking change:
customBuildApp(seeexamples/no-ssr)Documentation
README.md- API documentation with comparisontypes/index.d.ts- TypeScript types with JSDocTest plan
🤖 Generated with Claude Code