Skip to content

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

Closed
@jsibelman

Description

@jsibelman

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]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions