sylvainpolletvillard / ObjectModel

Strong Dynamically Typed Object Modeling for JavaScript
http://objectmodel.js.org
MIT License
467 stars 30 forks source link

Immer.js interop problem #123

Closed ArturBaybulatov closed 4 years ago

ArturBaybulatov commented 4 years ago

When objectmodel used in conjunction with immer, the following error comes up:

import produce from 'immer';
import {ArrayModel} from 'objectmodel';

produce(['a', 'b'], arr => { arr.push('c') })
// OK: ["a", "b", "c"]

produce(ArrayModel(String)(['a', 'b']), arr => { arr.push('c') })
// Custom Formatter Failed: Uncaught TypeError: 'getPrototypeOf' on proxy:
//   proxy target is non-extensible but the trap did not return its actual prototype
sylvainpolletvillard commented 4 years ago

Hello,

What version of immer are you using ? I can't reproduce the exception with the latest version, but the return value of produce() is null: https://codesandbox.io/s/amazing-feistel-w8yg1

I'm not familiar with immer but it looks like a bug. I just don't know what operation immer is doing on the object to get to this result

ArturBaybulatov commented 4 years ago

Latest versions of both: objectmodel 4.0.6, immer 6.0.1. The error is visible, when the code is run in a browser console. Although, looks like it's only a warning, since it doesn't stop the execution.

image

Actually, I've created this issue, because I had a different error in my project code, which is relatied to objectmodel and immer. The original error was the following:

image

My code was the following:

image

For now, I've worked around the problem, configuring immer to disable auto freezing:

import {setAutoFreeze} from 'immer';

setAutoFreeze(false);

I'm gonna close the issue, since the original problem turned out to be just a warning, and not a real error. Thanks!

sylvainpolletvillard commented 4 years ago

Okay, if you have more details about the specific operations done on model instances that give unexpected results, please keep me informed :+1: