Logo

dev-resources.site

for different kinds of informations.

Changelog 2024/48 aka We 🖤 Svelte 5

Published at
1/5/2025
Categories
svelte
releases
Author
nomodo-io
Categories
2 categories in total
svelte
open
releases
open
Author
9 person written this
nomodo-io
open
Changelog 2024/48 aka We 🖤 Svelte 5

We have rewritten our platform's frontend using Svelte 5, streamlining our workflow and refining our codebase to develop a more flexible and sustainable codebase. The following elements were notable.

What We Appreciate in Svelte 5

  1. Reusable Snippets Replacing Slots
  2. Callbacks Replacing Dispatchers
  3. Simplified Prop Handling with $props
  4. Improved Component Typing
  5. Explicit Reactivity with Runes
  6. Reduced Bundle Sizes

1. Reusable Snippets Replacing Slots

Svelte 5's new snippets system provides a powerful alternative to the slot-based system from Svelte 4. Where we previously used named slots with <svelte:fragment slot="name">, we now leverage the more flexible snippet syntax {#snippet name()}. This allows passing parameters to template fragments and maintaining reactivity, making complex UI patterns like recursive components and compound components more straightforward. Our modal and dropdown components benefit from this change, as content can be dynamically injected while preserving state and context.

<!-- Parent.svelte -->
<Card>
  <svelte:fragment slot="title">
    My Card Title
  </svelte:fragment>
  <svelte:fragment slot="content">
    Card content here
  </svelte:fragment>
</Card>

<!-- Card.svelte -->
<div class="card">
  <div class="title">
    <slot name="title" />
  </div>
  <div class="content">
    <slot name="content" />
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Svelte 4

<!-- Parent.svelte -->
<Card>
  {#snippet title()}
    My Card Title
  {/snippet}

  {#snippet content()}
    Card content here
  {/snippet}
</Card>

<!-- Card.svelte -->
<script>
  let { title, content } = $props();
</script>

<div class="card">
  <div class="title">
    {@render title()}
  </div>
  <div class="content">
    {@render content()}
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Svelte 5

2. Callbacks Replacing Dispatchers

Component communication is more straightforward with Svelte 5's approach to props and callbacks compared to event dispatchers. Where Svelte 4 required using createEventDispatcher pattern with dispatch('submit', { data }) and handling it with on:submit event listeners, Svelte 5 enables passing callback functions directly through props <Child onSubmit={handleSubmission} />. This reduces boilerplate, provides better TypeScript integration, and makes data flow more explicit throughout the application.

<!-- Child.svelte -->
<script>
  import { createEventDispatcher } from 'svelte';
  const dispatch = createEventDispatcher();

  function handleSubmit(data) {
    dispatch('submit', { data });
  }
</script>

<!-- Parent.svelte -->
<Child on:submit={({ detail }) => handleSubmission(detail.data)} />
Enter fullscreen mode Exit fullscreen mode

Svelte 4

<!-- Child.svelte -->
<script>
  let { onSubmit } = $props();

  function handleSubmit(data) {
    onSubmit?.(data);
  }
</script>

<!-- Parent.svelte -->
<Child onSubmit={handleSubmission} />
Enter fullscreen mode Exit fullscreen mode

Svelte 5

3. Simplified Prop Handling with $props

Svelte 5's $props rune brings a cleaner approach to component properties. The verbose export let syntax from Svelte 4 is replaced with a single destructuring statement let { prop1 = defaultValue, prop2 } = $props(). This approach significantly reduces code verbosity, improves TypeScript integration, significantly reduces prop-related boilerplate in components, and strengthens type checking.

4. Improved Component Typing

The typing improvements in Svelte 5 have been another standout feature for us. Built-in typed properties like placeholder and maxlength now function seamlessly, while custom traits can be defined with precision to ensure type safety. These enhancements have not only reduced the risk of runtime errors but have also made our code more robust and maintainable. Additionally, the deeper integration with TypeScript has significantly improved productivity and reliability.

5. Explicit Reactivity with Runes

Svelte 5's runes system represents a fundamental shift in reactivity management. Instead of Svelte 4's implicit reactivity with let declarations and $: statements, Svelte 5 uses explicit runes like $state() and $derived(). A typical example shows this evolution:

// Svelte 4
let count = 0;
$: tripled = count * 3;

// Svelte 5
let count = $state(0);
let tripled = $derived(count * 3);
Enter fullscreen mode Exit fullscreen mode

6. Reduced Bundle Sizes

The new compiler in Svelte 5 has brought significant optimisations, leading to bundle size reductions of up to 50% compared to Svelte 4. This efficiency boost not only improves performance but also aligns with our commitment to delivering a lightweight and fast platform.

A Worthwhile?

While adopting Svelte 5 and its new features—like snippets, callbacks, and runes—required some adjustments to our workflow, the results have been well worth the effort. The new features we’ve integrated have allowed us to create a cleaner, more scalable codebase. These changes are already helping us work more efficiently and will undoubtedly lead to fewer bugs and a smoother development experience in the long term.


To stay updated on what’s new at Nomodo, follow us on Twitter or join our Nomodo.io Discord channel. Also, don’t miss exploring MedusaJS.

From all of us at Nomodo.io, thank you for being part of our journey!

svelte Article's
30 articles in total
Favicon
🚀 I have released Eurlexa!!! EU Regulation at Your Fingertips!
Favicon
Building "Digital DSA": The Journey of Crafting a Smarter Loan Comparison Platform
Favicon
Tower defense clicker game built with Svelte 5, without canvas. Only CSS transitions and the power of Runes
Favicon
Optimize SvelteKit performance with brotli compression
Favicon
Migrating the VSCode theme generator to oklch
Favicon
Beatbump: Exploring Svelte Best Practices for Dynamic Web Applications
Favicon
SvelteJs vs ReactJs : But both can co-exists!
Favicon
Build a Simple Chatbot with Svelte and ElizaBot
Favicon
A minimalist password manager desktop app: a foray into Golang's Wails framework (Part 2)
Favicon
The Perfect Trio: Wails, Go & Svelte in Action
Favicon
Svelte 5: Share state between components (for Dummies)
Favicon
Integrating SvelteKit with Storyblok (Using Svelte 5)
Favicon
Changelog 2024/48 aka We 🖤 Svelte 5
Favicon
My first Micro SaaS | Automated, SEO-friendly Changelogs
Favicon
Quit Using Anonymous Functions in Props!
Favicon
From Svelte 4 to Svelte 5: Understanding Slots (default and named)
Favicon
Make EditorJS work in Svelte(kit) SSR
Favicon
Shadcn UI Theme generator, with OKLCH colors and ancient sacred geometry.
Favicon
A short guide to Async Components in Svelte 5
Favicon
New Post here!🍻
Favicon
Svelte vs Vue: Choosing the Best Front-End Framework
Favicon
Step-by-Step Tutorial: How to Use ALLAIS for Effortless UI Generation
Favicon
Schritt-für-Schritt-Anleitung: So verwenden Sie ALLAIS für die einfache UI-Generierung
Favicon
ALLAIS: Your Ultimate Personal UI Generator for Modern Web Development
Favicon
Пошаговый учебник: Как использовать ALLAIS для легкой генерации UI
Favicon
Svelte
Favicon
A minimalist password manager desktop app: a foray into Golang's Wails framework (Part 1)
Favicon
When Goliath Fell to David’s Smallest Stone: The Innocent Dropdown Tweak That Shattered React, Vue, and Svelte
Favicon
Deploying Your SvelteKit App to GitHub Pages with a Custom Domain (Ditch GoDaddy for Porkbun)
Favicon
Syncing DOM State and Data without IDs

Featured ones: