Skip to content
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

Problem with rendering nested elements returned by a function. #128

Open
mthadley opened this issue Jun 14, 2016 · 4 comments
Open

Problem with rendering nested elements returned by a function. #128

mthadley opened this issue Jun 14, 2016 · 4 comments

Comments

@mthadley
Copy link

mthadley commented Jun 14, 2016

Given the following component:

import Component from 'metal-jsx';
import {range} from 'lodash';

class CoolList extends Component {
    renderMessage(index) {
        return <em>{`my message ${index}`}</em>;
    }

    render() {
        return (
            <ul>
                {
                    range(5).map(
                        index => <li key={index}>{this.renderMessage(index)}</li>
                    )
                }
            </ul>
        );
    }
}

...this is what I see rendered:

<ul>
  <em>my message 0</em>
  <em>my message 1</em>
  <em>my message 2</em>
  <em>my message 3</em>
  <em>my message 4</em>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>

I noticed that if I make the following change, then the em is correctly rendered inside the li:

renderMessage(i) {
    // Return an array instead:
    return [<em>{`my message ${i}`}</em>];
}

Is this expected?

@mairatma
Copy link
Contributor

Nope, not expected, thanks for reporting this!

This is actually an issue with the compiler we use from JSX to incremental dom, so I've opened up an issue there. They've been extremely helpful with issues like this, so it should be fixed soon :)

@mairatma
Copy link
Contributor

mairatma commented Jul 5, 2016

This issue was moved to #6

@mairatma mairatma closed this as completed Jul 5, 2016
@mairatma
Copy link
Contributor

This issue was moved back.

@mairatma mairatma reopened this Jul 21, 2016
@mairatma
Copy link
Contributor

Just FYI, it seems like this problem has already been fixed by babel-plugin-incremental-dom (which has actually been renamed to babel-plugin-transform-incremental-dom).

Anyone using it directly just needs to update its version, but we should also update babel-preset-metal-jsx to use the new one now. I've created an issue there for this. We can close this once that's done and we've confirmed that the new version really fixes this issue.

If anyone wants to, feel free to grab this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants