A comprehensive demonstration of Svelte 5's revolutionary new features, built with modern tooling and beautiful UI. This project showcases the complete Svelte 5 ecosystem including Runes, Snippets, Enhanced State Management, Effects System, and Modern Event Handling.
This project serves as a learning resource for developers looking to understand the new paradigms introduced in Svelte 5, including the powerful Runes system, the new Snippets templating system, and advanced state management patterns.
Snippet<[ParamTypes]>
interfaceuntrack()
to access state without creating dependenciesonclick
syntax replacing on:click
Clone the repository
git clone https://github.com/Yuzu02/svelte5-showcase
cd svelte5-showcase
Install dependencies
bun install
Start the development server
bun run dev
Open your browser
Navigate to http://localhost:5173
to see the showcase in action.
# Development
bun run dev # Start development server with hot reload
bun run build # Build for production
bun run preview # Preview production build
# Quality Assurance
bun run check # Run type checking
bun run check:watch # Run type checking in watch mode
bun run lint # Run linter
bun run format # Format code with Prettier
bun run all # Run all checks (type, lint, format)
svelte5-showcase/
āāā src/
ā āāā lib/
ā ā āāā components/
ā ā ā āāā Card.svelte # Reusable card component with snippets
ā ā ā āāā RunesDemo.svelte # $state and $derived demonstrations
ā ā ā āāā SnippetsDemo.svelte # Snippets system showcase
ā ā ā āāā StateDemo.svelte # Advanced state management
ā ā ā āāā EffectsDemo.svelte # Effects system examples
ā ā ā āāā EventHandlerDemo.svelte # Modern event handling
ā ā āāā index.ts # Library exports
ā āāā routes/
ā ā āāā +layout.svelte # Root layout
ā ā āāā +page.svelte # Main showcase page
ā āāā app.css # Global styles
ā āāā app.d.ts # TypeScript declarations
ā āāā app.html # HTML template
āāā static/ # Static assets
āāā biome.jsonc # Biome configuration
āāā package.json # Dependencies and scripts
āāā svelte.config.js # Svelte configuration
āāā tailwind.config.js # Tailwind CSS configuration
āāā tsconfig.json # TypeScript configuration
āāā vite.config.ts # Vite configuration
Demonstrates the core reactive primitives:
$state
$derived.by()
Shows the powerful new templating system:
Advanced state patterns:
Side effect management:
Modern event handling patterns:
// ā
Good: Pure derived values
let doubled = $derived(count * 2);
let isEven = $derived(count % 2 === 0);
// ā
Good: Complex computations with $derived.by()
let stats = $derived.by(() => {
return heavyComputation(data);
});
// ā Avoid: Side effects in derived
let bad = $derived(count * Math.random()); // Don't do this!
// ā
Good: Deep reactive state
let profile = $state({
user: { name: 'Alice', preferences: { theme: 'dark' } }
});
// ā
Good: Raw state for non-reactive data
let config = $state.raw({ apiUrl: 'https://api.example.com' });
// ā
Good: Snapshots for history
const snapshot = $state.snapshot(profile);
// ā
Good: Effects with cleanup
$effect(() => {
const timer = setInterval(() => {
// Do something
}, 1000);
return () => clearInterval(timer);
});
// ā
Good: Pre-effects for DOM measurements
$effect.pre(() => {
const rect = element.getBoundingClientRect();
// Use measurements before DOM updates
});
<!-- ā
Good: Parameterized snippets -->
{#snippet card(title, content, variant = 'default')}
<div class="card card-{variant}">
<h3>{title}</h3>
<p>{content}</p>
</div>
{/snippet}
<!-- ā
Good: Passing snippets to components -->
<Card header={myHeader} content={myContent} />
<script lang="ts">
for TypeScript componentslet items: any[] = $state([])
import type { Snippet } from 'svelte'
onclick
instead of on:click
$effect
(use $derived
instead)untrack()
to access state without creating dependencies$state.raw
only triggers on reassignment$effect.pre
for DOM measurementsThis project demonstrates several important Svelte 5 concepts:
$state
and $derived
runes provide more explicit and powerful reactivityContributions are welcome! This project serves as a learning resource for the Svelte community.
git checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ā¤ļø using Svelte 5, SvelteKit, Bun, and Tailwind CSS
This project is maintained as a learning resource for the Svelte community. Star ā this repository if you find it helpful!