preactjs / create-preact

Create a Vite-powered Preact app in seconds
MIT License
46 stars 6 forks source link

Missing classes on even children #11

Closed thegamerx1 closed 10 months ago

thegamerx1 commented 10 months ago

Creating a template app and just changing the anchor to a paragraph breaks the classes. https://github.com/thegamerx1/vike-even/commit/d23d5eb725a32f0a930b70921fb13ff35f3d2e5c

thorium_dSSEHFr2Vf

lourot commented 10 months ago

Hi, Aurélien from Vike here. It happens only with <p>, not <div> or <span>. I'm not sure why this happens with <p>, but note that what you are trying to achieve is not valid HTML, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p :

Paragraphs are block-level elements, and notably will automatically close if another block-level element is parsed before the closing </p> tag. See "Tag omission" below.

Putting an <h2> inside a <p> will cause premature closing of <p> and weird things happen. (to be precise: it is valid HTML but it won't behave like you expect)

So I don't think what you are seeing is a preact nor a vike bug. The system is correctly making the weird specified things happen ;)

rschristian commented 10 months ago

Yep, browsers will insert a closing </p> where they need to which will throw off Preact (as its knowledge of the DOM is incorrect due to outside changes).

This, however, is a bug in your markup, not with any of the tools in use here. Going to close this out.

preact/debug should be warning you of this in dev I believe, per https://github.com/preactjs/preact/issues/4093