Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Aug 30, 2025

Description

Summary

  • expose RscPluginManager as plugin api, which can be used to implement simplified version of build pipeline on user land.
  • fix hard coded "rsc" in vitePluginDefineEncryptionKey
  • updated examples/browser-mode

TODO

  • build
  • replace module runner
  • client reference
  • server reference
  • test

@hi-ogawa hi-ogawa marked this pull request as ready for review August 30, 2025 06:35
@hi-ogawa hi-ogawa added the trigger: preview Trigger pkg.pr.new label Aug 30, 2025
Copy link

pkg-pr-new bot commented Aug 30, 2025

Open in StackBlitz

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

commit: 91c3bf7

Comment on lines +151 to +154
ctx.server.environments.client.hot.send({
type: 'full-reload',
path: ctx.file,
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is technically possible to get HMR working for this kind of setup in vite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never tried, but in principle, it's possible by

  • implement module runner hmr (the code is a bit stale but feat: implement fetch transport (POC) vite#18485 implemented transport for this)
  • apply react-refresh transform to react_client environment (which official plugin doesn't support currently, but probably do-able)

FYI, there's no HMR on Vitest, so I expect the lack of HMR would be a blocker for your use case. Do you any concern about this?

Comment on lines +103 to +124
onwarn(warning, defaultHandler) {
if (
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
(warning.message.includes('use client') ||
warning.message.includes('use server'))
) {
return
}
// https://github.com/vitejs/vite/issues/15012
if (
warning.code === 'SOURCEMAP_ERROR' &&
warning.message.includes('resolve original location') &&
warning.pos === 0
) {
return
}
if (userConfig.build?.rollupOptions?.onwarn) {
userConfig.build.rollupOptions.onwarn(warning, defaultHandler)
} else {
defaultHandler(warning)
}
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why this is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is normally setup by @vitejs/plugin-react to automatically silence some build warning (technically a rollup or esbuild bug, so it's just a workaround to reduce noise).

export const silenceUseClientWarning = (

Otherwise you'll met with logs like this:

src/client.tsx (1:0): Error when using sourcemap for reporting an error: Can't resolve original location of error.
src/client.tsx (1:0): Module level directives cause errors when bundled, "use client" in "src/client.tsx" was ignored.
...

Copy link

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank a lot! This looks great, and seems to work!

Comment on lines 9 to 14
{
enforce: 'pre',
...mdx({
format: 'mdx',
}),
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I revert this, then the mdx tests pass for me again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this got in 😅

Comment on lines +103 to +124
onwarn(warning, defaultHandler) {
if (
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
(warning.message.includes('use client') ||
warning.message.includes('use server'))
) {
return
}
// https://github.com/vitejs/vite/issues/15012
if (
warning.code === 'SOURCEMAP_ERROR' &&
warning.message.includes('resolve original location') &&
warning.pos === 0
) {
return
}
if (userConfig.build?.rollupOptions?.onwarn) {
userConfig.build.rollupOptions.onwarn(warning, defaultHandler)
} else {
defaultHandler(warning)
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is normally setup by @vitejs/plugin-react to automatically silence some build warning (technically a rollup or esbuild bug, so it's just a workaround to reduce noise).

export const silenceUseClientWarning = (

Otherwise you'll met with logs like this:

src/client.tsx (1:0): Error when using sourcemap for reporting an error: Can't resolve original location of error.
src/client.tsx (1:0): Module level directives cause errors when bundled, "use client" in "src/client.tsx" was ignored.
...

Comment on lines +151 to +154
ctx.server.environments.client.hot.send({
type: 'full-reload',
path: ctx.file,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never tried, but in principle, it's possible by

  • implement module runner hmr (the code is a bit stale but feat: implement fetch transport (POC) vite#18485 implemented transport for this)
  • apply react-refresh transform to react_client environment (which official plugin doesn't support currently, but probably do-able)

FYI, there's no HMR on Vitest, so I expect the lack of HMR would be a blocker for your use case. Do you any concern about this?

Comment on lines +5 to +7
// Webkit fails by
// > TypeError: ReadableByteStreamController is not implemented
test.skip(({ browserName }) => browserName === 'webkit')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasperpeulen FYI, I'm not sure what to do about this, but probably this means this setup would be broken on all Safari. I tried web-streams-polyfill but it probably broke other things #807.

@hi-ogawa hi-ogawa merged commit b81bf6a into main Sep 2, 2025
20 of 21 checks passed
@hi-ogawa hi-ogawa deleted the 08-29-feat_rsc_support_build_on_browser_mode branch September 2, 2025 00:56
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.

Support browser mode build
2 participants