Skip to content

Commit

Permalink
fix(explorer): use functional state updates to fix rendering loop
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Aug 22, 2024
1 parent 88aa98a commit 76529b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/components/discovery/DiscoveryQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ const DiscoveryQueryBuilder = ({ activeDataset, dataTypeForms, requiredDataTypes
setSchemasModalShown((s) => !s);
}, []);

const handleSetFormRef = useCallback(
(dataType, form) => {
setForms({ ...forms, [dataType.id]: form });
},
[forms],
);
const handleSetFormRef = useCallback((dataType, form) => {
// Without a functional state update, this triggers an infinite loop in rendering variant search
setForms((forms) => ({ ...forms, [dataType.id]: form }));
}, []);

useEffect(() => {
if (autoQuery?.isAutoQuery && shouldExecAutoQueryPt2) {
Expand Down
15 changes: 6 additions & 9 deletions src/components/discovery/DiscoverySearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,12 @@ const DiscoverySearchForm = ({ onChange, dataType, setFormRef, handleVariantHidd
[dataType],
);

const updateHelpFromFieldChange = useCallback(
(k, change) => {
setConditionsHelp({
...conditionsHelp,
[k]: change.fieldSchema.description, // can be undefined
});
},
[conditionsHelp],
);
const updateHelpFromFieldChange = useCallback((k, change) => {
setConditionsHelp((h) => ({
...h,
[k]: change.fieldSchema.description, // can be undefined
}));
}, []);

const getInitialOperator = useCallback(
(field, fieldSchema) => {
Expand Down

0 comments on commit 76529b5

Please sign in to comment.