Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stable-filter-selector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@equinor/fusion-react-filter": patch
---

Prevent `FilterOptionHeader` from entering an infinite render loop after upgrading `@equinor/fusion-observable` by keeping its selection count selector stable across renders.
4 changes: 3 additions & 1 deletion packages/filter/src/components/filter/FilterOptionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type FilterHeaderProps = {
readonly title: string;
};

const getSelectedCount = (selection?: Set<unknown>): number => selection?.size ?? 0;

const Styled = {
Root: styled.div`
display: flex;
Expand Down Expand Up @@ -63,7 +65,7 @@ export const FilterOptionHeader = (props: FilterHeaderProps): ReactElement => {
const { options$, selection$ } = useFilterOptionContext();
const optionCount = Object.keys(useObservableState(options$).value || {}).length;
const { value: selectedCount } = useObservableState(
useObservableSelector(selection$, (x) => (x ?? new Set()).size),
useObservableSelector(selection$, getSelectedCount),
{ initial: 0 },
);

Expand Down
Loading