mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 06:43:06 +00:00
fix(campaign): clear RelationChipCell blur timeout on unmount
Prevents setState after jsdom teardown (window is not defined) that failed CI unit on leadershipStateDeputyRelationCell.
This commit is contained in:
parent
07c884ee2e
commit
e36634786e
1 changed files with 16 additions and 1 deletions
|
|
@ -168,6 +168,8 @@ export const RelationChipCell = ({
|
|||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const chipRowRef = useRef<HTMLDivElement>(null)
|
||||
/** Blur debounce — cleared on unmount so setState cannot fire after jsdom teardown (CI flake). */
|
||||
const blurCloseTimeoutRef = useRef<number | null>(null)
|
||||
const baseId = useId()
|
||||
const listboxId = (surface: SuggestionSurface) => `${baseId}-${surface}-listbox`
|
||||
const optionId = useCallback(
|
||||
|
|
@ -175,6 +177,15 @@ export const RelationChipCell = ({
|
|||
[baseId],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (blurCloseTimeoutRef.current != null) {
|
||||
window.clearTimeout(blurCloseTimeoutRef.current)
|
||||
blurCloseTimeoutRef.current = null
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
setOptimistic((current) => {
|
||||
if (!current) return null
|
||||
|
|
@ -685,7 +696,11 @@ export const RelationChipCell = ({
|
|||
}}
|
||||
onFocus={() => setOpen(true)}
|
||||
onBlur={() => {
|
||||
window.setTimeout(() => {
|
||||
if (blurCloseTimeoutRef.current != null) {
|
||||
window.clearTimeout(blurCloseTimeoutRef.current)
|
||||
}
|
||||
blurCloseTimeoutRef.current = window.setTimeout(() => {
|
||||
blurCloseTimeoutRef.current = null
|
||||
if (!rootRef.current?.contains(document.activeElement)) {
|
||||
closeSuggestions()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue