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

Implicitly closing tags aren't allowed before closing block #2807

Closed
mrkishi opened this issue May 17, 2019 · 7 comments · Fixed by #2809
Closed

Implicitly closing tags aren't allowed before closing block #2807

mrkishi opened this issue May 17, 2019 · 7 comments · Fixed by #2809

Comments

@mrkishi
Copy link
Member

mrkishi commented May 17, 2019

Svelte supports implicitly closing tags like <li>first <li>second, but it won't allow them to be closed by a mustache closing block: https://svelte.dev/repl/733548506a2b44819e39157bd6a055d3.

I don't think this is intuitive and would expect svelte to either disallow it everywhere (even though it's valid html) or relax the mustache closing block rules (what I'd personally prefer).

@StevenWeathers
Copy link
Contributor

StevenWeathers commented May 18, 2019

I'll go ahead and be the negative nancy and say implicitly closing tags probably shouldn't be supported even if they are valid html, they would in my mind introduce complexity and make debugging harder.

Just my $0.02

@evdama
Copy link

evdama commented May 18, 2019

I'll go out on a limb here and would advocate the same as mrkishi. Keep it and make it work with mustaches as well. After all, less code is better https://svelte.dev/blog/write-less-code :)

@guojenman
Copy link

guojenman commented May 19, 2019

It's really hard to debug/maintain large trees where you have some unclosed tags. It often messes any closing tag highlighting help you get from IDEs as well. I'd rather have the compiler warn and throw early before it becomes a problem.

@teamore
Copy link

teamore commented Jan 16, 2022

While I understand that this feature might encourage some to write code which is difficult to debug/maintain, there are use cases where conditional opening and closing tags make sense in order to obey the DRY (Don´t Repeat Yourself) coding paradigm. Like this one:

{#if linkProvided}<a href={linkProvided}>{/if} <!-- some element --> {#if linkProvided}</a>{/if}

In order to archive conditional structures like the one above, you currently need to use redundant code, which is not elegant.

Imho, you should consider to add this feature despite the reasonable objections mentioned beforehand..

@mrkishi
Copy link
Member Author

mrkishi commented Jan 17, 2022

@teamore Unfortunately, that wouldn't be possible without major changes in how Svelte works, fundamentally. Svelte needs to understand the structure of the component statically, and the compiler works with the complete well-formed tree of tags.

While that example would indeed generate a valid tag in all cases if we were doing raw text templating, it would be impossible for the compiler to parse a valid and unique structure for arbitrary expressions and tree shapes.

@eunukasiko
Copy link

Is it still not possible in Svelte 4?

@Nazrinn
Copy link

Nazrinn commented Mar 19, 2024

This is breaking my whole workflow on creating menu items dynamically. I'm going to be forced to put my logic in the <script> instead of the HTML. Sucks.

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

Successfully merging a pull request may close this issue.

7 participants