solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.3k stars 923 forks source link

Malformed HTML warning for HTML within an attribute (i.e. Bootstrap Tooltip) #2338

Open murphye opened 2 days ago

murphye commented 2 days ago

Describe the bug

Using Solid 1.9.3, when running npm run build I get The HTML provided is malformed and will yield unexpected output when evaluated by a browser..

I started with the Solid Bootstrap template (https://github.com/solidjs/templates/tree/main/ts-bootstrap) and narrowed down where the problem is stemming from where there is HTML within an attribute, as shown here for a Bootstrap Tooltip:

                  <button
                      type="button"
                      class="btn btn-secondary"
                      data-bs-toggle="tooltip"
                      data-bs-html="true"
                      title="<em>Tooltip</em> <u>with</u> <b>HTML</b>"
                  >
                    Tooltip with HTML
                  </button>

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

The HTML provided is malformed and will yield unexpected output when evaluated by a browser.

- Expected
+ Received

- <div><section><h2>#text</h2><article><div><h3>#text</h3><a>#text</a></div><div><div><button>#text</button><button>#text</button><button>#text</button><button>#text</button><button>#text</em>#text<u>#text</u>#text<b>#text</b>#text</button></div></div></article></section></div>
+ <div><section><h2>#text</h2><article><div><h3>#text</h3><a>#text</a></div><div><div><button>#text</button><button>#text</button><button>#text</button><button>#text</button><button>#text#text<u>#text</u>#text<b>#text</b>#text</button></div></div></article></section></div>
Original HTML:
 <div class="bd-cheatsheet container-fluid bg-body"><section id=content><h2 class="sticky-xl-top fw-bold pt-3 pt-xl-5 pb-2 pb-xl-3">Contents</h2><article class="mt-3 mb-5 pb-5"id=tooltips><div class="bd-heading sticky-xl-top align-self-start mt-5 mb-3 mt-xl-0 mb-xl-2"><h3>Tooltips</h3><a class="d-flex align-items-center"href=../components/tooltips/>Documentation</a></div><div><div class="bd-example tooltip-demo"><button type=button class="btn btn-secondary"data-bs-toggle=tooltip data-bs-placement=top title="Tooltip on top">Tooltip on top</button><button type=button class="btn btn-secondary"data-bs-toggle=tooltip data-bs-placement=right title="Tooltip on end">Tooltip on end</button><button type=button class="btn btn-secondary"data-bs-toggle=tooltip data-bs-placement=bottom title="Tooltip on bottom">Tooltip on bottom</button><button type=button class="btn btn-secondary"data-bs-toggle=tooltip data-bs-placement=left title="Tooltip on start">Tooltip on start</button><button type=button class="btn btn-secondary"data-bs-toggle=tooltip data-bs-html=true title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Tooltip with HTML</button></div></div></article></section></div>

Expected behavior

No error

Screenshots or Videos

No response

Platform

Additional context

No response

ryansolid commented 1 day ago

I see. The output appears to be correct but the validation seems to get tripped up by the tags inside the title string. Thanks for reporting.

g-mero commented 10 hours ago

@ryansolid Same issue on <col /> and <colgroup/>

import { createMemo, For, onMount } from 'solid-js'
import context from './context'

function Col(props: { key: string, type: 'header' | 'body' }) {
  const [state, actions] = context.useContext()

  onMount(() => {
    actions.setSignalRefresh(state.signalRefresh + 1)
  })

  return (
    <col
      ref={(el) => { actions.setState(props.type === 'header' ? 'headerCols' : 'bodyCols', props.key, el) }}
      data-key={props.key}
    />
  )
}

export default function Colgroup(props: {
  type: 'header' | 'body'
}) {
  const [state] = context.useContext()
  const cols = createMemo(() => {
    if (state.data.length === 0) {
      return []
    }
    return Object.keys(state.data[0])
  })

  return (
    <>
      <colgroup>
        <For each={cols()}>
          {k => (
            <Col key={k} type={props.type} />
          )}
        </For>
      </colgroup>
    </>

  )
}
The HTML provided is malformed and will yield unexpected output when evaluated by a browser.

- Expected
+ Received

- <col>
Original HTML:
 <col>

The HTML provided is malformed and will yield unexpected output when evaluated by a browser.

- Expected
+ Received

- <colgroup></colgroup>
Original HTML:
 <colgroup></colgroup>
titoBouzout commented 7 hours ago

PR for tags in attributes, tfoot and col/colgroup https://github.com/ryansolid/dom-expressions/pull/370