Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

CssModulesContent.tsx

65 lines2.3 KB

1/// <reference types="vite/client" />
2/// <reference types="@vitejs/plugin-rsc/types" />
3import styles from './serverComponent.module.css'
4import { NestedAccentContent } from './NestedAccentContent'
5​
6// ============================================================================
7// CSS MODULES: Feature Card with CSS Modules
8// This is a pure server component file (no createServerFn) so vite-plugin-rsc's
9// CSS transform can properly wrap the exported component
10// ============================================================================
11​
12export function CssModulesContent({ data }: { data: { title?: string } }) {
13 const serverTimestamp = Date.now()
14​
15 const features = [
16 { id: 1, icon: 'βœ“', text: 'Scoped class names prevent conflicts' },
17 { id: 2, icon: 'βœ“', text: 'Works seamlessly in server components' },
18 { id: 3, icon: 'βœ“', text: 'CSS is extracted and optimized' },
19 { id: 4, icon: 'βœ“', text: 'Full IDE support with TypeScript' },
20 ]
21​
22 return (
23 <div className={styles.container} data-testid="rsc-css-modules-content">
24 <div className={styles.header}>
25 <span className={styles.badge} data-testid="rsc-css-modules-badge">
26 SERVER RENDERED
27 </span>
28 <span
29 className={styles.timestamp}
30 data-testid="rsc-css-modules-timestamp"
31 >
32 Fetched: {new Date(serverTimestamp).toLocaleTimeString()}
33 </span>
34 </div>
35​
36 <h2 className={styles.title} data-testid="rsc-css-modules-title">
37 {data.title || 'CSS Modules in RSC'}
38 </h2>
39​
40 <p className={styles.description}>
41 This server component uses CSS Modules for styling. The class names are
42 automatically scoped to prevent conflicts with other styles.
43 </p>
44​
45 <ul className={styles.featureList} data-testid="rsc-css-modules-features">
46 {features.map((feature) => (
47 <li
48 key={feature.id}
49 className={styles.featureItem}
50 data-testid={`rsc-css-modules-feature-${feature.id}`}
51 >
52 <span className={styles.featureIcon}>{feature.icon}</span>
53 <span>{feature.text}</span>
54 </li>
55 ))}
56 </ul>
57​
58 <div className={styles.footer}>
59 Component ID: css-mod-{Math.random().toString(36).slice(2, 8)}
60 </div>
61​
62 <NestedAccentContent />
63 </div>
64 )