WorkspaceWrapper
component provides a centralized way to handle workspace ID resolution and validation across the application. It automatically converts legacy workspace identifiers to validated UUIDs and provides the full workspace object to child components.
Problem Solved
Currently, workspace ID resolution is handled inconsistently across components:'personal'
→ resolves to the user’s personal workspace UUID'internal'
→ resolves toROOT_WORKSPACE_ID
- UUID strings → validates and uses as-is
WorkspaceWrapper
centralizes this logic and ensures that child components always receive a validated workspace UUID.
Installation
TheWorkspaceWrapper
is available in the web app at @/components/workspace-wrapper
.
Basic Usage
Function Children Pattern
With Loading Fallback
Advanced Usage
Using withWorkspace Helper
For client components that need workspace context, use thewithWorkspace
helper:
Client Component Receiving Workspace Props
API Reference
WorkspaceWrapper Props
Prop | Type | Required | Description |
---|---|---|---|
params | Promise<{ wsId: string }> | Yes | The route params containing wsId |
children | Function | Yes | Function that receives { workspace, wsId, isPersonal, isRoot } |
fallback | ReactNode | No | Loading fallback component |
withWorkspace Parameters
Parameter | Type | Required | Description |
---|---|---|---|
wsId | string | Yes | The workspace identifier (legacy or UUID) |
Component | React.ComponentType | Yes | Client component to render |
props | T | Yes | Props to pass to the component |
fallback | ReactNode | No | Loading fallback component |
Children Function Parameters
Parameter | Type | Description |
---|---|---|
workspace | Workspace & { role: WorkspaceUserRole; joined: boolean } | Full workspace object with user role and joined status |
wsId | string | Validated UUID from workspace.id |
isPersonal | boolean | Whether the workspace is a personal workspace |
isRoot | boolean | Whether the workspace is the root/internal workspace |
Migration Guide
Before (Manual Resolution)
After (With WorkspaceWrapper)
Real-World Example
Here’s how the dashboard page uses the WorkspaceWrapper:Benefits
- Centralized Logic: All workspace ID resolution logic is centralized
- Type Safety: TypeScript ensures proper workspace object structure
- Error Handling: Automatic
notFound()
when workspace doesn’t exist - Loading States: Built-in Suspense support with custom fallbacks
- Cleaner Code: Reduces boilerplate in page components
- Future-Proof: Easy to modify workspace resolution logic in one place
Error Handling
TheWorkspaceWrapper
automatically handles common error cases:
- Invalid workspace ID →
notFound()
- User not authenticated → Redirects to login (via
getWorkspace
) - Workspace not found →
notFound()
- User not a member →
notFound()
Performance Considerations
- The wrapper uses React Suspense for loading states
- Workspace data is fetched once and passed down to children
- Consider using
fallback
prop for better UX during loading - The component is optimized for server-side rendering
Best Practices
- Always use the validated
wsId
from the wrapper, not the original parameter - Provide meaningful fallbacks for better user experience
- Use the
withWorkspace
helper for client components that need workspace context - Keep workspace logic centralized - don’t duplicate workspace resolution elsewhere
- Handle loading states gracefully with appropriate fallback components
Troubleshooting
Common Issues
Issue:notFound()
is called unexpectedly
Solution: Ensure the user has access to the workspace and the workspace ID is valid
Issue: TypeScript errors with workspace object
Solution: Make sure you’re using the workspace object provided by the wrapper, not importing it separately
Issue: Loading state never resolves
Solution: Check that the getWorkspace
function is working correctly and not throwing errors
Debug Tips
- Check the browser’s Network tab for failed workspace requests
- Verify the workspace ID in the URL is correct
- Ensure the user is authenticated and has workspace access
- Check the console for any error messages from
getWorkspace