diff --git a/packages/cli/src/commands/experimental/setupRscHandler.js b/packages/cli/src/commands/experimental/setupRscHandler.js index b65b78b8d860..7f843b391c2d 100644 --- a/packages/cli/src/commands/experimental/setupRscHandler.js +++ b/packages/cli/src/commands/experimental/setupRscHandler.js @@ -121,6 +121,41 @@ export const handler = async ({ force, verbose }) => { }) }, }, + { + title: 'Adding CSS files...', + task: async () => { + const files = [ + { + template: 'Counter.css.template', + path: 'Counter.css', + }, + { + template: 'Counter.module.css.template', + path: 'Counter.module.css', + }, + { + template: 'App.css.template', + path: 'App.css', + }, + { + template: 'App.module.css.template', + path: 'App.module.css', + }, + ] + + files.forEach((file) => { + const template = fs.readFileSync( + path.resolve(__dirname, 'templates', 'rsc', file.template), + 'utf-8' + ) + const filePath = path.join(rwPaths.web.src, file.path) + + writeFile(filePath, template, { + overwriteExisting: force, + }) + }) + }, + }, { title: 'Updating index.html...', task: async () => { diff --git a/packages/cli/src/commands/experimental/templates/rsc/App.css.template b/packages/cli/src/commands/experimental/templates/rsc/App.css.template new file mode 100644 index 000000000000..b2d3dc07c3d1 --- /dev/null +++ b/packages/cli/src/commands/experimental/templates/rsc/App.css.template @@ -0,0 +1,3 @@ +h1 { + text-decoration: underline; +} diff --git a/packages/cli/src/commands/experimental/templates/rsc/App.module.css.template b/packages/cli/src/commands/experimental/templates/rsc/App.module.css.template new file mode 100644 index 000000000000..29212ea8142d --- /dev/null +++ b/packages/cli/src/commands/experimental/templates/rsc/App.module.css.template @@ -0,0 +1,3 @@ +.title { + color: green; +} 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 f060d7838319..eeef58d34680 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template +++ b/packages/cli/src/commands/experimental/templates/rsc/App.tsx.template @@ -1,12 +1,28 @@ +import { Assets } from '@redwoodjs/vite/assets' +import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' + +// @ts-expect-error no types +import styles from './App.module.css' import { Counter } from './Counter' +import './App.css' + +// TODO (RSC) Something like this will probably be needed +// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; + +globalThis.rwRscGlobal = new ProdRwRscServerGlobal() + const App = ({ name = 'Anonymous' }) => { return ( -
-

Hello {name}!!

-

This is a server component.

- -
+ <> + {/* TODO (RSC) should be part of the router later */} + +
+

Hello {name}!!

+

This is a server component.

+ +
+ ) } diff --git a/packages/cli/src/commands/experimental/templates/rsc/Counter.css.template b/packages/cli/src/commands/experimental/templates/rsc/Counter.css.template new file mode 100644 index 000000000000..4cbd74d7d5b6 --- /dev/null +++ b/packages/cli/src/commands/experimental/templates/rsc/Counter.css.template @@ -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/packages/cli/src/commands/experimental/templates/rsc/Counter.module.css.template b/packages/cli/src/commands/experimental/templates/rsc/Counter.module.css.template new file mode 100644 index 000000000000..736b0da8688c --- /dev/null +++ b/packages/cli/src/commands/experimental/templates/rsc/Counter.module.css.template @@ -0,0 +1,3 @@ +.header { + font-style: italic; +} diff --git a/packages/cli/src/commands/experimental/templates/rsc/Counter.tsx.template b/packages/cli/src/commands/experimental/templates/rsc/Counter.tsx.template index af7d4db69f8a..a6e38c4059b5 100644 --- a/packages/cli/src/commands/experimental/templates/rsc/Counter.tsx.template +++ b/packages/cli/src/commands/experimental/templates/rsc/Counter.tsx.template @@ -2,6 +2,10 @@ import React from 'react' +// @ts-expect-error no types +import styles from './Counter.module.css' +import './Counter.css' + export const Counter = () => { const [count, setCount] = React.useState(0) @@ -9,7 +13,7 @@ export const Counter = () => {

Count: {count}

-

This is a client component.

+

This is a client component.

) }