From 5ff4f694fd50071ddd94752b4418b09e1ece2ecb Mon Sep 17 00:00:00 2001 From: Kundan Date: Fri, 24 Jul 2026 18:14:22 +0530 Subject: [PATCH] fix: Schema Diff filter chip toggle broadcasting stale empty selection (#10172) selectFilterOption() computed newOptions inside the functional setSelectedFilters(prev => {...}) updater, then used that same variable to dispatch TRIGGER_CHANGE_FILTER synchronously. Since the updater runs lazily on next render, every chip toggle broadcast an empty filter, so the tree always showed "No difference found" until a full re-Compare. Compute the new selection synchronously from current state and use it for both the state update and the dispatched event. Fixes #10102 --- .../components/SchemaDiffButtonComponent.jsx | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx b/web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx index 3cf0675e4..ef1beb066 100644 --- a/web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx +++ b/web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx @@ -112,21 +112,22 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI }, [filters]); const selectFilterOption = (option) => { - let newOptions = []; - setSelectedFilters((prev) => { - let newSelectdOptions = [...prev]; - let removeIndex = newSelectdOptions.indexOf(option); - if (prev.includes(option)) { - newSelectdOptions.splice(removeIndex, 1); - } else { - newSelectdOptions.push(option); - } - newOptions = [...newSelectdOptions]; - return newSelectdOptions; - }); + // Derive the new selection synchronously from the current state. + // The new array must be computed here (not inside a setState updater) + // because React invokes functional updaters lazily during render, so a + // value assigned inside the updater is not yet available when the event + // below fires. Reading it there previously broadcast an empty filter + // list, which blanked the results tree on every chip toggle. #10102 + let newSelectedOptions = [...selectedFilters]; + let removeIndex = newSelectedOptions.indexOf(option); + if (removeIndex !== -1) { + newSelectedOptions.splice(removeIndex, 1); + } else { + newSelectedOptions.push(option); + } - let filterParam = newOptions; - eventBus.fireEvent(SCHEMA_DIFF_EVENT.TRIGGER_CHANGE_FILTER, { filterParams: filterParam }); + setSelectedFilters(newSelectedOptions); + eventBus.fireEvent(SCHEMA_DIFF_EVENT.TRIGGER_CHANGE_FILTER, { filterParams: newSelectedOptions }); }; const selectCompareOption = (option) => {