Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{@html html-string} replacing tr,td tags #4852

Closed
mishrasatyam opened this issue May 17, 2020 · 6 comments
Closed

{@html html-string} replacing tr,td tags #4852

mishrasatyam opened this issue May 17, 2020 · 6 comments
Labels

Comments

@mishrasatyam
Copy link

If a table's tbody has an existing tr element and we place another tr before it using @html tag,
the tags tr, td are stripped.
To Reproduce
Please see here:
https://svelte.dev/repl/dee930a465e14a31baa1846003463e12?version=3.22.3

Thanks

@Conduitry Conduitry added the bug label May 18, 2020
@Conduitry
Copy link
Member

It looks like this happened between 3.6.11 and 3.7.0 as a result of #3329. I'm not sure what can reasonably be done about this. The newer way of handling {@html} blocks involves creating a temporary <div> and setting its innerHTML, which presents a problem here, as certain types of elements are not allowed as children of <div>s.

@GrygrFlzr
Copy link
Member

What if instead of creating a <div>, the compiler creates a <template> element instead?
It seems like it was meant for element fragments.

@GrygrFlzr
Copy link
Member

In the meantime, here's a workaround which uses <template>:
https://svelte.dev/repl/bf25404232fe427899450cc397f461a6?version=3.22.3

@Rich-Harris
Copy link
Member

As an alternative to using <template> (which has the IE compatibility issue @Conduitry identifies in #4857), what if we used the same element as the parent, or maybe only in cases where these issues arise?

e.g.

-html_tag = new HtmlTag(/*html_data*/ ctx[0], null);
+html_tag = new HtmlTag(/*html_data*/ ctx[0], null, 'tbody');

That would require the compiler to know the parent element type at runtime, which precludes top-level {@html ...} tags and any future <svelte:element> additions. Though perhaps it could be done at runtime instead, if we rejiggered things in HtmlTag slightly.

@Rich-Harris
Copy link
Member

FYI have implemented the proposed alternative in #4863

@Conduitry
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants