rapscallion icon indicating copy to clipboard operation
rapscallion copied to clipboard

It doesnt seem to work with ImmutableJS

Open oskarleonard opened this issue 8 years ago • 6 comments

I am getting this error: TypeError: Unknown node of type: undefined at traverse.js:373:9

When i try to do this in a comp

    return (
        <div className="footer__container">
            {
                links && links.map((link, index) => {
                    return (
                        <p key={index}>dfdfdf</p>
                    );
                })
            }
        </div>
    );

However, if i change the link to a regular js list it will work:

    return (
        <div className="footer__container">
            {
                links && links.toJS().map((link, index) => {
                    return (
                        <p key={index}>dfdfdf</p>
                    );
                })
            }
        </div>
    );

When i log the list to the console, you clearly see the props of the regular list while the ImmutableJS list will only display object. And you can see the type prop on the regular list.

image

image

oskarleonard avatar Aug 08 '17 16:08 oskarleonard

I've just gotten the exact same error for the exact same reason. It would be really cool if we had support for Immutable.js since lots of people use it in their projects.

Razem avatar Nov 20 '17 17:11 Razem

Have you tried calling “.toArray()” after “.map”, otherwise React will use immutable’s iterables which rapscallion probably doesn’t support

kitten avatar Nov 20 '17 18:11 kitten

@philpl Sure, it worked. But since React supports Immutable lists, I would expect the same from Rapscallion.

Razem avatar Nov 20 '17 19:11 Razem

To help my understanding of the changes involved, can someone point me to how React handles things or a pseudo-code diff of what the changes would involve to be immutable-compatible?

ryan-roemer avatar Nov 20 '17 21:11 ryan-roemer

Hi @wayweary. Can you provide a reduced repro that I can work against? This should definitely be addressable, but it'll be easier if I start without having to recreate your broken experience. @Razem, feel free to jump in, too :)

divmain avatar Nov 28 '17 06:11 divmain

@divmain Here is an example: https://github.com/Razem/rapscallion-immutable-test

As you can see, it can be successfully rendered using the ReactDOMServer.renderToString method, but Rapscallion fails to recognize Immutable objects as iterables.

I believe the problem is somewhere in src/render/traverse.js.

Also note that since React 16, keys are also rendered for Immutable maps. Which is not happening in React 15. So {testMap.map((item, key) => (<span key={key}>{item} </span>))} would actually render a<span>Hello </span>b<span>World </span> instead of just <span>Hello </span><span>World </span>. But since the Rapscallion is focused on React 15, it should probably render the output wihout the keys.

Razem avatar Nov 28 '17 12:11 Razem