Skip to content

Best Practices

packages/plugins/my-plugin/
├── src/
│ ├── components/ # UI components
│ ├── server/ # tRPC routers
│ ├── hooks/ # Custom hooks
│ ├── lib/ # Utilities
│ ├── types.ts # TypeScript types
│ ├── manifest.ts # Plugin manifest
│ └── index.ts # Exports
  • One component per file
  • Export from index.ts
  • Group related components in subdirectories
  • Use TypeScript for all code
// ✅ GOOD: Fetch only what you need
const { data } = trpc.timer.getEntries.useQuery({
workUnitId,
select: ['id', 'startTime', 'duration'],
limit: 50,
});
// ❌ BAD: Fetch all data
const { data } = trpc.timer.getAllData.useQuery();
const expensiveValue = useMemo(() => {
return calculateComplexMetric(data);
}, [data]);
const [searchQuery, setSearchQuery] = useState('');
const debouncedSearch = useDebouncedValue(searchQuery, 300);
useEffect(() => {
performSearch(debouncedSearch);
}, [debouncedSearch]);
export function MyComponent() {
const { data, isLoading, error } = trpc.getData.useQuery();
if (isLoading) return <Loader />;
if (error) {
return (
<Alert color="error">
Failed to load data: {error.message}
</Alert>
);
}
return <DataDisplay data={data} />;
}
// Define typed props
interface MyTabProps {
context: WorkUnitContext;
config: PluginConfig;
}
// Use typed hooks
const { data } = trpc.myPlugin.getData.useQuery<DataType>({ id });
// Type guards
function isWorkUnit(entity: any): entity is WorkUnit {
return entity && typeof entity.id === 'string';
}
import { render, screen } from '@testing-library/react';
import { MyComponent } from './MyComponent';
describe('MyComponent', () => {
it('renders correctly', () => {
render(<MyComponent data={mockData} />);
expect(screen.getByText('Expected Text')).toBeInTheDocument();
});
});
  • Use semantic HTML
  • Provide alt text for images
  • Ensure keyboard navigation
  • Use ARIA labels where needed
  • Test with screen readers
  • Validate all inputs
  • Sanitize user content
  • Check permissions before actions
  • Use parameterized queries
  • Never expose secrets in client code