Open History to see the last commit
1import { createServerFn } from '@tanstack/react-start'
2import { renderServerComponent } from '@tanstack/react-start/rsc'
3import { serverBox, serverBadge, serverHeader, timestamp } from './serverStyles'
4β
5// ============================================================================
6// BASIC: User Profile Card
7// Used by: rsc-basic.tsx, rsc-hydration.tsx
8// ============================================================================
9β
10export const getBasicServerComponent = createServerFn({ method: 'GET' })
11 .validator((data: { label?: string }) => data)
12 .handler(async ({ data }) => {
13 const serverTimestamp = Date.now()
14β
15 // Simulate fetching user from database
16 const user = {
17 id: 'usr_' + Math.random().toString(36).slice(2, 8),
18 name: 'Sarah Chen',
19 role: 'Senior Software Engineer',
20 department: 'Platform Team',
21 email: 'sarah.chen@example.com',
22 joinDate: 'March 2021',
23 projects: 12,
24 contributions: 847,
25 }
26β
27 return renderServerComponent(
28 <div style={serverBox} data-testid="rsc-basic-content">
29 <div style={serverHeader}>
30 <span style={serverBadge} data-testid="rsc-server-badge">
31 SERVER RENDERED
32 </span>
33 <span style={timestamp} data-testid="rsc-server-timestamp">
34 Fetched: {new Date(serverTimestamp).toLocaleTimeString()}
35 </span>
36 </div>
37β
38 {/* Profile Header */}
39 <div style={{ display: 'flex', gap: '16px', marginBottom: '16px' }}>
40 <div
41 style={{
42 width: '64px',
43 height: '64px',
44 borderRadius: '50%',
45 backgroundColor: '#0284c7',
46 display: 'flex',
47 alignItems: 'center',
48 justifyContent: 'center',
49 color: 'white',
50 fontSize: '24px',
51 fontWeight: 'bold',
52 }}
53 >
54 SC
55 </div>
56 <div>
57 <h2
58 style={{ margin: '0 0 4px 0', color: '#0c4a6e' }}
59 data-testid="rsc-label"
60 >
61 {user.name}
62 </h2>
63 <div style={{ color: '#0369a1' }}>{user.role}</div>
64 <div style={{ color: '#64748b', fontSize: '14px' }}>
65 {user.department}
66 </div>
67 </div>
68 </div>
69β
70 {/* Stats */}
71 <div
72 style={{
73 display: 'grid',
74 gridTemplateColumns: 'repeat(3, 1fr)',
75 gap: '12px',
76 padding: '12px',
77 backgroundColor: '#f0f9ff',
78 borderRadius: '6px',
79 textAlign: 'center',
80 }}
81 >
82 <div>
83 <div
84 style={{
85 fontSize: '24px',
86 fontWeight: 'bold',
87 color: '#0284c7',
88 }}
89 >
90 {user.projects}
91 </div>
92 <div style={{ fontSize: '12px', color: '#64748b' }}>Projects</div>
93 </div>
94 <div>
95 <div
96 style={{
97 fontSize: '24px',
98 fontWeight: 'bold',
99 color: '#0284c7',
100 }}
101 >
102 {user.contributions}
103 </div>
104 <div style={{ fontSize: '12px', color: '#64748b' }}>
105 Contributions
106 </div>
107 </div>
108 <div>
109 <div
110 style={{
111 fontSize: '24px',
112 fontWeight: 'bold',
113 color: '#0284c7',
114 }}
115 >
116 {user.joinDate.split(' ')[1]}
117 </div>
118 <div style={{ fontSize: '12px', color: '#64748b' }}>Since</div>
119 </div>
120 </div>
121β
122 <div style={{ marginTop: '12px', fontSize: '13px', color: '#64748b' }}>
123 User ID: {user.id}
124 </div>
125 </div>,
126 )
127 })