Related plugins
Description
Currently rsc plugin copies all assets from rsc environment to client environment by default.
|
for (const asset of Object.values(manager.bundles['rsc']!)) { |
|
if (asset.fileName === rscViteManifest) continue |
|
if (asset.type === 'asset' && filterAssets(asset.fileName)) { |
|
this.emitFile({ |
|
type: 'asset', |
|
fileName: asset.fileName, |
|
source: asset.source, |
|
}) |
|
} |
|
} |
This is mainly for copying css assets on server that are handled internally by rsc plugin but also end-user's ?url import inside rsc environment.
However this is not a safe heuristics since rsc environment is the server logic which should get exposed as public assets. As one such example, rscViteManifest is avoided to get copied above.
For this concern, rsc plugin provides copyServerAssetsToClient option to control which gets copied, but this option isn't composable and more like targetted as end-user's tweak to filter out something.
|
/** |
|
* This option allows customizing how client build copies assets from server build. |
|
* By default, all assets are copied, but frameworks can establish server asset convention |
|
* to tighten security using this option. |
|
*/ |
|
copyServerAssetsToClient?: (fileName: string) => boolean |
Suggested solution
Explore whether we can improve default heuristics to only detect assets which are clearly intended as public assets i.e. side effect css import and ?url import in rsc environment.
If user plugins employs emitFile({ type: "asset" }) in rsc environment, they shouldn't get copied to public assets in client environment by default, but that should be opt-in behavior. For example, Astro seems to have introduced emitClientAsset withastro/astro#15345 for such behavior possible.
Alternative
No response
Additional context
No response
Validations
Related plugins
plugin-react
plugin-react-swc
plugin-react-oxc
plugin-rsc
Description
Currently rsc plugin copies all assets from
rscenvironment toclientenvironment by default.vite-plugin-react/packages/plugin-rsc/src/plugin.ts
Lines 1078 to 1087 in f066114
This is mainly for copying css assets on server that are handled internally by rsc plugin but also end-user's
?urlimport insiderscenvironment.However this is not a safe heuristics since
rscenvironment is the server logic which should get exposed as public assets. As one such example,rscViteManifestis avoided to get copied above.For this concern, rsc plugin provides
copyServerAssetsToClientoption to control which gets copied, but this option isn't composable and more like targetted as end-user's tweak to filter out something.vite-plugin-react/packages/plugin-rsc/src/plugin.ts
Lines 190 to 195 in f066114
Suggested solution
Explore whether we can improve default heuristics to only detect assets which are clearly intended as public assets i.e. side effect css import and
?urlimport in rsc environment.If user plugins employs
emitFile({ type: "asset" })in rsc environment, they shouldn't get copied to public assets in client environment by default, but that should be opt-in behavior. For example, Astro seems to have introducedemitClientAssetwithastro/astro#15345 for such behavior possible.Alternative
No response
Additional context
No response
Validations