Part 19 of a series on Svelte in 2026. Part 18 traced a running SvelteKit app. This part steps back from SvelteKit and puts one component next to its React twin.
Every earlier part compared one idea with React: a counter, a derived value, an effect, a prop. That’s fair to each idea and unfair to both frameworks, because nobody ships a counter. So for this part I wrote one ordinary component twice and counted what ran.
It’s a packing list. You type an item and add it, tick items off as you pack them, see “3 of 7 packed”, hide what’s already packed, and remove things you changed your mind about. Two components in each version: the list, and a row. I loaded each production build with 100 items in Chromium and put a counter at the top of every component function.
Checking one item off ran 101 component functions in React: the list, then all 100 rows. With the React Compiler turned on it was still 101. In Svelte it was zero. Getting React down to two took three changes, and the reason it took them is the most useful thing I learned from the exercise.
The lab ran Svelte 5.57.3, React 19.3.1 and babel-plugin-react-compiler 1.0.0, all built with Vite 8.3.5 and driven by Playwright 1.64.1.
The Svelte version
<script lang="ts"> import PackingItem from "./PackingItem.svelte"; import { seed } from "./seed";
let items = $state(seed()); let draft = $state(""); let hidePacked = $state(false);
let packed = $derived(items.filter((i) => i.packed).length); let shown = $derived(hidePacked ? items.filter((i) => !i.packed) : items);
function add(event: SubmitEvent) { event.preventDefault(); const name = draft.trim(); if (!name) return; items.push({ id: Date.now(), name, packed: false }); draft = ""; }
function remove(id: number) { items = items.filter((i) => i.id !== id); }</script>
<form onsubmit={add}> <input bind:value={draft} placeholder="Add an item" /> <button disabled={!draft.trim()}>Add</button></form>
<p>{packed} of {items.length} packed</p><label><input type="checkbox" bind:checked={hidePacked} /> Hide packed</label>
<ul> {#each shown as item (item.id)} <PackingItem {item} ontoggle={() => (item.packed = !item.packed)} onremove={() => remove(item.id)} /> {/each}</ul>
<style> ul { list-style: none; padding: 0; }</style>PackingItem.svelte takes item, ontoggle and onremove as props and renders an <li> with a checkbox, the name and a remove button, plus a scoped .packed style that strikes the name through.
Nothing in there would surprise someone who read parts 3 to 6. items.push(...) is the whole update, because $state made the array a deep proxy. packed and shown say what they are and never list what they read. Ticking a box flips one property on one object, and the row’s class and the count are the only two things on the page that read it.
The React version
import { useState, type FormEvent } from "react";import { PackingItem } from "./PackingItem";import { seed } from "./seed";
export function PackingList() { const [items, setItems] = useState(seed); const [draft, setDraft] = useState(""); const [hidePacked, setHidePacked] = useState(false);
const packed = items.filter((i) => i.packed).length; const shown = hidePacked ? items.filter((i) => !i.packed) : items;
function add(event: FormEvent) { event.preventDefault(); const name = draft.trim(); if (!name) return; setItems([...items, { id: Date.now(), name, packed: false }]); setDraft(""); }
function toggle(id: number) { setItems(items.map((i) => (i.id === id ? { ...i, packed: !i.packed } : i))); }
function remove(id: number) { setItems(items.filter((i) => i.id !== id)); }
return ( <> <form onSubmit={add}> <input value={draft} onChange={(e) => setDraft(e.target.value)} placeholder="Add an item" /> <button disabled={!draft.trim()}>Add</button> </form>
<p> {packed} of {items.length} packed </p> <label> <input type="checkbox" checked={hidePacked} onChange={(e) => setHidePacked(e.target.checked)} />{" "} Hide packed </label>
<ul className="list"> {shown.map((item) => ( <PackingItem key={item.id} item={item} onToggle={() => toggle(item.id)} onRemove={() => remove(item.id)} /> ))} </ul> </> );}The row is the same shape as Svelte’s, with its .packed class coming from a CSS Module, since React has no scoped styles of its own (part 11 covered that).
This is the code I’d write without thinking about performance, and I think most React developers would too. It’s longer: formatted by Prettier, Svelte’s two files came to 61 non-blank lines and React’s three to 76, before the list got any styles. Most of the gap is toggle: in React you build a new array with a new object in it, while Svelte assigns to item.packed.
The bundles differ more than the source does. Svelte’s build was 17.2 kB gzipped and React’s 69.4 kB, 70.3 kB with the Compiler. Part 2 explains where that comes from; it’s mostly React’s fixed runtime, not this component.
What ran when one thing changed
- React, as written
- 101 (list + 100 rows)
- React + Compiler
- 101 (list + 100 rows)
- React + Compiler, reshaped, memo()
- 2 (list + 1 row)
- Svelte
- 0
- What to notice
- The Compiler alone didn't help: toggle() reads items, so every row got a new onToggle and missed its cache.
- React, as written
- 101 (list + 100 rows)
- React + Compiler
- 1 (list)
- React + Compiler, reshaped, memo()
- 1 (list)
- Svelte
- 0
- What to notice
- The case the Compiler is built for. The rows' JSX didn't depend on draft, so it was reused.
- React, as written
- 102 (list + 101 rows)
- React + Compiler
- 102 (list + 101 rows)
- React + Compiler, reshaped, memo()
- 2 (list + the new row)
- Svelte
- 1 (the new row)
- What to notice
- Svelte's 1 is the new PackingItem being created. Nothing else ran.
- React, as written
- 101 (list + 100 rows)
- React + Compiler
- 101 (list + 100 rows)
- React + Compiler, reshaped, memo()
- 1 (list)
- Svelte
- 0
- What to notice
- Hiding one packed row means removing one <li>. Svelte's keyed each block did only that.
- React, as written
- 101 (list + 100 rows)
- React + Compiler
- 101 (list + 100 rows)
- React + Compiler, reshaped, memo()
- 1 (list)
- Svelte
- 0
- What to notice
- Same story as hiding: one row leaves, and only the reshaped React version left the others alone.
The plain React column is React’s model working as documented: state changed in PackingList, so PackingList ran again, and so did every child it rendered. Typing one letter into the “add” box ran 100 row functions that had nothing to do with the draft.
The React Compiler fixed exactly that case. It memoized the mapped rows on shown, toggle and remove, none of which change while you type, so the list ran once and the rows not at all. That’s the “skipping cascading re-rendering” the Compiler docs promise.1
Checking an item off was still 101, and I had to read the compiled output to see why. toggle reads items, so the Compiler rebuilt it whenever items changed, and so it rebuilt every () => toggle(item.id) arrow, so every row got a new onToggle prop and missed its cache. The docs walk through a similar list and say the Compiler handles it “with or without the arrow function”. That held in my lab while I typed, when the parent re-rendered for an unrelated reason. When the array itself changes, as it does every time you tick a box, every arrow is new.
Getting down to two took three changes:
setItems((items) => items.map(...)), the updater form, sotoggleno longer readsitemsand stays the same function.- Pass
toggleitself to the row, which callsonToggle(item.id), instead of a fresh arrow per row. - Wrap the row in
memo().
With the first two and no memo(), the row functions still ran 100 times, but each one hit its compiled cache and returned its old JSX. That’s cheaper than a real re-render without being free. Without the Compiler, memo() alone did nothing, since toggle was a new function on every render.
Does any of that matter? At 100 items, no. I timed one keystroke and one toggle, from the event to the next task (JavaScript and DOM updates, not paint), and every version stayed under half a millisecond. At 5,000 items, plain React spent about 14 ms per keystroke and 17 ms per toggle, which is most of a 60 Hz frame. The Compiler took the keystroke to 0.1 ms and left the toggle at 17. The reshaped version with the cache hits and no memo() toggled in 3.6 ms; with memo(), 1.3 ms. Svelte, as written, did both in about 0.1 and 2 ms.
Svelte lost that last one. Its 2 ms is the packed count re-running over 5,000 items. The memoized React version re-counts the same 5,000, so my guess is the difference is reading through Svelte’s proxies instead of plain objects; I didn’t profile it.
Where the Svelte version bit me
My first Svelte row didn’t take an ontoggle callback. It did this:
<input type="checkbox" bind:checked={item.packed} />That’s two fewer props, and it works: the box ticks, and the count updates. In dev, it also logged ownership_invalid_mutation: “Mutating unbound props (item, …) is strongly discouraged.” Svelte suggests bind:item in the parent, or a callback.
I tried bind:item first, and that didn’t compile: each_item_invalid_assignment, because you can’t bind to the item of an {#each} in runes mode. Binding through an index would need items[i], and I was iterating over shown, a filtered copy. So I wrote the callback, and the Svelte row ended up looking like the React row: a prop for the data and a function to call when it should change.
That’s the honest shape of Svelte’s shortcut. Mutation is the easy path inside the component that owns the state, and Svelte asks you to stop at the component boundary. React never lets you start, since setItems with a new array is the only way to change anything, and that’s exactly why memo() can trust a shallow compare: a row’s item is a different object if and only if it changed.
Where React’s version is better
It’s all JavaScript. shown.map(...) is a call you already know, PackingItem could live in the same file as the list if I wanted, and TypeScript checks every expression in the markup without a language server that understands a template syntax. Svelte has snippets for the “small thing in the same file” case and svelte-check for the types, and both are good, but they’re Svelte’s to learn.
The rest is the reason part 1 gave: React is used by 85% of State of JS 2025 respondents against Svelte’s 27.5%.2 Every library you’ll need has a React version first, and every developer you hire has written useState. A packing list doesn’t change that.
What I’d take from it
Svelte’s version was shorter and did the least work without my thinking about it. React’s version did more, and the Compiler took care of half of that for free; the other half needed me to know how the Compiler caches, which is the thing it was supposed to save me from knowing. That’s the real difference, more than the line count: in Svelte the fast version is the version you write first, and in React it’s a version you can reach.
At 100 items, though, nobody will feel any of this. Pick on the other grounds: the team, the libraries, the hiring pool. The verdict on those is part 22’s job.
Next: building a component library in Svelte.
The next parts aren’t out yet — check back soon.
Footnotes
-
React docs, Introduction to React Compiler, “What does React Compiler do?” and the
ExpensiveComponentexample. ↩ -
State of JS 2025: Front-end frameworks, usage figures pulled from the Devographics API as described in part 1. The runes announcement covers why Svelte 5 moved to signals in the first place. ↩

