-
-
Notifications
You must be signed in to change notification settings - Fork 6
hashCode attempts to modify frozen object #140
Comments
I found the solution to it in immutable-js#1717 |
@bdurrer Yeah, still wasn't sure whether to keep this open or not, because it seemed like a change in behavior from |
It is a regression, yes. I am also not sure if we should care about it tho. |
@conartist6 Any opinion on this one? |
After reviewing this, I don't think this is really |
This isn't about setting properties on an immutable object, it's about setting properties on any object used as a key. The real fix is to drop IE11 support and use Maps internally instead of this bonkers system with objects and hash codes. |
Okay, interesting, I didn't look at it closely enough. Do you think this is worth changing for 4.0? |
I guess I think it depends. We could always push it to 5.0. And it'd be a fair amount of work I think. Who is going to do it? We'd probably want to rip out hashCode and hash and valueObject too, since those are all part of this crazy solution to make up for the lack of Maps. |
I would postpone it or even make redux-freeze fix it instead |
I was able to reproduce this in 3.8.2 (CodeSandbox) so I'm removing it from the 4.0 milestone. (Perhaps there was a change that made it happen more often in some of the 4.x releases?) |
I think it usually happend when modifying Records in Maps, but I never figured out how to pinpoint it, it felt random. Oops , misclicked on close |
From @bdurrer on Thu, 13 Jun 2019 17:44:19 GMT
I already wrote this into an old issue (immutable-js#1228), which was about an older release version and is closed.
What happened
When working with records in collections, Immutable sometimes tries to set an hashCode of a frozen object, resulting in an exception.
Expected behavior: No exception, of course. I expect hashCode to be set when creating an instance, not generated later on.
The hashCode function looks like a getter but apparently it sets it too:
How to reproduce
It started happening after upgrading from 4.0.0-rc.9 to 4.0.0-rc.12.
I am very sorry, but I was unable to create an example which triggers this behavior. It only occurs in a big react/redux/saga project, where the redux state is using Immutable collections and various Record types heavily.
The behavior can be reproduced in said project, it reliably appears in the same code location. However, it appears in weird places, e.g. at one point a call to
orderedMap.has(itemRecord)
throws it, somewhere else it is alist.valueSeq()
that fails.Furthermore, calling
orderedMap.has(itemRecord)
in some other location might not produce an error at all. It seems like it is an arcane order of things that need to happen, before the error occurs.Anyway, here is an stacktrace, which was triggered by a seemingly simple
orderedMap.has(itemRecord)
:In this case,
has()
triggershashCode()
on the Record, which is already part of theorderedMap
and (in my understanding) should already have set the hash code.Originally posted by @bdurrer in immutable-js#1228 (comment)
Copied from original issue: immutable-js#1717
The text was updated successfully, but these errors were encountered: