-
-
Notifications
You must be signed in to change notification settings - Fork 176
feat(rsc): support browser mode build #801
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
Conversation
commit: |
…browser_mode' into 08-29-feat_rsc_support_build_on_browser_mode
ctx.server.environments.client.hot.send({ | ||
type: 'full-reload', | ||
path: ctx.file, | ||
}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 toreact_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?
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) | ||
} | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
...
There was a problem hiding this 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!
playground/mdx/vite.config.ts
Outdated
{ | ||
enforce: 'pre', | ||
...mdx({ | ||
format: 'mdx', | ||
}), | ||
}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😅
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) | ||
} | ||
}, |
There was a problem hiding this comment.
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.
...
ctx.server.environments.client.hot.send({ | ||
type: 'full-reload', | ||
path: ctx.file, | ||
}) |
There was a problem hiding this comment.
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 toreact_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?
// Webkit fails by | ||
// > TypeError: ReadableByteStreamController is not implemented | ||
test.skip(({ browserName }) => browserName === 'webkit') |
There was a problem hiding this comment.
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.
Description
Summary
RscPluginManager
as plugin api, which can be used to implement simplified version of build pipeline on user land."rsc"
invitePluginDefineEncryptionKey
examples/browser-mode
TODO