-
Notifications
You must be signed in to change notification settings - Fork 71
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
Warning on component unmount #17
Comments
try doing this -> got to svgImage.js inside the library folder and do the following changes
it worked for me |
hey also add this to the start of the component -> |
@appdemox sadly that didn't fix it for me, still getting the error (the same one described above) |
so im not the only one... |
thanks but that did not fix it for me.. |
Hi, When this component mounts, it tries to fetch the svg file data and sets it to state. It is a one time operation. RN is warning about a potential memory leak in a case where a component maybe subscribed to an event listener, and continues to call setState when the event triggers (even though the component has unmounted). So calling setState after component has unmounted could be a sign that you have an event listener that has not been purged yet, and such event listener could cause memory leak. There is no memory leak in this case since the image is only attempted to be fetched once, and setState is called definitely just once. I could add a fix to not call setState if component has already been unmounted, but that is not the issue here. It seems like there is an underlying issue with component in the root level. I'll give you an example: If you have a loading spinner that uses this component, and this component fetches data from uri provided, and before the svg can be loaded, the actual data has been fetched so there is no need to show the spinner anymore. In this case, you would probably be better off using an icon font or a svg from within project instead of loading it from remote uri (since there is no point making the user to wait for some time just to see a loading spinner). The other case is that you actually have a view that needs to render an image, but the parent keeps modifying the key so the Image component keeps getting recreated multiple times. This could be a big perf issue in your app. So I suggest you to put a Post your findings here after checking. Cheers! |
Hi, thanks for this library.
This component is working well for me but the only strange thing is that it gives me this warning every time the component unmounts. Is there something that I have to unsubscribe to in componentWillUnmount?
Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
in SvgImage (at index.js:18)
in MyImage (at index.js:71)
in RCTView (at View.js:60)
in View (at index.js:70)
in RCTView (at View.js:60)
in View (at index.js:69)
in RCTScrollContentView (at ScrollView.js:791)
in RCTScrollView (at ScrollView.js:887)
in ScrollView (at index.js:68)
in Login (created by Connect(Login))
in Connect(Login) (at SceneView.js:10)
The text was updated successfully, but these errors were encountered: