react-native-image-viewing icon indicating copy to clipboard operation
react-native-image-viewing copied to clipboard

Can't perform a React state update on an unmounted component is appearing while closing the modal using onRequestClose.

Open Jatverma54 opened this issue 5 years ago • 6 comments

node_modules\react-native\Libraries\LogBox\LogBox.js:173:8 in registerError

  • node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
  • node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
  • node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:106:4 in printWarning
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:75:16 in error
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19152:9 in warnAboutUpdateOnUnmountedFiberInDEV
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17093:40 in scheduleUpdateOnFiber
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:11003:16 in dispatchAction
  • [native code]:null in dispatchAction
  • node_modules\react-native-image-viewing\dist\hooks\useRequestClose.js:29:23 in setTimeout$argument_0
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:383:16 in callTimers
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

Jatverma54 avatar Dec 03 '20 17:12 Jatverma54

+1

Any temporary fix for this ?

Janak-Nirmal avatar Feb 08 '21 11:02 Janak-Nirmal

Bump

nextstudioal avatar Apr 13 '21 16:04 nextstudioal

Facing the same issue

bruuuuuuuce avatar May 11 '21 22:05 bruuuuuuuce

@Jatverma54 @bruuuuuuuce Can you share a repo with minimal implementation where this issue is occurring? I can look into it and submit a PR if possible.

Are you conditionally rendering ImageViewing component?

rajeshde avatar Aug 10 '21 03:08 rajeshde

I found it occurs if you change imageIndex prop in onRequestClose callback or somehow modify imageIndex while fadeout. My case:

const [currentIndex, setCurrentIndex] = useState(null)
// ...
  visible={typeof currentIndex === 'number'}
  imageIndex={currentIndex}
  onRequestClose={() => setCurrentIndex(null)}
// ...

Changed to:

const [isVisible, setIsVisible] = useState(false)
const [currentIndex, setCurrentIndex] = useState(0)
// ...
  visible={isVisible}
  imageIndex={currentIndex}
  onRequestClose={() => setIsVisible(false)}
// ...

Solution: don't use same state for visible and imageIndex props

mr-faraday avatar Aug 12 '21 13:08 mr-faraday

For my case, I changed this:

{fullscreenImg && !isPDF && (
    <ImageView
      images={fullscreenImages}
      imageIndex={0}
      visible={fullscreenImg}
      onRequestClose={() => setFullscreenImg(false)}
    />
)}

To the following:

<ImageView
  images={fullscreenImages}
  imageIndex={0}
  visible={fullscreenImg}
  onRequestClose={() => setFullscreenImg(false)}
/>

vahidvdn avatar Apr 26 '23 14:04 vahidvdn