preact icon indicating copy to clipboard operation
preact copied to clipboard

preact/debug: Incorrect table warning

Open marvinhagemeister opened this issue 2 years ago • 4 comments

  • [x] Check if updating to the latest Preact version resolves the issue

Describe the bug preact/debug throws a warning when the code is valid HTML code. That's unexpected.

To Reproduce

import "preact/debug";
import { render } from "preact";

render(<table><tr /></table>, document.getElementById("app"));

Expected behavior No warning, it's a valid HTML structure. Iirc there are some rules regarding tbody when it must be present and not. I don't know them at the top of my head, best to check with the spec.

marvinhagemeister avatar Aug 20 '23 20:08 marvinhagemeister

I originally noticed this with a complete table structure, including thead and tbody. I was also getting warnings about those elements needing a table parent (which they had).

adamgreg avatar Aug 20 '23 20:08 adamgreg

@marvinhagemeister this does not warn for me https://codesandbox.io/s/damp-dream-td65f3?file=/src/index.js

JoviDeCroock avatar Aug 22 '23 09:08 JoviDeCroock

This vdom structure does result in HTML which doesn't match the vdom and is modified during hydration.

See this (admittedly canned) example where there's a flash of styling change when hydration happens: https://codesandbox.io/s/busy-williams-scnwzw?file=/src/index.mjs

nmain avatar Aug 23 '23 16:08 nmain

Interesting! Looks like the browser automatically inserts a <tbody> element.

marvinhagemeister avatar Aug 23 '23 16:08 marvinhagemeister

This doesn't throw/log an error, but it should; while the spec technically allows for <tr> to be a child of <table>, it does this knowing full well that all parsers will instead wrap it inside of a <tbody>.

We should warn here.

rschristian avatar May 08 '24 19:05 rschristian