Skip to content

fix(android): Unable to update properties for view tag#5216

Closed
ngocle2497 wants to merge 3 commits intosoftware-mansion:mainfrom
ngocle2497:fix/android_update_props
Closed

fix(android): Unable to update properties for view tag#5216
ngocle2497 wants to merge 3 commits intosoftware-mansion:mainfrom
ngocle2497:fix/android_update_props

Conversation

@ngocle2497
Copy link

Summary

Platform: Android

I catch this issue when use FlashList with large data and have animated update on each item.
One element can be update/replace/recycle, so view tag can be update/remove too
So, before update props, we check current view tag exist in UIManager or not.

Fix #4505
Fix #4231
Fix #3860

Test plan

Before:

before.mp4

After:

after.mp4

@efstathiosntonas
Copy link
Contributor

efstathiosntonas commented Oct 11, 2023

Hi @MasonLe2497, Log needs to be imported:

NodesManager.java:356: error: cannot find symbol Log.d("Reanimated-updateProps", "Skip update props cause viewTag not exist or have been removed!");

@tomekzaw
Copy link
Member

@MasonLe2497 Thanks for submitting the PR! I agree we should do something about this error. Instead of checking if the view exists before updating props, maybe we could wrap mUIImplementation.synchronouslyUpdateViewOnUIThread and mUIManager.updateView calls into try/catch blocks? This way we can also avoid the error in case when the view exists when calling updateProps on the UI thread but no longer exists when calling mUIManager.updateView on the native modules thread.

@ngocle2497
Copy link
Author

@MasonLe2497 Thanks for submitting the PR! I agree we should do something about this error. Instead of checking if the view exists before updating props, maybe we could wrap mUIImplementation.synchronouslyUpdateViewOnUIThread and mUIManager.updateView calls into try/catch blocks? This way we can also avoid the error in case when the view exists when calling updateProps on the UI thread but no longer exists when calling mUIManager.updateView on the native modules thread.

Ok. I'll try tomorrow.(from UTC +7:00)

@ngocle2497
Copy link
Author

@tomekzaw i tried to wrap try/catch to mUIImplementation.synchronouslyUpdateViewOnUIThread, but i still catch the issue.
I think synchronouslyUpdateViewOnUIThread run on different thread, so we cant catch nothing here

Screen.Recording.2023-10-12.at.09.19.45.mov

@ngocle2497
Copy link
Author

Hi @MasonLe2497, Log needs to be imported:

NodesManager.java:356: error: cannot find symbol Log.d("Reanimated-updateProps", "Skip update props cause viewTag not exist or have been removed!");

Thanks, I just update my PR

@Latropos Latropos added Important This seem to be a serious issue and we will need to take a deeper look into it some time soon and removed Important This seem to be a serious issue and we will need to take a deeper look into it some time soon labels Oct 26, 2023
@ranaavneet
Copy link

Hey @tomekzaw, is there anything else we can do about this?

@thomazcapra
Copy link

👀

@damianbeles
Copy link

@tomekzaw any update?

Comment on lines +347 to +349
// We need to check current view exist in UIManager or not
// Sometime, view can be replace, recycle, ... with wrong way (like FlashList)
// So before update, We need to check view tag exist in UIManager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rephrase this comment

Comment on lines +352 to +354
if(view == null) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(view == null) {
return;
}
if (view == null) {
return;
}

if(view == null) {
return;
}
} catch (Exception ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (Exception ex) {
} catch (Exception e) {

return;
}
} catch (Exception ex) {
Log.d("Reanimated-updateProps", "Skip update props cause viewTag not exist or have been removed!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this warning so that we don't pollute the logs.

Suggested change
Log.d("Reanimated-updateProps", "Skip update props cause viewTag not exist or have been removed!");

}
} catch (Exception ex) {
Log.d("Reanimated-updateProps", "Skip update props cause viewTag not exist or have been removed!");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please describe in which cases the exception will be thrown?

@damianbeles
Copy link

@ngocle2497 do you plan to review the change requests? We really need this in prod. If not, let me know and I'll do it.

joe-sam

This comment was marked as resolved.

@thomas-rx
Copy link
Contributor

@damianbeles @ngocle2497 I opened ticket #5767 to address that important error.

github-merge-queue bot pushed a commit that referenced this pull request May 13, 2024
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

I'm opening this PR to address a critical issue previously tackled by PR
#5216, which has stalled due to the original author's inactivity.

This fix is crucial for resolving significant bugs affecting Android
view property updates (referenced in issues #4505, #4231, #3860) that
impact application stability and performance.

Typical error : 
```unknown:NativeViewHierarchyManager: Unable to update properties for view tag 943
03-07 19:54:33.543 19722 19722 E unknown:NativeViewHierarchyManager: com.facebook.react.uimanager.IllegalViewOperationException: ViewManager for tag 943 could not be found.
```

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->

### Before patching

https://github.com/software-mansion/react-native-reanimated/assets/40337934/a7cd7f8c-c0a3-4a84-98f7-4853886799f0

### After patching

https://github.com/software-mansion/react-native-reanimated/assets/40337934/c4dfe495-fed9-48cf-a227-e7768cec26cc

---------

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
@piaskowyk
Copy link
Member

Thank you for your pull request and the time you've dedicated to it! I appreciate that 🙌. These changes have been implemented in this PR, so I'll close this one.

@piaskowyk piaskowyk closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

10 participants