Skip to content

toJS() converts plain JS objects with a length property, in an Immutable collection, to an array (v4) #1438

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

Closed
jsibelman opened this issue Nov 8, 2017 · 1 comment
Milestone

Comments

@jsibelman
Copy link

What happened

Using Immutable 4.0.0-rc.9, a Map containing a plain object with a length: <number> property gets converted via toJS() to an object containing only an array of that length, with any other properties removed.

What I expected to see was a plain object containing a plain object with all properties intact.

We ran into this issue dealing with the output produced by Draft's convertToRaw helper which produces a property called inlineStyleRanges which is an array of objects, all of which have a length: <number> property.

How to reproduce

You can see it in action here:
https://codepen.io/jsibelman/pen/ooYJMX?editors=0012

The code:

const node = Immutable.Map({
  inlineStyleRanges: {
    length: 4,
    foo: 'bar'
  }
});

console.log('node.toJS()', node.toJS());

The output seen in the console:

"node.toJS()" Object {
  inlineStyleRanges: [undefined, undefined, undefined, undefined]
}
@jsibelman jsibelman changed the title toJS() converts plain JS objects, with a length property, in an Immutable collection to an array (v4) toJS() converts plain JS objects with a length property, in an Immutable collection, to an array (v4) Nov 8, 2017
@acusti
Copy link
Contributor

acusti commented May 10, 2018

This issue is fixed in a fork I’m maintaining to help get v4 over the finish line. If you would find it useful, you can install a build now that includes the fix by replacing your immutable dependency string in package.json with:

    "immutable": "brandcast/immutable-js-built#aa94985",

Note that I needed to clear out my yarn.lock file and node_modules and install from scratch to get the proper version.

@leebyron leebyron added this to the 4.0 milestone May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants