compiler icon indicating copy to clipboard operation
compiler copied to clipboard

`<table>` is not rendered correctly in .astro components with `is:raw`

Open Yixuan-Wang opened this issue 3 years ago • 2 comments

What version of astro are you using?

2.0.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Linux(WSL)

Describe the Bug

The following .astro component code produces wrong HTML rendering results.

---
const html = `<table is:raw><thead><tr><th>a</th><th align="left">b</th><th align="right">c</th><th align="center">d</th></tr></thead><tbody><tr><td>1</td><td align="left">2</td><td align="right">3</td><td align="center">4</td></tr></tbody></table>`;
---
<table is:raw><thead><tr><th>a</th><th align="left">b</th><th align="right">c</th><th align="center">d</th></tr></thead><tbody><tr><td>1</td><td align="left">2</td><td align="right">3</td><td align="center">4</td></tr></tbody></table>
<hr>
<Fragment set:html={html}>

图片

The component is compiled into the following HTML, which is not desired.

abcd1234
<table></table>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-wzww1o?file=src/pages/index.astro

Participation

  • [ ] I am willing to submit a pull request for this issue.

Yixuan-Wang avatar Jan 31 '23 17:01 Yixuan-Wang

Hi, I had a brief look into this. It looks like if you remove the is:raw from the table it works just fine.

E.g.

<table><thead><tr><th>a</th><th align="left">b</th><th align="right">c</th><th align="center">d</th></tr></thead><tbody><tr><td>1</td><td align="left">2</td><td align="right">3</td><td align="center">4</td></tr></tbody></table>

The docs on is:raw seem to suggest it's only really needed in special cases, because it treats everything inside as text. This might explain the weird behaviour on your end.

https://docs.astro.build/en/reference/directives-reference/#advanced-directives

bloycey avatar Feb 01 '23 05:02 bloycey

I still think this behavior is a quirk. The doc of is:raw suggest that the content inside will be treated as plain text. Does that imply it will be forwarded to innerHTML if the outer element is a vanilla HTML element?

Yixuan-Wang avatar Feb 01 '23 07:02 Yixuan-Wang