Files
twenty/packages
Sonarly Claude Code ccbe22b9e9 Filter dropdown crashes when currentView is undefined during render
https://sonarly.com/issue/5512?type=bug

The ViewBarFilterDropdownAdvancedFilterButton component throws an unrecoverable error during render when `currentView?.objectMetadataId` is falsy, crashing the filter dropdown UI on the `/objects/companies` page.

Fix: Split `ViewBarFilterDropdownAdvancedFilterButton` into a wrapper and an inner `ViewBarFilterDropdownAdvancedFilterButtonContent` component.

**The wrapper** (exported) calls only `useGetCurrentViewOnly()` and checks `currentView?.objectMetadataId`. If undefined, it returns `null` — gracefully hiding the button during transient states when view data hasn't loaded yet. This avoids the render-time crash.

**The content component** receives `objectMetadataId` as a guaranteed `string` prop, so all hooks (`useObjectMetadataItemById`, `useAtomFamilySelectorValue`, etc.) are called unconditionally, satisfying React's Rules of Hooks.

Changes:
1. Renamed the original component to `ViewBarFilterDropdownAdvancedFilterButtonContent`, accepting `objectMetadataId: string` as a prop
2. Removed the `throw new Error('Object metadata id is missing from current view')` guard and the `objectMetadataId` local variable
3. Changed `objectId: objectMetadataId ?? null` to `objectId: objectMetadataId` (no longer nullable)
4. Added new exported `ViewBarFilterDropdownAdvancedFilterButton` wrapper that returns `null` when `objectMetadataId` is not defined, otherwise renders the content component

This is the same approach from two prior unmerged fix attempts (commits `0df4821e41` and `7728d61983`).
2026-03-12 10:11:15 +00:00
..