Hidden Features & Patterns in Ocean
This document reveals powerful features and patterns that already exist in Ocean but might not be immediately obvious.
🎯 Data Fetching & Mutations
useMutationWithToast
Automatically handles loading states, success/error toasts, and cache invalidation:
const mutation = useMutationWithToast({
mutationFn: async (data) => apiClient.updateProfile(data),
successMessage: 'Profile updated successfully',
errorMessage: 'Failed to update profile',
invalidateQueries: [['profile', userId]],
})
useGraphQLQuery
Type-safe GraphQL queries with automatic error handling:
const { data, isLoading } = useGraphQLQuery(GET_USER_QUERY, { userId }, { enabled: !!userId })
withRetry
Built-in retry logic for resilient API calls:
const result = await withRetry(() => apiClient.fetchData(), { maxAttempts: 3, delayMs: 1000 })
🔐 Authentication Patterns
Multi-Tab Synchronization
Auth state automatically syncs across browser tabs - no setup needed!
JWT Monitoring
The <JWTMonitor /> component tracks token expiry in real-time:
- Shows countdown to expiry
- Automatic refresh attempts
- Visual indicators for token health
Race Condition Protection
Auth context handles concurrent auth operations safely - no manual coordination needed.
🎨 UI Utilities
useIsMobile Hook
Responsive behavior without media queries:
const isMobile = useIsMobile()
return isMobile ? <MobileView /> : <DesktopView />
Theme-Aware Assets
Dynamic logos based on current theme:
const logo = getThemedLogo(theme, systemPreference)
const logomark = getThemedLogomark(theme, systemPreference)
Loading Skeletons
Pre-built loading states:
if (isLoading) return <DashboardLoadingSkeleton />
if (isAuthLoading) return <AuthLoadingSkeleton />
🚨 Error Handling
Error Boundaries
Three types for different contexts:
// Wrap components with specific error handling
export default withErrorBoundary(MyComponent, {
fallback: <CustomErrorUI />,
onError: (error) => console.error(error),
})
Manual Error Triggering
const { showBoundary } = useErrorBoundary()
// Trigger error boundary programmatically
showBoundary(new Error('Something went wrong'))
Structured Error Classes
throw new ApiError('Failed to fetch', { statusCode: 404 })
throw new AuthError('Session expired')
throw new NetworkError('Connection lost')
🛠️ Development Tools
Debug Commands
# Debug user creation flow
pnpm debug:user "test@email.com" "Org Name"
# Check production health
pnpm health:check
# Monitor secret rotation
pnpm security:check
# Test performance regression
pnpm perf:check
One-Command Setup
# Complete environment setup in <5 minutes
pnpm setup:ocean
Error Boundary Testing
In development, use <ErrorBoundaryTest /> to test error states.
📊 Performance Features
GraphQL Operation Tracking
All GraphQL operations are automatically tracked for performance:
- Operation duration
- Success/failure rates
- Automatic Sentry integration
Bundle Size Monitoring
# Check for bundle size regressions
pnpm perf:check
🎯 Form Patterns
TanStack Form with Valibot
Type-safe forms with automatic validation:
const form = useForm({
defaultValues: { email: '' },
onSubmit: async ({ value }) => {
await mutation.mutateAsync(value)
},
validators: {
onChange: profileUpdateSchema,
},
})
Pre-built Validation Schemas
Check /src/schemas/ for reusable validation:
loginSchemasignupSchemaprofileUpdateSchemaorganizationSchema
🔄 State Management
Organization Context
Automatically manages organization switching:
const { currentOrganization, switchOrganization } = useOrganization()
PostHog Integration
Feature flags and analytics ready to use:
const { isFeatureEnabled } = usePostHog()
if (isFeatureEnabled('new-feature')) {
// Show new feature
}
🎪 Hidden UI Features
Container Queries (Tailwind v4)
Components can respond to their container size:
<div className="@container">
<div className="grid @sm:grid-cols-2 @lg:grid-cols-3">
{/* Responsive to container, not viewport! */}
</div>
</div>
Dynamic Breadcrumbs
Breadcrumbs automatically update based on route - no manual management needed.
Collapsible Sidebar
The sidebar remembers its state and syncs across page reloads.
💡 Pro Tips
- Always use
useMutationWithToastinstead of raw mutations - Leverage error boundaries instead of try-catch in components
- Use
useIsMobilefor responsive logic instead of CSS-only - Check
/scripts/folder for automation tools - Use
pnpm validatebefore commits - it catches many issues - Explore
/docs/adr/for architecture decisions and rationale
🚀 Advanced Patterns
Provisioning Service
New user setup is fully automated:
- Creates Supabase profile
- Provisions Neon database
- Sets up Stripe customer
- All with automatic rollback on failure
Health Monitoring
Production health endpoints track:
- Database connections
- External service availability
- Queue sizes
- Error rates
Security Monitoring
Automatic monitoring for:
- Secret rotation schedules
- API key usage
- Authentication anomalies
Most of these features work out-of-the-box without additional configuration. The Ocean platform is more powerful than it appears on the surface!