Surprise! Svelte Secretly Sending Signals

This ad is not shown to multipass and full ticket holders
React Advanced
React Advanced 2025
November 27 - 1, 2025
London, UK & Online
We will be diving deep
Learn More
In partnership with Focus Reactive
Upcoming event
React Advanced 2025
React Advanced 2025
November 27 - 1, 2025. London, UK & Online
Learn more
Bookmark
Rate this content

Svelte 5 introduced runes which use signals under the hood. While signals are very cool and unlock a ton of composability possibilities they have their own gotchas... let's explore them while creating a reactive signal based system from scratch to really understand them from the base!

This talk has been presented at JSNation 2025, check out the latest edition of this JavaScript Conference.

FAQ

The speaker is Paolo Ricciuti, a Svelte ambassador and maintainer from Campobasso, Italy.

Paolo Ricciuti works as a senior software engineer, where he teaches and works with Svelte, participates in team augmentation, and organizes workshops.

The main topic of the talk is the implementation of reactivity in Svelte, particularly how signals are used to manage state and updates.

The writable store in Svelte is used to manage state with reactivity, using the observer pattern to notify subscribers when the state changes.

The proxy API allows interjecting operations on objects, simplifying state management by avoiding the need for explicit subscriptions for every state change.

Challenges include managing dependencies, cleaning up memory to avoid leaks, and handling asynchronous operations within effects.

Local storage can be used to persist state across page reloads. It is advised to synchronize local storage updates directly within state setting functions rather than using effects.

If the TC39 proposal for signals is adopted, it may reduce the need for custom implementations, though frameworks will still need to implement specific effects.

One complexity is handling unknown derived states, which require careful memory management to prevent leaks, especially when signals are used outside components.

The Svelte team is exploring experimental solutions to handle asynchronous functions within components, though challenges remain with async operations affecting reactivity.

Paolo Ricciuti
Paolo Ricciuti
28 min
12 Jun, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Welcome to a talk on Surprise! Svelte Secretly Sending Signals by Paolo Ricciuti showcasing live coding with a demo of reactivity in Svelte using writable stores and the proxy API. The proxy API in Svelte allows for intercepting object operations to enhance reactivity. Efficient state management, event handling, and dependency management are key topics discussed. Strategies for managing dependencies, handling current and actual effects, clearing sets, scheduling functions efficiently, and handling signal memory cleanup in Svelte are covered. The talk also addresses signal-based frameworks, async issue solutions, and alternative approaches like Solid for handling signals sequentially.

1. Introduction to Svelte Reactivity and Proxy API

Short description:

Welcome to a talk on Surprise! Svelte Secretly Sending Signals by Paolo Ricciuti from Campobasso, Italy. He is a Svelte ambassador and maintainer, a senior software engineer, and offers team augmentation services. Paolo showcases live coding with a demo of reactivity in Svelte using writable stores and introduces the proxy API.

Welcome, everyone, to my talk. It's called Surprise! Svelte Secretly Sending Signals. Before we begin, a small presentation is due. Who am I? I am Paolo Ricciuti. I come from Campobasso, Italy, the land of pizza. And you can find me on BlueSky as paolo.ricciuti.me or on GitHub as Paolo Ricciuti. I'm a Svelte ambassador and a Svelte maintainer, and I work as a senior software engineer at is super cool, because I get to work with Svelte but also to teach Svelte, both at meetups and conferences, just like this one, but also in my day-to-day job because we do what's called team augmentation, which means that we join your team, we help you hire, we teach you Svelte and best practice. We even do workshops. So if you want, you can scan this QR code and also get JS Nation 25 code for 25% off. And we also have a subscription API, not API service, so that if you don't have a full-blown project, you basically get access to our expertise, like, in Slack, and you can basically, like, ask us to review a code and stuff like that.

But it's demo time, because this will actually be 100% live coded, because apparently I hate myself. So let's switch to VS Code, where we are met with the most useless demo. It's a counter that doesn't work unless you keep the party going. And then you can, like, type here, and it will update on top. But the interesting bit is how everything is wired. So this is wired with the old way of doing reactivity in JavaScript files in Svelte, which is with a writable store. The writable store is basically the observer pattern, and you can see an implementation here. It's, like, 20 lines of code. And how you use it is also very simple. Like, you just declare the writable state, and you can subscribe to it, and this function will be invoked whenever the state changes. And then, like, this is a vanilla project, so you are wiring up the button, click listener, and this is how you update the state, which is...

But let's look at the implementation. So you pass an initial value, you store the value here, and then you have a set of subscriber, and here, a set is just a fancy array with no repetitions. And then you have a subscribe function that take a function as input, store it in the subscriber, invoke it with the current value, and then return a function to unsubscribe. Then you have the set function that just, like, sets the new value, like, the value to the new value, and then loop over every subscriber and call the function with the value. The update function is even easier because it's just calling the set function. And the value that you are passing in is this get new value function. Now, as you can see, like, using the store, the writables, is not really pretty. And Svelte is famous for its vibe, like, we want to do stuff simpler. So allow me to introduce you to the proxy API.

2. Enhancing Reactivity with Proxy API in Svelte

Short description:

The proxy API in Svelte allows for intercepting object operations using traps like get and set. By using proxies, you can implement side effects and enhance reactivity in your objects.

So I can do const P is equal a new proxy. The proxy API is very simple, and basically, you get an object like this, and then the second argument is actually a series of traps. And just like a network proxy where you can interject a request, you can basically interject operations on your object. For example, there is the get trap, and the get trap, you get the target and the key that you are trying to access. And you can return target at key for target at key for the default value. But you can also add, I don't know, console.log getting key. And if you do this, and I need something here. If you do this, and if I try to do console.log p.name, and if I save, you can see that in this case, I'm getting the value, which is Paolo, and I'm getting name, which is a sort of side effect. But what we are really interested in is the set function. So you can get a target, the key, and the value. And obviously, you can get the default behavior with target at key is equal to value. You need to return true, otherwise, you will get an error. But even here, you can do some side effect, basically. So if I save, and if I do p.name is equal to JS nation, and I save, you can see that we are getting setting name, JS nation, and then we are getting the actual value. So basically, we can replace these with our set function. And so instead of returning this object, we can do return new proxy.

Now, we need to pass in an object in this case. So we cannot pass literal values anymore. In Svelte, we don't have this limitation because it's a compiler. So I can remove this because since it's an object, the user can just access the object directly since it's a reference. And here I can basically do set, I get the target, I get the key, I get the value, and then I can basically do the same thing that I was doing here. So I can basically set the target at key equal to value to update the value. I need to return true as I've saved. And then we can just call our list of subscribers, the function again. So obviously, you may notice now we have a problem because we don't have a way to subscribe to it. So for the moment, let's do something dirty and let's return a tuple. And the first argument will be our subscribe function. So basically, I can do exactly this inside this function. And obviously, I don't need the value anymore because it's not there. Now, we can update our code now so we can remove all of these.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
The Talk discusses the shift to full-stack frameworks and the challenges of full-stack documentation. It highlights the power of interactive tutorials and the importance of user testing in software development. The Talk also introduces learn.svelte.dev, a platform for learning full-stack tools, and discusses the roadmap for SvelteKit and its documentation.
Svelte 5: North Star
JSNation US 2024JSNation US 2024
29 min
Svelte 5: North Star
Top Content
As a child, the speaker was fascinated with space and finding direction. Svelte is an HTML-first approach to web development that simplifies tasks and offers efficient reactivity. The speaker reflects on Svelte's growth, goals, and design philosophy. Svelte aims to fix broken software and prioritize user focus. The future direction includes error boundaries, better debugging, and AI's role. Building open source software is challenging, and Rust's impact is discussed. The speaker values framework diversity and highlights the advancements and challenges faced by web development.
The Wind and the Waves: The formation of Framework Waves from the Epicenter
JSNation 2022JSNation 2022
19 min
The Wind and the Waves: The formation of Framework Waves from the Epicenter
Top Content
Our understanding of innovation is wrong. Innovations are not introduced by a single point of light. The story of who invented the computer is not linear. Many steps forward led to the development of the computer. Angular has shaped and influenced multiple JavaScript waves, and Angular v14 simplifies development with standalone components.
Progressive Enhancement - What It Is and Isn’t, a Practical Introduction With Svelte
JSNation 2023JSNation 2023
20 min
Progressive Enhancement - What It Is and Isn’t, a Practical Introduction With Svelte
Progressive enhancement is a strategy that provides a baseline experience for all users while enhancing it for those with modern browsers. Feature detection and graceful degradation are complementary approaches to achieve this. Polyfills can emulate new browser functionality in old browsers. Progressive enhancement is about meeting user needs while considering performance. Building apps in SvelteKit allows for easy development of progressively enhanced apps. Svelte components and DOM content provide a convenient way to structure and update the UI. Form submission and progressive enhancement can be achieved by enabling file upload and processing when JavaScript is disabled.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Workshop
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
JSNation 2023JSNation 2023
174 min
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
Top Content
WorkshopFree
Alba Silvente Fuentes
Roberto Butti
2 authors
This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.
Building with SvelteKit and GraphQL
JSNation 2022JSNation 2022
170 min
Building with SvelteKit and GraphQL
Workshop
Scott Spence
Scott Spence
Want to get familiar with the framework that took the top spot for most loved framework on the Stack Overflow developer survey in 2021?Svelte is a super versatile framework with no virtual dom unlike React and Vue, it's a compiler that builds your projects into vanilla HTML, CSS and JavaScript.This workshop will go over the basics of setting up with SvelteKit and querying data from a GraphQL API and using that data in SvelteKit to retrieve data for use in the client (browser).Key learnings:How to use SvelteKit to build a simple project retrieve data from a GraphQL API and display it in the client. Many of the core concepts of Svelte and SvelteKit will be covered in this workshop.
Build Full Featured Frontend App with Svelte
React Summit 2020React Summit 2020
192 min
Build Full Featured Frontend App with Svelte
Workshop
Mikhail Kuznetsov
Mikhail Kuznetsov
Svelte is a new prominent JS framework exposing “write less do more” philosophy. During this workshop you will get proficiency as a Svelte developer. We will be building an app that mimics the famous Q&A website stackoverflow.com. Will start developing from simple front end components, later we'll connect it to a real running backend and then test it and optimise for production.Attending a workshop is the fastest way to acquire a body of knowledge about building web apps with Svelte.