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

Whitespace text nodes cannot appear as a child of <tr> #2000

Closed
4 tasks done
Lokua opened this issue Apr 4, 2022 · 4 comments · Fixed by #2252
Closed
4 tasks done

Whitespace text nodes cannot appear as a child of <tr> #2000

Lokua opened this issue Apr 4, 2022 · 4 comments · Fixed by #2252
Labels
💪 phase/solved Post is done

Comments

@Lokua
Copy link

Lokua commented Apr 4, 2022

Initial checklist

Affected packages and versions

[email protected]

Link to runnable example

Code Sandbox

Steps to reproduce

Seems we are unable to render jsx tables without white space warnings. This is not limited to <tr> as the title suggests, but pretty much any scenario where'd you want to write a table in jsx directly using typical code indentation will result in this error: Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <tr>. Make sure you don't have any extra whitespace between tags on each line of your source code..

code sandbox repro: https://codesandbox.io/s/fervent-star-m9qufk?file=/src/App.js

Easy work around is to wrap the jsx in a component: https://codesandbox.io/s/wonderful-haibt-bldeqz?file=/src/App.js

So not really a huge problem, but something I thought was worth bringing up.

Expected behavior

Semantic tables in jsx/html (non-markdown) don't result in console warnings.

Actual behavior

jsx/html (non-markdown) tables result in validateDOMNesting warnings.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

@jblarriviere

This comment was marked as off-topic.

@wooorm

This comment was marked as off-topic.

@paulkre
Copy link

paulkre commented Oct 15, 2022

Does anyone have a workaround?

@wooorm
Copy link
Member

wooorm commented Oct 17, 2022

There’s a workaround mention in the post:

Easy work around is to wrap the jsx in a component: [codesandbox.io/s/wonderful-haibt-bldeqz?file=/src/App.js](https://codesandbox.io/s/wonderful-haibt-bldeqz?file=/src/App.js)

Even better, use an expression:

export const planet = 'World'

# Hello, {planet}!

{
  <table>
    <thead>
      <tr>
        <th>A</th>
        <th>B</th>
      </tr>
    </thead>
  </table>
}

wooorm added a commit that referenced this issue Feb 9, 2023
Whitespace should be fine but React still fails on it.

Closes GH-2000.
wooorm added a commit that referenced this issue Feb 9, 2023
@wooorm wooorm added the 💪 phase/solved Post is done label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging a pull request may close this issue.

4 participants