New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning null or false from render within SVG hierarchy crashes app #84
Comments
Thanks for reporting this. |
Hi @magicismight and @steveliles, I seem to be encountering the second of these two issues as well - an exception similar to: As mentioned in the original issue, It occurs when There is no error if the component initially renders I’ve also noticed the same exception is thrown if the element I return is of a different type from the one previously rendered, e.g. changing
So it seems that:
Versions
If you have any ideas or if I might be doing something stupid please let me know 😄 |
Having the same issue with "react-native-svg": "^5.2.0" but I can workaround this problem by toggling the SVG element |
When building React components it is very convenient to be able to return null (or false) when you don't want to render anything. This is a documented feature of React.
However, returning null or false from the render method of a component nested somewhere within an Svg hierarchy fails (at least on iOS - I didn't try with Android yet).
The failure mode is different depending on whether a falsy value is returned in the initial render or a subsequent render that changes the output from a renderable component to a falsy value.
For example, the following crashes the app immediately (app completely shuts down and exits to home screen):
If a state or props change causes a render method to start returning falsy values where it previously returned SVG components an exception is thrown, for example:
The exception this produces is:
Exception 'shadowView (for ID 554) not found' was thrown while invoking replaceExistingNonRootView on target RCTUIManager with params ( 554, 555 )
My current workaround is instead of returning null, return a
<Nothing/>
component defined as:The text was updated successfully, but these errors were encountered: