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

Comments between JSX attributes lead to props being ignored #826

Closed
1 of 3 tasks
marvinhagemeister opened this issue Sep 1, 2021 · 0 comments · Fixed by #828
Closed
1 of 3 tasks

Comments between JSX attributes lead to props being ignored #826

marvinhagemeister opened this issue Sep 1, 2021 · 0 comments · Fixed by #828
Labels
bug Something isn't working

Comments

@marvinhagemeister
Copy link
Member

Describe the bug
When there is a comment between JSX attributes, all following props are ignored.

<div
  // comment
  id="foo"
/>

The above snippet will be transformed to this during development:

html`<div
  // comment
  id="foo"
/>`

...and because htm only recognises HTML-style comments, it gets confused and thinks that the slash is an indicator for closing the tag, thereby dropping props.

<!-- this will be rendered in the final HTML -->
<div></div>

I'm not sure where the best place to solve this is. On one hand htm can be seen as more or less strict HTML DSL and therefore only <!-- --> comments should be allowed. On the other hand it's often used as an alternative to JSX which favors /* */ or // foo comments.

I'm currently leaning to supporting JS-style comments in htm as it feels kinda "nice" and easier for folks being used to JSX to adapt to. Made an upstream PR to enhance htm's parser to ignore JS-style comments at: developit/htm#214

To Reproduce

See above.

Expected behavior

<div id="foo"></div>

Bug occurs with:

  • wmr or wmr start (development)
  • wmr build (production)
  • wmr serve

The bug doesn't occur during production builds as we use the babel htm transform plugin that drops all comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant