Skip to content

Add the {#component} logic block to put multiple components in one file #13637

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
Ocean-OS opened this issue Oct 17, 2024 · 3 comments
Closed

Comments

@Ocean-OS
Copy link
Contributor

Describe the problem

When working on large projects using Svelte, it can often become difficult to manage the amount of files due to the fact that Svelte only supports single-file components. Not to mention that most other frameworks support multiple components in a single file.

Describe the proposed solution

It would be very useful to add a {#component } block. This would separate components that are all stored in a single file. Here's an example:

{#component Counter}
<script>
let count = $state(0);
</script>
<button onclick={()=>count++}>Count is {count}</button>
{/component}
{#component Greeting}
<script>
let {name = "World"} = $props();
</script>
Hello, {name}!
{/component}

The {#component} block would be used to create multiple components in one file. The single parameter of the logic block is used to denote the name of the component.
Importing these components is quite simple, using destructuring:

<script>
import {Greeting, Counter} from "./Components.svelte"
</script>

This would also be very helpful for Svelte component libraries, as this would greatly decrease the file count of the library, which could also speed up installation and compile time.

Importance

would make my life easier

@Ocean-OS Ocean-OS changed the title Add the {#component} logic block to put multiple components in one file Add the {#component} logic block to put multiple components in one file Oct 17, 2024
@Ocean-OS
Copy link
Contributor Author

Please note that this is not a duplicate of sveltejs/kit#12944.

@7nik
Copy link
Contributor

7nik commented Oct 17, 2024

Please note that this is not a duplicate of sveltejs/kit#12944.

Because this is a duplicate of #2940.

@trueadm
Copy link
Contributor

trueadm commented Oct 17, 2024

Snippets provide a way of re-using content, and we've looked into this specifically in the past and tried it out. We universally agreed it wasn't right and caused far too many issues around things like scoped styles.

@trueadm trueadm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2024
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

No branches or pull requests

3 participants