Skip to content

Commit 10c1159

Browse files
committed
feat: Introduce native React 19 metadata support with a new PageMetadata component, replacing useDocumentTitleUpdater in home wrappers and adding related documentation.
1 parent 05197d4 commit 10c1159

File tree

9 files changed

+850
-42
lines changed

9 files changed

+850
-42
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
description: React 19 Features Implementation Plan
3+
---
4+
5+
# React 19 Features Implementation Plan
6+
7+
This document outlines the recommended React 18/19 features to implement in the DevBcn codebase.
8+
9+
## Phase 1: Quick Wins (High Impact, Low Effort)
10+
11+
### 1. Document Metadata Support
12+
13+
**Priority**: HIGH
14+
**Effort**: LOW
15+
**Impact**: Improves SEO, simplifies code
16+
17+
**Implementation**:
18+
19+
- Replace any react-helmet usage with native React 19 metadata
20+
- Add `<title>`, `<meta>`, and `<link>` tags directly in page components
21+
- Update year-specific pages (2023, 2024, 2025, 2026) with proper metadata
22+
23+
**Files to update**:
24+
25+
- `src/views/Home/HomeWrapper.tsx`
26+
- `src/2023/Home/Home2023Wrapper.tsx`
27+
- `src/2024/Home/HomeWrapper2024.tsx`
28+
- `src/2025/Home/HomeWrapper2025.tsx`
29+
- All major page components
30+
31+
### 2. Resource Preloading
32+
33+
**Priority**: HIGH
34+
**Effort**: LOW
35+
**Impact**: Faster page loads
36+
37+
**Implementation**:
38+
39+
- Add `preconnect` for Sessionize API
40+
- Add `preload` for critical fonts and images (Logo)
41+
- Add `prefetchDNS` for external resources
42+
43+
**Files to update**:
44+
45+
- `src/index.tsx` (global preloads)
46+
- Major route components
47+
48+
### 3. Enhanced Suspense Boundaries
49+
50+
**Priority**: MEDIUM
51+
**Effort**: LOW
52+
**Impact**: Better loading states
53+
54+
**Implementation**:
55+
56+
- Wrap async data fetching components with Suspense
57+
- Add better fallback components
58+
- Improve error boundaries
59+
60+
**Files to update**:
61+
62+
- `src/components/Router/SuspenseRoute.tsx`
63+
- Data-fetching components
64+
65+
## Phase 2: Data Fetching Improvements (Medium Effort)
66+
67+
### 4. Migrate to `use()` Hook
68+
69+
**Priority**: MEDIUM
70+
**Effort**: MEDIUM
71+
**Impact**: Cleaner async code
72+
73+
**Implementation**:
74+
75+
- Gradually migrate from react-query to `use()` API
76+
- Start with simple data fetching hooks
77+
- Keep react-query for complex caching needs
78+
79+
**Files to update**:
80+
81+
- `src/hooks/useFetchSpeakers.ts`
82+
- `src/hooks/useFetchTalks.ts`
83+
- Other data fetching hooks
84+
85+
## Phase 3: Advanced Features (Higher Effort)
86+
87+
### 5. Optimistic Updates with `useOptimistic`
88+
89+
**Priority**: LOW
90+
**Effort**: MEDIUM
91+
**Impact**: Better UX for interactive features
92+
93+
**Implementation**:
94+
95+
- Add to favorite/bookmark features (if any)
96+
- Add to voting/rating features (if any)
97+
- Add to any user interaction that requires server updates
98+
99+
### 7. Ref Cleanup Functions
100+
101+
**Priority**: LOW
102+
**Effort**: LOW
103+
**Impact**: Better resource management
104+
105+
**Implementation**:
106+
107+
- Review all ref usage
108+
- Add cleanup functions where needed
109+
- Focus on intersection observers, event listeners
110+
111+
## Phase 4: Future (Experimental)
112+
113+
### 8. React Compiler
114+
115+
**Priority**: FUTURE
116+
**Effort**: LOW (once stable)
117+
**Impact**: Automatic performance optimization
118+
119+
**Implementation**:
120+
121+
- Wait for stable release
122+
- Enable compiler in build config
123+
- Remove manual `useMemo` and `useCallback`
124+
- Test thoroughly
125+
126+
## Implementation Steps
127+
128+
1. **Start with Phase 1** - Quick wins that improve performance immediately
129+
2. **Test thoroughly** - Ensure 80% test coverage is maintained
130+
3. **Monitor performance** - Use React DevTools to measure improvements
131+
4. **Document changes** - Update README with new patterns
132+
5. **Gradual migration** - Don't rush, migrate incrementally
133+
134+
## Success Metrics
135+
136+
- [ ] Improved Lighthouse scores
137+
- [ ] Faster Time to Interactive (TTI)
138+
- [ ] Better Core Web Vitals
139+
- [ ] Reduced bundle size (if removing libraries)
140+
- [ ] Improved developer experience
141+
- [ ] All tests passing with 80%+ coverage
142+
143+
## Notes
144+
145+
- React 19 is now stable (released December 5, 2024)
146+
- Most features are production-ready
147+
- Server Components require Next.js or similar framework
148+
- React Compiler is still experimental but used in production by Instagram

docs/PageMetadata-Usage.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# PageMetadata Component - Usage Guide
2+
3+
## Overview
4+
5+
The `PageMetadata` component leverages React 19's native metadata support to render SEO tags directly in your components without needing external libraries like `react-helmet`.
6+
7+
## Quick Start
8+
9+
### Basic Usage
10+
11+
```tsx
12+
import { PageMetadata } from "@components/common/PageMetadata";
13+
14+
export const MyPage = () => {
15+
return (
16+
<>
17+
<PageMetadata
18+
title="My Page Title"
19+
description="A brief description of my page"
20+
/>
21+
22+
{/* Your page content */}
23+
</>
24+
);
25+
};
26+
```
27+
28+
### Using Centralized Configuration
29+
30+
For consistency across the site, use the centralized metadata configuration:
31+
32+
```tsx
33+
import { PageMetadata } from "@components/common/PageMetadata";
34+
import { getPageMetadata } from "@config/metadata";
35+
36+
export const HomeWrapper2025 = () => {
37+
return (
38+
<>
39+
<PageMetadata {...getPageMetadata("home2025")} />
40+
41+
{/* Your page content */}
42+
</>
43+
);
44+
};
45+
```
46+
47+
## Advanced Usage
48+
49+
### Custom Metadata
50+
51+
```tsx
52+
<PageMetadata
53+
title="DevBcn 2025 - Speakers"
54+
description="Meet our amazing speakers for DevBcn 2025"
55+
canonicalUrl="https://www.devbcn.com/2025/speakers"
56+
ogImage="https://www.devbcn.com/images/speakers-2025.jpg"
57+
ogType="website"
58+
twitterCard="summary_large_image"
59+
keywords={["speakers", "tech conference", "barcelona", "2025"]}
60+
/>
61+
```
62+
63+
### Dynamic Metadata
64+
65+
```tsx
66+
export const SpeakerDetailPage = ({ speaker }) => {
67+
return (
68+
<>
69+
<PageMetadata
70+
title={`${speaker.name} - DevBcn Speaker`}
71+
description={speaker.bio}
72+
canonicalUrl={`https://www.devbcn.com/speakers/${speaker.id}`}
73+
ogImage={speaker.profileImage}
74+
ogType="article"
75+
/>
76+
77+
{/* Speaker content */}
78+
</>
79+
);
80+
};
81+
```
82+
83+
## Props Reference
84+
85+
| Prop | Type | Required | Default | Description |
86+
| -------------- | ------------------------------------ | -------- | ----------------------- | -------------------------- | ----------------------- |
87+
| `title` | `string` || - | Page title (will append " | DevBcn" if not present) |
88+
| `description` | `string` || - | Page description for SEO |
89+
| `canonicalUrl` | `string` || - | Canonical URL for the page |
90+
| `ogImage` | `string` || Default OG image | Open Graph image URL |
91+
| `ogType` | `"website" \| "article" \| "event"` || `"website"` | Open Graph type |
92+
| `twitterCard` | `"summary" \| "summary_large_image"` || `"summary_large_image"` | Twitter card type |
93+
| `keywords` | `string[]` || `[]` | SEO keywords |
94+
95+
## Adding New Pages to Configuration
96+
97+
To add a new page to the centralized configuration:
98+
99+
1. Open `src/config/metadata.ts`
100+
2. Add your page to the `METADATA_CONFIG` object:
101+
102+
```typescript
103+
export const METADATA_CONFIG = {
104+
// ... existing pages
105+
106+
myNewPage: {
107+
title: "My New Page - DevBcn",
108+
description: "Description of my new page",
109+
canonicalUrl: `${BASE_URL}/my-new-page`,
110+
ogImage: `${BASE_URL}/images/my-new-page.jpg`,
111+
keywords: ["keyword1", "keyword2"],
112+
},
113+
};
114+
```
115+
116+
3. Use it in your component:
117+
118+
```tsx
119+
<PageMetadata {...getPageMetadata("myNewPage")} />
120+
```
121+
122+
## Migration from react-helmet
123+
124+
If you're migrating from `react-helmet`, here's the comparison:
125+
126+
### Before (react-helmet)
127+
128+
```tsx
129+
import { Helmet } from "react-helmet";
130+
131+
<Helmet>
132+
<title>My Page | DevBcn</title>
133+
<meta name="description" content="My description" />
134+
<link rel="canonical" href="https://www.devbcn.com/my-page" />
135+
</Helmet>;
136+
```
137+
138+
### After (React 19 Native)
139+
140+
```tsx
141+
import { PageMetadata } from "@components/common/PageMetadata";
142+
143+
<PageMetadata
144+
title="My Page"
145+
description="My description"
146+
canonicalUrl="https://www.devbcn.com/my-page"
147+
/>;
148+
```
149+
150+
## Benefits
151+
152+
**No External Dependencies** - Uses React 19's native features
153+
**Type-Safe** - Full TypeScript support
154+
**Centralized** - All metadata in one configuration file
155+
**Consistent** - Automatic title formatting
156+
**SEO-Friendly** - Includes all essential meta tags
157+
**Social Media Ready** - Open Graph and Twitter cards included
158+
159+
## Testing
160+
161+
The component includes comprehensive tests. To run them:
162+
163+
```bash
164+
npm test -- PageMetadata
165+
```
166+
167+
## Best Practices
168+
169+
1. **Always provide title and description** - These are essential for SEO
170+
2. **Use the centralized config** - Keeps metadata consistent
171+
3. **Include canonical URLs** - Helps with duplicate content issues
172+
4. **Provide OG images** - Improves social media sharing
173+
5. **Use descriptive keywords** - But don't keyword stuff
174+
6. **Keep descriptions under 160 characters** - For optimal display in search results
175+
7. **Make titles unique** - Each page should have a distinct title
176+
177+
## Examples by Page Type
178+
179+
### Home Page
180+
181+
```tsx
182+
<PageMetadata {...getPageMetadata("home2025")} />
183+
```
184+
185+
### Content Page (Speakers, Talks, etc.)
186+
187+
```tsx
188+
<PageMetadata {...getPageMetadata("speakers")} />
189+
```
190+
191+
### Dynamic Detail Page
192+
193+
```tsx
194+
<PageMetadata
195+
title={`${item.title} - DevBcn`}
196+
description={item.description}
197+
canonicalUrl={`https://www.devbcn.com/${item.slug}`}
198+
ogImage={item.image}
199+
/>
200+
```
201+
202+
## Troubleshooting
203+
204+
**Q: The title doesn't appear in the browser tab**
205+
A: Make sure the `PageMetadata` component is rendered. Check React DevTools to verify it's in the component tree.
206+
207+
**Q: Meta tags aren't showing in view source**
208+
A: React 19's metadata is rendered client-side. For SSR, you'll need a framework like Next.js.
209+
210+
**Q: Can I use multiple PageMetadata components?**
211+
A: Only use one per page. The last one rendered will take precedence.
212+
213+
**Q: How do I test if metadata is working?**
214+
A: Use browser DevTools to inspect the `<head>` element, or use tools like [metatags.io](https://metatags.io/) to preview social cards.

0 commit comments

Comments
 (0)