codeant-ai-for-open-source[bot] commented on code in PR #38470:
URL: https://github.com/apache/superset/pull/38470#discussion_r2935255026
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -483,6 +506,47 @@ export default function PluginFilterSelect(props:
PluginFilterSelectProps) {
setExcludeFilterValues(value === 'true');
};
+ const debouncedLikeChange = useMemo(
+ () =>
+ debounce((text: string) => {
+ if (text) {
+ updateDataMask([text]);
+ } else {
+ updateDataMask(null);
+ }
+ }, Constants.SLOW_DEBOUNCE),
+ [updateDataMask],
+ );
+
+ useEffect(() => {
+ if (!isLikeOperator || clearAllTrigger) {
+ debouncedLikeChange.cancel();
+ }
+ }, [clearAllTrigger, debouncedLikeChange, isLikeOperator]);
+
+ useEffect(() => () => debouncedLikeChange.cancel(), [debouncedLikeChange]);
Review Comment:
**Suggestion:** The cleanup effect tied to `debouncedLikeChange` cancels
pending debounced updates every time the debounced function is recreated, which
can happen on normal prop/state changes. This can silently drop the latest
typed LIKE input (input shows text but filter is not applied). Track the latest
debounced function in a ref and only cancel on operator/clear-all transitions
and unmount. [race condition]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ LIKE input text may not reach filter state.
- ❌ Dashboard filtering can show stale unfiltered results.
- ⚠️ UI text and applied query become inconsistent.
```
</details>
```suggestion
const debouncedLikeChangeRef = useRef(debouncedLikeChange);
useEffect(() => {
debouncedLikeChangeRef.current = debouncedLikeChange;
}, [debouncedLikeChange]);
useEffect(() => {
if (!isLikeOperator || clearAllTrigger) {
debouncedLikeChangeRef.current.cancel();
}
}, [clearAllTrigger, isLikeOperator]);
useEffect(
() => () => {
debouncedLikeChangeRef.current.cancel();
},
[],
);
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open a dashboard Filter Bar where Select filter renders through
`FilterControl.tsx:133-146` → `FilterValue.tsx:153-170` (`<SuperChart
chartType={filterType}>`) into `SelectFilterPlugin.tsx`.
2. Configure that Select filter with LIKE mode (`isLikeOperator` true) and
inverse
selection enabled; UI shows both text input
(`SelectFilterPlugin.tsx:575-576`) and exclude
dropdown (`SelectFilterPlugin.tsx:560-563`).
3. Type text in the LIKE input; `handleLikeInputChange` queues a debounced
update
(`SelectFilterPlugin.tsx:529-533`, `509-517`) rather than immediate
`updateDataMask`.
4. Before debounce timeout, toggle the exclude dropdown
(`handleExclusionToggle` at
`SelectFilterPlugin.tsx:505-507`), which changes `excludeFilterValues`;
`updateDataMask`
depends on that (`SelectFilterPlugin.tsx:255`) so `debouncedLikeChange` is
recreated.
5. On recreation, cleanup effect `useEffect(() => () =>
debouncedLikeChange.cancel(),
[debouncedLikeChange])` (`SelectFilterPlugin.tsx:527`) cancels the pending
typed update;
input still displays text (`likeInputValue`) but no filter mask update is
emitted
(`setDataMask` only runs from dataMask changes at
`SelectFilterPlugin.tsx:460`).
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
**Line:** 521:527
**Comment:**
*Race Condition: The cleanup effect tied to `debouncedLikeChange`
cancels pending debounced updates every time the debounced function is
recreated, which can happen on normal prop/state changes. This can silently
drop the latest typed LIKE input (input shows text but filter is not applied).
Track the latest debounced function in a ref and only cancel on
operator/clear-all transitions and unmount.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38470&comment_hash=f3f4ea07fdffc6c3b20d320a127be802d0ba05bc807228491e391d375b4c6107&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38470&comment_hash=f3f4ea07fdffc6c3b20d320a127be802d0ba05bc807228491e391d375b4c6107&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]