Skip to content

Commit

Permalink
chore(rsc): Remove RSC-specific logic from our babel config (#11528)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Sep 11, 2024
1 parent b508121 commit 199218c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
11 changes: 3 additions & 8 deletions packages/babel-config/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
export interface Flags {
forJest?: boolean // will change the alias for module-resolver plugin
forPrerender?: boolean // changes what babel-plugin-redwood-routes-auto-loader does
forRsc?: boolean
forJavaScriptLinting?: boolean // will enable presets to supporting linting in the absence of typescript related presets/plugins/parsers
}

Expand Down Expand Up @@ -117,10 +116,7 @@ export const getWebSideBabelPlugins = (
}

export const getWebSideOverrides = (
{ forPrerender, forRsc }: Flags = {
forPrerender: false,
forRsc: false,
},
{ forPrerender }: Flags = { forPrerender: false },
): TransformOptions[] => {
// Have to use a readonly array here because of a limitation in TS
// See https://stackoverflow.com/a/70763406/88106
Expand All @@ -131,9 +127,7 @@ export const getWebSideOverrides = (
},
// Automatically import files in `./web/src/pages/*` in to
// the `./web/src/Routes.[ts|jsx]` file.
// We do not do this for RSC because there are differences between server and client
// so each specific build stage handles the auto-importing of routes
!forRsc && {
{
test: /Routes.(js|tsx|jsx)$/,
plugins: [
[
Expand All @@ -143,6 +137,7 @@ export const getWebSideOverrides = (
{
forPrerender,
} satisfies RoutesAutoLoaderOptions,
'babel-plugin-redwood-routes-auto-loader',
],
],
},
Expand Down
24 changes: 19 additions & 5 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ export default function redwoodPluginVite(): PluginOption[] {
const streamingEnabled = rwConfig.experimental.streamingSsr.enabled
const rscEnabled = rwConfig.experimental?.rsc?.enabled

const webSideDefaultBabelConfig = getWebSideDefaultBabelConfig()

const babelConfig = {
...webSideDefaultBabelConfig,
// For RSC we don't want to include the routes auto-loader plugin as we
// handle that differently in each specific RSC build stage
overrides: rscEnabled
? webSideDefaultBabelConfig.overrides.filter((override) => {
return !override.plugins?.some((plugin) => {
return (
Array.isArray(plugin) &&
plugin[2] === 'babel-plugin-redwood-routes-auto-loader'
)
})
})
: webSideDefaultBabelConfig.overrides,
}

return [
{
name: 'redwood-plugin-vite-html-env',
Expand Down Expand Up @@ -153,11 +171,7 @@ export default function redwoodPluginVite(): PluginOption[] {
},
]),
react({
babel: {
...getWebSideDefaultBabelConfig({
forRsc: rscEnabled,
}),
},
babel: babelConfig,
}),
// Only include the Buffer polyfill for non-rsc dev, for DevFatalErrorPage
// Including the polyfill plugin in any form in RSC breaks
Expand Down

0 comments on commit 199218c

Please sign in to comment.