Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jan 5, 2026

Description

Establishes __VITE_ENVIRONMENT_RUNNER_IMPORT__ as a convention for frameworks to integrate custom environment setups with import.meta.viteRsc.loadModule.

declare global {
  function __VITE_ENVIRONMENT_RUNNER_IMPORT__(
    environmentName: string,
    id: string,
  ): Promise<any>
}

The problem:

import.meta.viteRsc.loadModule allows importing modules across environments (e.g., RSC → SSR). By default, both environments run in the main Vite process as RunnableDevEnvironment. However, frameworks like Nitro run environments in separate workers where they can communicate internally but not from the main Vite process.

The convention:

Frameworks with custom environment setups can override this global to provide their own module import logic:

// Default (set by plugin)
globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async (env, id) => {
  return server.environments[env].runner.import(id)
}

// Custom (e.g., worker-based environments)
globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async (env, id) => {
  return myWorkerRunners[environmentname].import(id)
}

This allows import.meta.viteRsc.loadModule to work seamlessly across different runtime configurations without changes to user code.


@hi-ogawa hi-ogawa changed the title feat(rsc): standardize loadModule runner global feat(rsc): standardize import.meta.viteRsc.loadModule runner global Jan 5, 2026
hi-ogawa and others added 2 commits January 5, 2026 16:45
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@hi-ogawa hi-ogawa marked this pull request as ready for review January 5, 2026 07:50
hi-ogawa and others added 2 commits January 5, 2026 17:03
Simplified API from `(environmentName) => Promise<ModuleRunner>` to
`(environmentName, id) => Promise<any>` for better abstraction.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@hi-ogawa hi-ogawa changed the title feat(rsc): standardize import.meta.viteRsc.loadModule runner global feat(rsc): expose __VITE_ENVIRONMENT_RUNNER_IMPORT__ global for dev Jan 5, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): expose __VITE_ENVIRONMENT_RUNNER_IMPORT__ global for dev feat(rsc): establish __VITE_ENVIRONMENT_RUNNER_IMPORT__ convention for custom environment integration Jan 5, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): establish __VITE_ENVIRONMENT_RUNNER_IMPORT__ convention for custom environment integration feat(rsc): use __VITE_ENVIRONMENT_RUNNER_IMPORT__ for import.meta.viteRsc.loadModule global Jan 5, 2026
@hi-ogawa hi-ogawa added the trigger: preview Trigger pkg.pr.new label Jan 5, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/plugin-react@1037
npm i https://pkg.pr.new/@vitejs/plugin-react-oxc@1037
npm i https://pkg.pr.new/@vitejs/plugin-rsc@1037
npm i https://pkg.pr.new/@vitejs/plugin-react-swc@1037

commit: 15fa1bc

@hi-ogawa hi-ogawa merged commit 687458d into main Jan 5, 2026
20 of 21 checks passed
@hi-ogawa hi-ogawa deleted the 01-05-feat_rsc_standardize_loadmodule_runner_global branch January 5, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trigger: preview Trigger pkg.pr.new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants