Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-server): expose external client reference via virtual module during dev #187

Merged
merged 12 commits into from
Mar 15, 2024

Conversation

hi-ogawa
Copy link
Owner

@hi-ogawa hi-ogawa commented Mar 15, 2024

By wrapping "use client" node_modules with virtual module on RSC server, this will allow only main server to resolve node modules with correct deps optimization hash.

  • server (RSC)
//// plugin: server-virtual-use-client-node-modules

// some/page.tsx
import { Balancer } from "react-wrap-balancer";
// ⇓ `resolveId` hook to overwrite Vite's "node resolve"
import { Balancer } from "virtual:use-client-node-module/react-wrap-balancer";

// virtual:use-client-node-module/react-wrap-balancer
// ⇓ `load` hook
export const Balancer = createClientReference(
  "/@id/__x00__virtual:use-client-node-module/react-wrap-balancer::Balancer"
)
  • client (SSR and Browser)
//// plugin: client-virtual-use-client-node-modules

// virtual:virtual:use-client-node-module/react-wrap-balancer
// ⇓ `load` hook
export { Balancer } from "react-wrap-balancer";

// client's "node resolve" kicks in, so deps optimization works as usual
react-wrap-balancer example

image

todo

@hi-ogawa hi-ogawa mentioned this pull request Mar 15, 2024
69 tasks
@hi-ogawa hi-ogawa changed the title feat(react-server): expose external client reference via virtual module feat(react-server): expose external client reference via virtual module during dev Mar 15, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review March 15, 2024 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant