Skip to content

refactor(rsc): remove server optimizeDeps.include in favor of cjs module runner transform #692

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

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ export default function vitePluginRsc(
},
optimizeDeps: {
include: [
'react',
'react-dom',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-dom/server.edge',
`${REACT_SERVER_DOM_NAME}/client.edge`,
// 'react',
// 'react-dom',
// 'react/jsx-runtime',
// 'react/jsx-dev-runtime',
// 'react-dom/server.edge',
// `${REACT_SERVER_DOM_NAME}/client.edge`,
],
exclude: [PKG_NAME],
},
Expand All @@ -337,12 +337,12 @@ export default function vitePluginRsc(
},
optimizeDeps: {
include: [
'react',
'react-dom',
'react/jsx-runtime',
'react/jsx-dev-runtime',
`${REACT_SERVER_DOM_NAME}/server.edge`,
`${REACT_SERVER_DOM_NAME}/client.edge`,
// 'react',
// 'react-dom',
// 'react/jsx-runtime',
// 'react/jsx-dev-runtime',
// `${REACT_SERVER_DOM_NAME}/server.edge`,
// `${REACT_SERVER_DOM_NAME}/client.edge`,
],
exclude: [PKG_NAME],
},
Expand Down
14 changes: 13 additions & 1 deletion packages/plugin-rsc/src/plugins/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function cjsModuleRunnerPlugin(): Plugin[] {
applyToEnvironment: (env) => env.config.dev.moduleRunnerTransform,
async transform(code, id) {
if (
id.includes('/node_modules/') &&
(id.includes('/node_modules/') || isDevCjs(id)) &&
!id.startsWith(this.environment.config.cacheDir) &&
/\b(require|exports)\b/.test(code)
) {
Expand Down Expand Up @@ -72,6 +72,10 @@ export default module.exports;
}

function extractPackageKey(id: string): string {
if (isDevCjs(id)) {
return '@vitejs/plugin-rsc'
}

// .../.yarn/cache/abc/... => abc
const yarnMatch = id.match(/\/.yarn\/cache\/([^/]+)/)
if (yarnMatch) {
Expand All @@ -89,3 +93,11 @@ function extractPackageKey(id: string): string {
}
return id
}

// this is needed only when developing package itself within pnpm workspace
function isDevCjs(id: string): boolean {
return (
!import.meta.url.includes('/node_modules/') &&
id.includes('/vendor/react-server-dom/')
)
}
Loading