mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-21 20:03:08 +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 rootRef = useRef<HTMLDivElement>(null)
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
const chipRowRef = useRef<HTMLDivElement>(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 baseId = useId()
|
||||||
const listboxId = (surface: SuggestionSurface) => `${baseId}-${surface}-listbox`
|
const listboxId = (surface: SuggestionSurface) => `${baseId}-${surface}-listbox`
|
||||||
const optionId = useCallback(
|
const optionId = useCallback(
|
||||||
|
|
@ -175,6 +177,15 @@ export const RelationChipCell = ({
|
||||||
[baseId],
|
[baseId],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (blurCloseTimeoutRef.current != null) {
|
||||||
|
window.clearTimeout(blurCloseTimeoutRef.current)
|
||||||
|
blurCloseTimeoutRef.current = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOptimistic((current) => {
|
setOptimistic((current) => {
|
||||||
if (!current) return null
|
if (!current) return null
|
||||||
|
|
@ -685,7 +696,11 @@ export const RelationChipCell = ({
|
||||||
}}
|
}}
|
||||||
onFocus={() => setOpen(true)}
|
onFocus={() => setOpen(true)}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
window.setTimeout(() => {
|
if (blurCloseTimeoutRef.current != null) {
|
||||||
|
window.clearTimeout(blurCloseTimeoutRef.current)
|
||||||
|
}
|
||||||
|
blurCloseTimeoutRef.current = window.setTimeout(() => {
|
||||||
|
blurCloseTimeoutRef.current = null
|
||||||
if (!rootRef.current?.contains(document.activeElement)) {
|
if (!rootRef.current?.contains(document.activeElement)) {
|
||||||
closeSuggestions()
|
closeSuggestions()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue