Replies: 1 comment
-
While this perspective is valid, it overlooks the foundational principles of Svelte. Quick Recap: What is Svelte's design philosophy?
The idea of treating Snippets as anonymous components is conceptually valid—but the proposed syntax change introduces ambiguity, runtime overhead, and architectural misalignment. Svelte’s strength lies in its compiler-driven model, which favors explicitness, static guarantees, and minimal syntax. Walk with me for a moment.. if we preserve
These are not abstract ideals—they are backed by compiler internals, performance benchmarks, and then there is always the "cognitive science" part of the equation on code comprehension and it's own scalability implications. You're absolutely right to notice that Svelte 5 snippets resemble anonymous components—but that’s precisely the point. Snippets aren’t meant to replicate components; they’re designed to solve a different architectural concern: composability without fragmentation. In architecture design, choosing a framework isn’t just about syntax—it’s about how it handles component composition at scale. React’s slot model relies on children, render props, and context, which often leads to deeply nested trees and scattered logic. Svelte 5 snippets, by contrast, offer inline, recursive, and parameterized composition with SSR safety and zero hydration overhead. Treating snippets as components would reintroduce the very complexity Svelte was designed to avoid. Instead, snippets let you co-locate logic, reduce boilerplate, and maintain closure-like behavior—all within a single file. That’s not a limitation—it’s a strategic advantage. The way I see it is: When designing frontend architectures, understanding composition implications will serve as a valuable guide in your architecture toolbox, helping you navigate component composition decisions amidst the ever-growing list of architectural considerations will prove to be invaluable. Let data-driven decisions guide you when navigating technology choices! So having a healthy, open, discussions exactly like this is huge for anything that stands a chance in our world driven by the proliferation of technology. So bravo @LaneSun for this post! For anybody interested I carved out a post on this topic so I wouldn't use discussions as my new soap box 🤣. It lives here for now: https://www.notion.so/Component-Composition-Svelte-5-vs-React-24dd7342e5718058aa7ffc068bfb8d71. As usual, ping me if you have questions or concerns--or just want to hack! 🤜 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
After upgrading to Svelte 5, I’ve had this lingering thought about the implementation of Snippets that feels a bit odd.
Snippets are powerful, and I understand they are the successor to Slots. I didn’t have this feeling during the Slot era because Slots were relatively simple in functionality—too limited to make me overthink things (once again, kudos to the team for their amazing work).
Back to the main point: when using Snippets, their flexibility often makes me wonder—isn’t this just an anonymous Component?
Take the following code as an example:
Why not replace it with this form:
From my perspective, a Snippet that accepts an object as its argument is structurally consistent with a regular Component. It feels similar to the difference between arrow functions and regular functions in JavaScript—I believe the two could share the same design. This way, Snippets would gain Component-like features such as richer parameter passing, better control over reactivity, type safety, and more.
We could also introduce a new syntax for Snippets to make them visually identical to Components:
This would then be compiled into an anonymous Component and bundled with the parent Component.
I think this approach could significantly reduce the number of Component files—for example,
scrollbar-root.svelte
,scrollbar-handler.svelte
,scrollbar-tracker.svelte
, etc., could all be consolidated into a single.svelte
file!They could even detect closures to automatically generate certain reactive bindings, reducing boilerplate code when developing "large components" (cases where multiple components are used together) for passing contextual information.
Additionally, if the above proposal could be implemented, I believe the following idea would naturally follow:
Namely, allowing Snippets to be embedded directly into JavaScript.
Consider the role of JavaScript’s
let/const
keywords and{@const ...}
in our framework—wherelet/const
are the prototypes, and{@const ...}
serves as a supplement to achieve similar functionality in HTML.Ultimately, I think Snippets will follow the same path—where
$snippet(...)
in JavaScript becomes the primary form, and{#snippet}
in HTML acts as a supplement.If this could be realized, we would achieve first-class language-level Component facilities within the Svelte framework. This would completely overturn previous debates about defining multiple script blocks in a single file and eliminate React’s biggest advantage over Svelte—the syntactic consistency and closure-like behavior enabled by JSX.
Of course, my understanding of Svelte may not be deep enough, and my arguments might not hold water. But in any case, this is my personal perspective—one that might guide Svelte toward a more elegant and powerful future.
Beta Was this translation helpful? Give feedback.
All reactions