slideshare/REACT19_IMPLEMENTATION.md
Michael Mainguy 15d3789bb4 Add full-screen layout preview route and fix iframe sandbox issue
- Create LayoutPreviewPage component for full-screen layout previews
- Add preview route /themes/:themeId/layouts/:layoutId/preview to App routing
- Update theme components with preview links and improved navigation
- Fix iframe sandbox error by adding allow-scripts permission
- Enhance template renderer with layout metadata support
- Replace PostCSS with regex-only CSS parsing for browser compatibility
- Add comprehensive standards documentation for code quality
- Clean up CSS slot indicators to be always visible with descriptions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 13:48:13 -05:00

112 lines
3.2 KiB
Markdown

# React 19 Implementation Standards
## Current Status: NOT IMPLEMENTED
The codebase uses React 19.1.1 but implements ZERO React 19 features. This is a significant gap.
This might be OK if the features aren't needed, are complex or costly, or there is a better way that
doesn't violate react standard approaches.
## Required React 19 Features to Implement
### 1. Actions for Form Handling
Replace manual form state management with React 19 Actions:
```typescript
// ❌ CURRENT - Manual state management
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const handleSubmit = async (e) => {
setLoading(true);
try {
await submitForm(e);
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
// ✅ REACT 19 - Actions
const [state, submitAction] = useActionState(async (prevState, formData) => {
// Action automatically handles loading/error states
return await submitForm(formData);
}, initialState);
```
### 2. useOptimistic for Theme Previews
Implement optimistic updates for theme switching:
```typescript
// ✅ IMPLEMENT
function ThemePreview({ currentTheme }) {
const [optimisticTheme, setOptimisticTheme] = useOptimistic(
currentTheme,
(currentTheme, optimisticValue) => ({ ...currentTheme, ...optimisticValue })
);
const switchTheme = async (newTheme) => {
setOptimisticTheme(newTheme); // Immediate UI update
await saveTheme(newTheme); // Actual save
};
}
```
### 3. Modern Context Syntax
Replace Provider wrapper with direct Context rendering:
```typescript
// ❌ OLD
<ThemeContext.Provider value={themeValue}>
<App />
</ThemeContext.Provider>
// ✅ REACT 19
<ThemeContext value={themeValue}>
<App />
</ThemeContext>
```
### 4. Error Boundaries with Actions
Implement error boundaries that work with Actions:
```typescript
// ✅ IMPLEMENT
class ThemeErrorBoundary extends React.Component {
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, errorInfo) {
// Log to error reporting service
console.error('Theme loading error:', error, errorInfo);
}
}
```
## Implementation Priority
### HIGH PRIORITY
1. **Theme selection Actions** - Replace manual form handling
2. **Error boundaries** - Add proper error handling
3. **useOptimistic for theme previews** - Better UX
### MEDIUM PRIORITY
1. **Context syntax modernization** - Update provider patterns
2. **Form Actions for theme creation** - When that feature is added
3. **Server Actions integration** - If backend is added
### LOW PRIORITY
1. **Preloading optimization** - Use React 19 preloading APIs
2. **Streaming SSR** - If SSR is implemented
3. **Advanced concurrent features** - As needed
## Migration Strategy
1. Start with theme selection Actions (highest impact)
2. Add error boundaries for robustness
3. Implement optimistic updates for better UX
4. Gradually modernize Context usage
5. Add advanced features as needed
## Resources
- [React 19 Actions Documentation](https://react.dev/reference/react/useActionState)
- [useOptimistic Hook](https://react.dev/reference/react/useOptimistic)
- [Error Boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)