Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-4382: Fixing the reset button functionality #2217

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const TreeViewWrapper: React.FC<TreeViewWrapperProps> = (props) => {
const { roots, isLoading, error } = useGetManyObstreeData(conceptUuids);

if (error) return <ErrorState error={error} headerTitle={t('dataLoadError', 'Data load error')} />;

const MemoizedFilterProvider = React.memo(FilterProvider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because MemoizedFilterProvider is declared within the TreeViewWrapper component:

  • A new component type is created on every render of TreeViewWrapper
  • React will unmount the older provider and mount a new one each time TreeViewWrapper re-renders
  • Any state in the subtree of FilterProvider will reset on re-render

We should move the memoized component outside the parent to preserve its identity as a stable reference:

const MemoizedFilterProvider = React.memo(FilterProvider); 

const TreeViewWrapper: React.FC<TreeViewWrapperProps> = (props) => {
  // ... rest of the code
  return <MemoizedFilterProvider roots={...} />;
};

Copy link
Author

@UNCANNY69 UNCANNY69 Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised that the solution work in a completely unexpected way (Due to it referencing the component again its remounting and triggering initialize action , which is completely not right)

if (roots?.length) {
return (
<FilterProvider roots={!isLoading ? roots : []}>
<MemoizedFilterProvider roots={!isLoading ? roots : []}>
<TreeView {...props} isLoading={isLoading} />
</FilterProvider>
</MemoizedFilterProvider>
);
}

Expand Down