Skip to content

breaking: treat special elements that never have content as void elements #11245

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

Closed
wants to merge 2 commits into from

Conversation

jrmajor
Copy link
Contributor

@jrmajor jrmajor commented Apr 19, 2024

Since we already know that self-closing tags are not cool, we don't want to write <svelte:options />, and instead have to do <svelte:options></svelte:options>. These elements can never have content anyway, so with these changes, we will be able to just write <svelte:options>

<svelte:options>

<!-- no longer valid -->
<svelte:options></svelte:options>
<svelte:options>this was ignored anyway</svelte:options>
<!-- still valid -->
<svelte:options />
<!-- invalid before -->
<svelte:options>

<svelte:window>, <svelte:document>, <svelte:body>

If there was content inside, compiler would throw invalid-element-content error. Now it will throw invalid-void-content.

<!-- no longer valid -->
<svelte:window></svelte:window>
<!-- still valid -->
<svelte:window />
<!-- invalid before -->
<svelte:window>

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Apr 19, 2024

🦋 Changeset detected

Latest commit: 54ab321

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

I definitely get where your head's at but I don't think we should make this change. Void elements are a concept specific to HTML, and extending it to <svelte:...> components adds learning curve and introduces tricky questions:

  • if we treat these elements as HTML, then <svelte:component this={Foo} /> would cease to be valid, unless we make things inconsistent
  • if we decide that <svelte:component this={Foo} /> should be invalid for the sake of consistency, then what about <Foo />?
  • if Foo.svelte doesn't contain {@render someprop()} then it too could be considered 'void' — should it be treated as such?

Much better to keep the quirks of HTML confined, in my view. But if none of those arguments are persuasive, then consider the behaviour of most IDEs:

Screen.Recording.2024-04-19.at.11.36.24.AM.mov

@dummdidumm
Copy link
Member

I stand by my point in #11224 (comment) and also think we should not do this (neither the other PR)

@jrmajor
Copy link
Contributor Author

jrmajor commented Apr 19, 2024

I thought we do treat svelte: elements like HTML. If we don't, then it all makes sense :)

Closing this and #11244. Thanks for the reply!

@jrmajor jrmajor closed this Apr 19, 2024
@jrmajor jrmajor deleted the void-special-elements branch April 20, 2024 07:01
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 this pull request may close these issues.

3 participants