Overview
Follow these best practices to create high-quality, performant, and maintainable Shopify extensions with Synapse.Performance Optimization
Bundle Size
Keep extensions under 50KB
- Remove unused imports
- Avoid large dependencies
- Use tree-shaking
- Code splitting
Load Time
Load in under 500ms
- Lazy load components
- Minimize initial render
- Cache API responses
- Optimize images
Re-renders
Minimize unnecessary renders
- Use React.memo
- Optimize useEffect deps
- Memoize calculations
- Avoid inline functions
Function Speed
Functions under 5ms
- Use Rust over JavaScript
- Minimize loops
- Cache results
- Limit query surface
Code Quality
TypeScript Best Practices
- Strict Types
- Type Guards
- Interface Definitions
Use strict TypeScript configuration:Benefits:
- Catch errors early
- Better IDE support
- Self-documenting code
- Easier refactoring
Component Structure
1
Single Responsibility
Each component does one thing:
2
Extract Custom Hooks
Reuse logic with custom hooks:
3
Memoize Expensive Operations
Use useMemo for calculations:
Function Optimization
Rust vs JavaScript
- When to Use Rust
- When to Use JavaScript
- Performance Tips
Use Rust for:
- Production functions
- Performance-critical logic
- Complex calculations
- Large-scale operations
- 10-100x faster than JS
- Compiled to WebAssembly
- Type safety
- No garbage collection
Error Handling
Graceful Degradation
Graceful Degradation
Handle failures without breaking:
Error Boundaries
Error Boundaries
Catch component errors:
Function Error Handling
Function Error Handling
Never panic in functions:
User-Friendly Messages
User-Friendly Messages
Explain errors clearly:
Testing
- Unit Tests
- Integration Tests
- Function Tests
Test individual functions:
Accessibility
Keyboard Navigation
Support keyboard users:
Screen Readers
Label everything:
Color Contrast
Ensure readability:
- Use Shopify UI components (compliant by default)
- Avoid custom colors
- Test with contrast checker
- Minimum 4.5:1 ratio
Focus States
Visible focus indicators:
- Shopify components have focus states
- Don’t remove with CSS
- Test with Tab key
- Ensure focus order logical
Security
Input Validation
Input Validation
Validate all user inputs:
API Security
API Security
Secure API calls:
Sensitive Data
Sensitive Data
Never log or expose:
Deployment Best Practices
1
Test Locally First
2
Review MCP Validation
Check validation output before deploying
- All APIs valid
- No deprecated components
- TypeScript compiles
- No console errors
3
Monitor Deployment
Watch logs during deployment:Verify deployment succeeds
4
Test in Dev Store
- Add items to cart
- Go through checkout
- Test all code paths
- Verify on mobile
5
Monitor Performance
- Check loading times
- Review error rates
- Monitor function execution time
- Track user feedback