-
Notifications
You must be signed in to change notification settings - Fork 12
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
Crio and React - Array Map #20
Comments
I'll scope this out as soon as I'm home, I'm on vacation right now but will be home this evening. Can you post the code you used to create this? I want to make sure I replicate the circumstances as best I can. |
Unfortunately it is proprietary code so can't copy paste directly. However it is something similar to : `
} where the props contains a property called "data" which is an object similar to:
Some additional info:
Let me know if I can help more. |
I just reread this again and I have a feeling I know what the problem is... if the item returned from the map is an object or array, it tries to re-crio the returned value into a new crio. This is not necessary when the object returned is a react object. I'll try to come up with a generic isPlainObject checker so that this doesn't happen with react objects or other non-POJOs. |
I think it makes sense. I think the other libraries (seamless immutable or freezer not sure) also had this issue and it was quite annoying to have to do a toJS() on each array that arrive to React. |
@andreigabreanu indeed, actually my solution was to learn from (steal?) I have tested this locally and it's working as expected, so I'm gonna release it soon and you can tell me if it solves your problem (if it doesn't, I'll do a more rigorous testing when I have more time this week). I have also included some documentation to the README about recursive objects because the real root of the issue is that React elements are recursive objects and you cannot make a recursive object truly immutable ( |
alright, released v2.5.1 with the treatment of React elements as immutable, closing for now. If you have any more issues with this let me know! |
Tested as well with 2.5.1. It works indeed. I think this makes sense and I wouldn't say it is a bug in the library because the data is basically acting the proper way, the fact that react does some stuff in the loop and overall this makes everything slow is more or less a React issue. Anyway, thanks for the very fast help ! Have a great day! |
Actually it may not be a React issue... even though it's letting the object through, the object is still getting hashed for equality comparison, and hashing that recursive object may be slowing things down significantly. I'll see if I can tune it up. EDIT Indeed the hashing of the ReactElement was causing a significant slowdown (when mapping 10 elements it was taking 87ms, whereas the native was taking less than 1ms). In version 2.5.2 I have been able to cut that significantly so that the time is much closer to the native (difference is negligible until u get into mapping over 1000+ React elements). One extra step that you can take, though, is setting up a generic utility function that uses the native const thawMap = (crioArray, fn) => {
return Array.prototype.map.call(crioArray, fn);
}); In my quick testing, this performed at the same rate as the native Thanks @andreigabreanu! |
I confirm it works good now ! (without the generic fn). |
It seems that when using Crio with React and you have an array of objects and try to do a simple iteration crio fails with error (see below).
Adding a .thaw().map() instead fixes the problem so it is probably something related to how React interacts with Crio during the map.
The text was updated successfully, but these errors were encountered: