diff --git a/__fixtures__/test-project-rsa/web/src/App.tsx b/__fixtures__/test-project-rsa/web/src/App.tsx index c27bb9fa9863..27cb83121ff7 100644 --- a/__fixtures__/test-project-rsa/web/src/App.tsx +++ b/__fixtures__/test-project-rsa/web/src/App.tsx @@ -1,11 +1,18 @@ -import { FatalErrorBoundary } from '@redwoodjs/web' +import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' +import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' import Routes from './Routes' +import './index.css' + const App = () => ( - + + + + + ) diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/AboutCounter.tsx b/__fixtures__/test-project-rsa/web/src/components/Counter/AboutCounter.tsx similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/AboutCounter.tsx rename to __fixtures__/test-project-rsa/web/src/components/Counter/AboutCounter.tsx diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/Counter.css b/__fixtures__/test-project-rsa/web/src/components/Counter/Counter.css similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/Counter.css rename to __fixtures__/test-project-rsa/web/src/components/Counter/Counter.css diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/Counter.module.css b/__fixtures__/test-project-rsa/web/src/components/Counter/Counter.module.css similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/Counter.module.css rename to __fixtures__/test-project-rsa/web/src/components/Counter/Counter.module.css diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/Counter.tsx b/__fixtures__/test-project-rsa/web/src/components/Counter/Counter.tsx similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/Counter.tsx rename to __fixtures__/test-project-rsa/web/src/components/Counter/Counter.tsx diff --git a/__fixtures__/test-project-rsa/web/src/entries.ts b/__fixtures__/test-project-rsa/web/src/entries.ts index c5b1f644a370..6259057e245b 100644 --- a/__fixtures__/test-project-rsa/web/src/entries.ts +++ b/__fixtures__/test-project-rsa/web/src/entries.ts @@ -5,9 +5,9 @@ export default defineEntries( async (id) => { switch (id) { case 'AboutPage': - return import('./AboutPage') + return import('./pages/AboutPage/AboutPage') case 'HomePage': - return import('./HomePage') + return import('./pages/HomePage/HomePage') default: return null } diff --git a/__fixtures__/test-project-rsa/web/src/index.html b/__fixtures__/test-project-rsa/web/src/index.html index 9516be5e9597..6b3b066be037 100644 --- a/__fixtures__/test-project-rsa/web/src/index.html +++ b/__fixtures__/test-project-rsa/web/src/index.html @@ -5,7 +5,6 @@ - diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/AboutPage.css b/__fixtures__/test-project-rsa/web/src/pages/AboutPage/AboutPage.css similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/AboutPage.css rename to __fixtures__/test-project-rsa/web/src/pages/AboutPage/AboutPage.css diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/AboutPage.tsx b/__fixtures__/test-project-rsa/web/src/pages/AboutPage/AboutPage.tsx similarity index 91% rename from __fixtures__/test-project-rsc-external-packages/web/src/AboutPage.tsx rename to __fixtures__/test-project-rsa/web/src/pages/AboutPage/AboutPage.tsx index 0caf6a955090..2706e12e63db 100644 --- a/__fixtures__/test-project-rsc-external-packages/web/src/AboutPage.tsx +++ b/__fixtures__/test-project-rsa/web/src/pages/AboutPage/AboutPage.tsx @@ -1,7 +1,7 @@ import { Assets } from '@redwoodjs/vite/assets' import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' -import { AboutCounter } from './AboutCounter' +import { AboutCounter } from '../../components/Counter/AboutCounter' import './AboutPage.css' diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/HomePage.css b/__fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.css similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/HomePage.css rename to __fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.css diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/HomePage.module.css b/__fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.module.css similarity index 100% rename from __fixtures__/test-project-rsc-external-packages/web/src/HomePage.module.css rename to __fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.module.css diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/HomePage.tsx b/__fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.tsx similarity index 94% rename from __fixtures__/test-project-rsc-external-packages/web/src/HomePage.tsx rename to __fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.tsx index c41c85f371c5..383eca179ef4 100644 --- a/__fixtures__/test-project-rsc-external-packages/web/src/HomePage.tsx +++ b/__fixtures__/test-project-rsa/web/src/pages/HomePage/HomePage.tsx @@ -3,8 +3,8 @@ import { RscForm } from '@tobbe.dev/rsc-test' import { Assets } from '@redwoodjs/vite/assets' import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' +import { Counter } from '../../components/Counter/Counter' import { onSend } from './actions' -import { Counter } from './Counter' // @ts-expect-error no types import styles from './HomePage.module.css' diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/App.tsx b/__fixtures__/test-project-rsc-external-packages/web/src/App.tsx index c27bb9fa9863..27cb83121ff7 100644 --- a/__fixtures__/test-project-rsc-external-packages/web/src/App.tsx +++ b/__fixtures__/test-project-rsc-external-packages/web/src/App.tsx @@ -1,11 +1,18 @@ -import { FatalErrorBoundary } from '@redwoodjs/web' +import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' +import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' import Routes from './Routes' +import './index.css' + const App = () => ( - + + + + + ) diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/AboutCounter.tsx b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/AboutCounter.tsx new file mode 100644 index 000000000000..c86915e87f8b --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/AboutCounter.tsx @@ -0,0 +1,20 @@ +'use client' + +import React from 'react' + +// @ts-expect-error no types +import styles from './Counter.module.css' +import './Counter.css' + +export const AboutCounter = () => { + const [count, setCount] = React.useState(0) + + return ( +
+

Count: {count}

+ +

This is a client component.

+

RSC on client: {globalThis.RWJS_EXP_RSC ? 'enabled' : 'disabled'}

+
+ ) +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.css b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.css new file mode 100644 index 000000000000..4cbd74d7d5b6 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.css @@ -0,0 +1,7 @@ +/** + * This should affect all h3 elements on the page, both server components and + * client components. This is just standard CSS stuff + */ +h3 { + color: orange; +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.module.css b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.module.css new file mode 100644 index 000000000000..736b0da8688c --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.module.css @@ -0,0 +1,3 @@ +.header { + font-style: italic; +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.tsx b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.tsx new file mode 100644 index 000000000000..5f21e7cdac2d --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/components/Counter/Counter.tsx @@ -0,0 +1,21 @@ +'use client' + +import React from 'react' + +import 'client-only' + +// @ts-expect-error no types +import styles from './Counter.module.css' +import './Counter.css' + +export const Counter = () => { + const [count, setCount] = React.useState(0) + + return ( +
+

Count: {count}

+ +

This is a client component.

+
+ ) +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/entries.ts b/__fixtures__/test-project-rsc-external-packages/web/src/entries.ts index c5b1f644a370..6259057e245b 100644 --- a/__fixtures__/test-project-rsc-external-packages/web/src/entries.ts +++ b/__fixtures__/test-project-rsc-external-packages/web/src/entries.ts @@ -5,9 +5,9 @@ export default defineEntries( async (id) => { switch (id) { case 'AboutPage': - return import('./AboutPage') + return import('./pages/AboutPage/AboutPage') case 'HomePage': - return import('./HomePage') + return import('./pages/HomePage/HomePage') default: return null } diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/index.html b/__fixtures__/test-project-rsc-external-packages/web/src/index.html index 9516be5e9597..6b3b066be037 100644 --- a/__fixtures__/test-project-rsc-external-packages/web/src/index.html +++ b/__fixtures__/test-project-rsc-external-packages/web/src/index.html @@ -5,7 +5,6 @@ - diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.css b/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.css new file mode 100644 index 000000000000..995b3bbde1e0 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.css @@ -0,0 +1,2 @@ +.about-page { +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.tsx b/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.tsx new file mode 100644 index 000000000000..2706e12e63db --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/pages/AboutPage/AboutPage.tsx @@ -0,0 +1,27 @@ +import { Assets } from '@redwoodjs/vite/assets' +import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' + +import { AboutCounter } from '../../components/Counter/AboutCounter' + +import './AboutPage.css' + +// TODO (RSC) Something like this will probably be needed +// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; + +globalThis.rwRscGlobal = new ProdRwRscServerGlobal() + +const AboutPage = () => { + return ( +
+ {/* TODO (RSC) should be part of the router later */} + +
+

About Redwood

+ +

RSC on server: {globalThis.RWJS_EXP_RSC ? 'enabled' : 'disabled'}

+
+
+ ) +} + +export default AboutPage diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.css b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.css new file mode 100644 index 000000000000..9be6b50cd8f7 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.css @@ -0,0 +1,2 @@ +.home-page { +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.module.css b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.module.css new file mode 100644 index 000000000000..29212ea8142d --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.module.css @@ -0,0 +1,3 @@ +.title { + color: green; +} diff --git a/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.tsx b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.tsx new file mode 100644 index 000000000000..383eca179ef4 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages/web/src/pages/HomePage/HomePage.tsx @@ -0,0 +1,32 @@ +import { RscForm } from '@tobbe.dev/rsc-test' + +import { Assets } from '@redwoodjs/vite/assets' +import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' + +import { Counter } from '../../components/Counter/Counter' +import { onSend } from './actions' +// @ts-expect-error no types +import styles from './HomePage.module.css' + +import './HomePage.css' + +// TODO (RSC) Something like this will probably be needed +// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; + +globalThis.rwRscGlobal = new ProdRwRscServerGlobal() + +const HomePage = ({ name = 'Anonymous' }) => { + return ( +
+ {/* TODO (RSC) should be part of the router later */} + +
+

Hello {name}!!

+ + +
+
+ ) +} + +export default HomePage diff --git a/packages/babel-config/src/plugins/babel-plugin-redwood-routes-auto-loader.ts b/packages/babel-config/src/plugins/babel-plugin-redwood-routes-auto-loader.ts index 7457db2babcc..4b2d0405afab 100644 --- a/packages/babel-config/src/plugins/babel-plugin-redwood-routes-auto-loader.ts +++ b/packages/babel-config/src/plugins/babel-plugin-redwood-routes-auto-loader.ts @@ -8,6 +8,7 @@ import { processPagesDir, getPaths, ensurePosixPath, + getConfig, } from '@redwoodjs/project-config' interface PluginOptions { @@ -63,6 +64,14 @@ export default function ( ) } + if (getConfig().experimental?.rsc?.enabled) { + // TODO (RSC): Enable auto-loader for RSC + return { + name: 'babel-plugin-redwood-routes-auto-loader', + visitor: {}, + } + } + return { name: 'babel-plugin-redwood-routes-auto-loader', visitor: { diff --git a/packages/cli/src/commands/experimental/setupRscHandler.js b/packages/cli/src/commands/experimental/setupRscHandler.js index 2dac190ec12e..01f210a222ad 100644 --- a/packages/cli/src/commands/experimental/setupRscHandler.js +++ b/packages/cli/src/commands/experimental/setupRscHandler.js @@ -102,7 +102,11 @@ export const handler = async ({ force, verbose }) => { ), 'utf-8' ) - const homePagePath = path.join(rwPaths.web.src, 'HomePage.tsx') + const homePagePath = path.join( + rwPaths.web.pages, + 'HomePage', + 'HomePage.tsx' + ) writeFile(homePagePath, homePageTemplate, { overwriteExisting: force, @@ -117,7 +121,11 @@ export const handler = async ({ force, verbose }) => { ), 'utf-8' ) - const aboutPagePath = path.join(rwPaths.web.src, 'AboutPage.tsx') + const aboutPagePath = path.join( + rwPaths.web.pages, + 'AboutPage', + 'AboutPage.tsx' + ) writeFile(aboutPagePath, aboutPageTemplate, { overwriteExisting: force, @@ -131,7 +139,11 @@ export const handler = async ({ force, verbose }) => { path.resolve(__dirname, 'templates', 'rsc', 'Counter.tsx.template'), 'utf-8' ) - const counterPath = path.join(rwPaths.web.src, 'Counter.tsx') + const counterPath = path.join( + rwPaths.web.components, + 'Counter', + 'Counter.tsx' + ) writeFile(counterPath, counterTemplate, { overwriteExisting: force, @@ -150,7 +162,11 @@ export const handler = async ({ force, verbose }) => { ), 'utf-8' ) - const counterPath = path.join(rwPaths.web.src, 'AboutCounter.tsx') + const counterPath = path.join( + rwPaths.web.components, + 'Counter', + 'AboutCounter.tsx' + ) writeFile(counterPath, counterTemplate, { overwriteExisting: force, @@ -163,23 +179,23 @@ export const handler = async ({ force, verbose }) => { const files = [ { template: 'Counter.css.template', - path: 'Counter.css', + path: ['components', 'Counter', 'Counter.css'], }, { template: 'Counter.module.css.template', - path: 'Counter.module.css', + path: ['components', 'Counter', 'Counter.module.css'], }, { template: 'HomePage.css.template', - path: 'HomePage.css', + path: ['pages', 'HomePage', 'HomePage.css'], }, { template: 'HomePage.module.css.template', - path: 'HomePage.module.css', + path: ['pages', 'HomePage', 'HomePage.module.css'], }, { template: 'AboutPage.css.template', - path: 'AboutPage.css', + path: ['pages', 'AboutPage', 'AboutPage.css'], }, ] @@ -188,7 +204,7 @@ export const handler = async ({ force, verbose }) => { path.resolve(__dirname, 'templates', 'rsc', file.template), 'utf-8' ) - const filePath = path.join(rwPaths.web.src, file.path) + const filePath = path.join(rwPaths.web.src, ...file.path) writeFile(filePath, template, { overwriteExisting: force, diff --git a/packages/cli/src/commands/experimental/templates/rsc/AboutPage.tsx.template b/packages/cli/src/commands/experimental/templates/rsc/AboutPage.tsx.template index 0caf6a955090..2706e12e63db 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/AboutPage.tsx.template +++ b/packages/cli/src/commands/experimental/templates/rsc/AboutPage.tsx.template @@ -1,7 +1,7 @@ import { Assets } from '@redwoodjs/vite/assets' import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' -import { AboutCounter } from './AboutCounter' +import { AboutCounter } from '../../components/Counter/AboutCounter' import './AboutPage.css' diff --git a/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template b/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template index d95fc48fe27d..27cb83121ff7 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template +++ b/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template @@ -1,4 +1,5 @@ import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' +import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' import Routes from './Routes' @@ -8,7 +9,9 @@ import './index.css' const App = () => ( - + + + ) diff --git a/packages/cli/src/commands/experimental/templates/rsc/HomePage.tsx.template b/packages/cli/src/commands/experimental/templates/rsc/HomePage.tsx.template index 9a41caf53190..ad75dbcfa24e 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/HomePage.tsx.template +++ b/packages/cli/src/commands/experimental/templates/rsc/HomePage.tsx.template @@ -1,7 +1,7 @@ import { Assets } from '@redwoodjs/vite/assets' import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' -import { Counter } from './Counter' +import { Counter } from '../../components/Counter/Counter' // @ts-expect-error no types import styles from './HomePage.module.css' diff --git a/packages/cli/src/commands/experimental/templates/rsc/entries.ts.template b/packages/cli/src/commands/experimental/templates/rsc/entries.ts.template index c5b1f644a370..6259057e245b 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/entries.ts.template +++ b/packages/cli/src/commands/experimental/templates/rsc/entries.ts.template @@ -5,9 +5,9 @@ export default defineEntries( async (id) => { switch (id) { case 'AboutPage': - return import('./AboutPage') + return import('./pages/AboutPage/AboutPage') case 'HomePage': - return import('./HomePage') + return import('./pages/HomePage/HomePage') default: return null }