|
1 | | -import { Link, createFileRoute } from '@tanstack/react-router' |
| 1 | +import { createFileRoute, Link, linkOptions } from '@tanstack/react-router' |
| 2 | +import type { CSSProperties } from 'react' |
2 | 3 |
|
3 | 4 | export const Route = createFileRoute('/')({ |
4 | 5 | component: Home, |
5 | 6 | }) |
6 | 7 |
|
| 8 | +const examples = linkOptions([ |
| 9 | + { |
| 10 | + to: '/rsc-node-module-client', |
| 11 | + title: 'Node module client component', |
| 12 | + description: |
| 13 | + 'Hydrates a client component imported from node_modules inside an RSC route.', |
| 14 | + marker: 'RSC', |
| 15 | + markerColor: '#0284c7', |
| 16 | + }, |
| 17 | + { |
| 18 | + to: '/rsc-css-url', |
| 19 | + title: 'css?url stylesheet', |
| 20 | + description: |
| 21 | + 'Applies a stylesheet imported with the ?url query from route head metadata.', |
| 22 | + marker: 'CSS', |
| 23 | + markerColor: '#16a34a', |
| 24 | + }, |
| 25 | +]) |
| 26 | + |
| 27 | +const colors = { |
| 28 | + server: '#0284c7', |
| 29 | + client: '#16a34a', |
| 30 | + async: '#f59e0b', |
| 31 | +} |
| 32 | + |
| 33 | +const styles = { |
| 34 | + page: { |
| 35 | + maxWidth: '800px', |
| 36 | + padding: '20px', |
| 37 | + fontFamily: |
| 38 | + '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', |
| 39 | + }, |
| 40 | + title: { |
| 41 | + margin: '0 0 8px 0', |
| 42 | + color: '#1e293b', |
| 43 | + fontSize: '24px', |
| 44 | + }, |
| 45 | + description: { |
| 46 | + color: '#64748b', |
| 47 | + lineHeight: '1.5', |
| 48 | + marginBottom: '20px', |
| 49 | + }, |
| 50 | + legend: { |
| 51 | + display: 'flex', |
| 52 | + gap: '16px', |
| 53 | + marginBottom: '20px', |
| 54 | + padding: '12px', |
| 55 | + backgroundColor: '#f8fafc', |
| 56 | + borderRadius: '8px', |
| 57 | + flexWrap: 'wrap', |
| 58 | + }, |
| 59 | + legendItem: { |
| 60 | + display: 'flex', |
| 61 | + alignItems: 'center', |
| 62 | + gap: '6px', |
| 63 | + }, |
| 64 | + legendText: { |
| 65 | + color: '#475569', |
| 66 | + fontSize: '13px', |
| 67 | + }, |
| 68 | + legendColor: { |
| 69 | + width: '16px', |
| 70 | + height: '16px', |
| 71 | + borderRadius: '4px', |
| 72 | + }, |
| 73 | + grid: { |
| 74 | + display: 'grid', |
| 75 | + gap: '16px', |
| 76 | + gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))', |
| 77 | + }, |
| 78 | + card: { |
| 79 | + display: 'block', |
| 80 | + padding: '16px', |
| 81 | + backgroundColor: '#f8fafc', |
| 82 | + borderRadius: '8px', |
| 83 | + border: '1px solid #e2e8f0', |
| 84 | + textDecoration: 'none', |
| 85 | + }, |
| 86 | + marker: { |
| 87 | + display: 'grid', |
| 88 | + placeItems: 'center', |
| 89 | + width: '40px', |
| 90 | + height: '32px', |
| 91 | + marginBottom: '8px', |
| 92 | + borderRadius: '6px', |
| 93 | + color: 'white', |
| 94 | + fontSize: '13px', |
| 95 | + fontWeight: 'bold', |
| 96 | + }, |
| 97 | + cardTitle: { |
| 98 | + marginBottom: '4px', |
| 99 | + color: '#0f172a', |
| 100 | + fontWeight: 'bold', |
| 101 | + }, |
| 102 | + cardDescription: { |
| 103 | + color: '#64748b', |
| 104 | + fontSize: '13px', |
| 105 | + lineHeight: '1.4', |
| 106 | + }, |
| 107 | +} satisfies Record<string, CSSProperties> |
| 108 | + |
| 109 | +function legendColor(color: string): CSSProperties { |
| 110 | + return { |
| 111 | + ...styles.legendColor, |
| 112 | + backgroundColor: color, |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +function markerStyle(color: string): CSSProperties { |
| 117 | + return { |
| 118 | + ...styles.marker, |
| 119 | + backgroundColor: color, |
| 120 | + } |
| 121 | +} |
| 122 | + |
7 | 123 | function Home() { |
8 | 124 | return ( |
9 | | - <main> |
10 | | - <h1>Rsbuild RSC fixture</h1> |
11 | | - <Link to="/rsc-node-module-client">Node module client component</Link> |
| 125 | + <main style={styles.page} data-testid="index-page"> |
| 126 | + <h1 data-testid="home-title" style={styles.title}> |
| 127 | + React Server Components Rsbuild E2E Tests |
| 128 | + </h1> |
| 129 | + <p style={styles.description}> |
| 130 | + These examples cover Rsbuild-specific RSC behavior with clear visual |
| 131 | + distinction between server-rendered content and client-side assets. |
| 132 | + </p> |
| 133 | + |
| 134 | + <div style={styles.legend}> |
| 135 | + <div style={styles.legendItem}> |
| 136 | + <span style={legendColor(colors.server)} /> |
| 137 | + <span style={styles.legendText}>Server Rendered (RSC)</span> |
| 138 | + </div> |
| 139 | + <div style={styles.legendItem}> |
| 140 | + <span style={legendColor(colors.client)} /> |
| 141 | + <span style={styles.legendText}>Client Hydration and Assets</span> |
| 142 | + </div> |
| 143 | + <div style={styles.legendItem}> |
| 144 | + <span style={legendColor(colors.async)} /> |
| 145 | + <span style={styles.legendText}>Rsbuild SSR Coverage</span> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + |
| 149 | + <nav style={styles.grid}> |
| 150 | + {examples.map(({ marker, markerColor, title, description, ...link }) => ( |
| 151 | + <Link key={link.to} {...link} style={styles.card}> |
| 152 | + <div style={markerStyle(markerColor)}>{marker}</div> |
| 153 | + <div style={styles.cardTitle}>{title}</div> |
| 154 | + <div style={styles.cardDescription}>{description}</div> |
| 155 | + </Link> |
| 156 | + ))} |
| 157 | + </nav> |
12 | 158 | </main> |
13 | 159 | ) |
14 | 160 | } |
0 commit comments