mayu-live / framework

Mayu is a live updating server-side component-based VDOM rendering framework written in Ruby
https://mayu.live
GNU Affero General Public License v3.0
130 stars 4 forks source link

Validate nesting of DOM nodes #14

Open aalin opened 1 year ago

aalin commented 1 year ago

Browsers accept invalid HTML and rearranges things into valid HTML.

So:

<table>
  <tr></tr>
</table>

will turn into:

<table>
  <tbody>
    <tr></tr>
  </tbody>
</table>

This will make Mayu confused because there is a tbody where there should be a tr...

Something like this maybe:

https://github.com/facebook/react/blob/97d75c9c8bcddb0daed1ed062101c7f5e9b825f4/packages/react-dom-bindings/src/client/validateDOMNesting.js

This should be configurable so that it can be disabled in production mode.

Update: If #20 gets implemented with Nokogiri, then, I think that Nokogiri will make sure elements are wrapped correctly. The errors from Nokogiri could be logged, but the server side DOM will at least be valid, so that it will always be in sync with the browser DOM.