Skip to content

Commit fcd7c39

Browse files
authored
RSC: Add css files to the example (#8905)
1 parent 2a92ac3 commit fcd7c39

7 files changed

Lines changed: 77 additions & 6 deletions

File tree

packages/cli/src/commands/experimental/setupRscHandler.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,41 @@ export const handler = async ({ force, verbose }) => {
121121
})
122122
},
123123
},
124+
{
125+
title: 'Adding CSS files...',
126+
task: async () => {
127+
const files = [
128+
{
129+
template: 'Counter.css.template',
130+
path: 'Counter.css',
131+
},
132+
{
133+
template: 'Counter.module.css.template',
134+
path: 'Counter.module.css',
135+
},
136+
{
137+
template: 'App.css.template',
138+
path: 'App.css',
139+
},
140+
{
141+
template: 'App.module.css.template',
142+
path: 'App.module.css',
143+
},
144+
]
145+
146+
files.forEach((file) => {
147+
const template = fs.readFileSync(
148+
path.resolve(__dirname, 'templates', 'rsc', file.template),
149+
'utf-8'
150+
)
151+
const filePath = path.join(rwPaths.web.src, file.path)
152+
153+
writeFile(filePath, template, {
154+
overwriteExisting: force,
155+
})
156+
})
157+
},
158+
},
124159
{
125160
title: 'Updating index.html...',
126161
task: async () => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
text-decoration: underline;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.title {
2+
color: green;
3+
}

packages/cli/src/commands/experimental/templates/rsc/App.tsx.template

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
import { Assets } from '@redwoodjs/vite/assets'
2+
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal'
3+
4+
// @ts-expect-error no types
5+
import styles from './App.module.css'
16
import { Counter } from './Counter'
27

8+
import './App.css'
9+
10+
// TODO (RSC) Something like this will probably be needed
11+
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal;
12+
13+
globalThis.rwRscGlobal = new ProdRwRscServerGlobal()
14+
315
const App = ({ name = 'Anonymous' }) => {
416
return (
5-
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}>
6-
<h1>Hello {name}!!</h1>
7-
<h3>This is a server component.</h3>
8-
<Counter />
9-
</div>
17+
<>
18+
{/* TODO (RSC) <Assets /> should be part of the router later */}
19+
<Assets />
20+
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}>
21+
<h1 className={styles.title}>Hello {name}!!</h1>
22+
<h3>This is a server component.</h3>
23+
<Counter />
24+
</div>
25+
</>
1026
)
1127
}
1228

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This should affect all h3 elements on the page, both server components and
3+
* client components. This is just standard CSS stuff
4+
*/
5+
h3 {
6+
color: orange;
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.header {
2+
font-style: italic;
3+
}

packages/cli/src/commands/experimental/templates/rsc/Counter.tsx.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import React from 'react'
44

5+
// @ts-expect-error no types
6+
import styles from './Counter.module.css'
7+
import './Counter.css'
8+
59
export const Counter = () => {
610
const [count, setCount] = React.useState(0)
711

812
return (
913
<div style={{ border: '3px blue dashed', margin: '1em', padding: '1em' }}>
1014
<p>Count: {count}</p>
1115
<button onClick={() => setCount((c) => c + 1)}>Increment</button>
12-
<h3>This is a client component.</h3>
16+
<h3 className={styles.header}>This is a client component.</h3>
1317
</div>
1418
)
1519
}

0 commit comments

Comments
 (0)