Close passphrase scanner on unmount (#2313)

This commit is contained in:
ekzyis 2025-07-23 16:32:45 +02:00 committed by GitHub
parent 2a0dfd7af6
commit e1162b815a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1350,11 +1350,21 @@ function PasswordScanner ({ onScan, text }) {
loading: () => <PageLoading /> loading: () => <PageLoading />
}) })
const closeRef = useRef()
useEffect(() => {
return () => {
// close modal on remount to avoid calling stale callbacks
// see https://github.com/stackernews/stacker.news/pull/2313
closeRef.current?.()
}
}, [])
return ( return (
<InputGroup.Text <InputGroup.Text
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
onClick={() => { onClick={() => {
showModal(onClose => { showModal(onClose => {
closeRef.current = onClose
return ( return (
<div> <div>
{text && <h5 className='line-height-md mb-4 text-center'>{text}</h5>} {text && <h5 className='line-height-md mb-4 text-center'>{text}</h5>}