-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
Unexpected access to getter
property in irrelevant plain objects
#1012
Comments
Usually the quickest way to find these things out, is to disable that piece of code and see if a test breaks. Not sure if I understood your question correctly, but yes, I think it is indeed for "wrapping" cases like: |
@mweststrate This explanation is make scene to me, then I think ANOTHER reason in deep is the 93 line in it access Lines 90 to 98 in 8e12c78
In any case, immer shouldn't even have to try freeze a
it shoud write the process deal in "write" step of |
I'm not sure there is an easy non-expensive way of skipping over calling the getters, but feel to give it a try. In any case, having (non-idempotent) side effects usually creates problems in any case, even without Immer. |
Actually, I have a series of array with each item that has a It's not really lacking side effects, but just have relatively more computationally intensive. |
Yeah getters in an immutable tree are always a bit of a strange thing.
Using a separate weakmap instead can be a cleaner solution.
As an ugly workaround you could keep a global flag to prevent computations,
or maybe `isDraft(this)` works as well in the getter. Feel free to submit a
PR that would address this issue (upfront I don't give merge guarantees, as
that will depend on correctness, perf impact, maintability and size)
…On Wed, Jan 11, 2023 at 9:59 AM zthxxx ***@***.***> wrote:
Actually, I have a series of array with each item that has a getter
property to make lazy calculations when they need to be used for the
performance reasons, but immer called all of them even only make
irrelevant modifications in produce(), so our page is stuck.
—
Reply to this email directly, view it on GitHub
<#1012 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBFY5ZGMN25JWL5AJNLWRZY6LANCNFSM6AAAAAATXFLJD4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Immer 10 changed the approached to getters, so closing here. |
🙋♂ Question
Here is two question, when will a plain object contain
drafts
in the recursivelyfinalize
function?I think a plain object here always means not modify in
produce()
and not create by immer proxy, maybe move a proxy draft property into new object then add it back to draft's new property field?immer/src/core/finalize.ts
Lines 62 to 71 in 8e12c78
Is that the only thing need to do in this condition for plain object is
maybeFreeze(rootScope, value, true)
rather thaneach(finalizeProperty(...)))
?I think this is the reason to cause some UNEXPECTED access to
getter
property in an irrelevant plain object whenproduce()
returns result, which will have some side effects.The problem case like below:
Link to repro
To reproduce: https://stackblitz.com/edit/node-pgmcfz?file=immer-getter-without-freeze.mjs
Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: