0
0
Svelteframework~10 mins

Development server and HMR in Svelte - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Development server and HMR
Start Development Server
Server Serves Files
Browser Loads App
Detect File Change
Send Update via HMR
Browser Applies Update
App Updates Without Full Reload
Repeat
The development server runs and serves your app. When you change code, it sends updates to the browser using HMR, so the app updates instantly without reloading.
Execution Sample
Svelte
npm run dev
// Server starts
// Edit src/App.svelte
// Save file
// Browser updates component instantly
Starts the Svelte development server with HMR enabled, so changes in code update the app live in the browser.
Execution Table
StepActionServer StateBrowser StateResult
1Run 'npm run dev'Server starts, listens for changesBrowser loads app first timeApp visible in browser
2Edit src/App.svelteDetects file changeWaiting for updateNo visible change yet
3Save fileSends HMR update to browserReceives updatePartial app update triggered
4Apply updateIdle, waiting for next changeComponent updates without full reloadUI updates instantly
5No more changesIdleApp stableWaiting for next edit
💡 No exit; server and HMR run continuously during development
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
serverStatusstoppedrunningsending updateidleidle
browserAppStatenot loadedloadedreceiving updateupdatedstable
fileChangeDetectedfalsetruetruefalsefalse
Key Moments - 2 Insights
Why doesn't the browser do a full reload after I save a file?
Because the development server uses HMR to send only the changed parts, the browser updates the app without reloading the whole page, as shown in step 4 of the execution table.
What happens if I don't save the file after editing?
The server won't detect any change, so no update is sent. The browser stays the same, as seen between steps 1 and 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the server state right after saving the file?
ASending update
BIdle
CStopped
DDetecting file change
💡 Hint
Check Step 3 in the execution table under 'Server State'
At which step does the browser apply the update without a full reload?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Result' column in the execution table for Step 4
If the fileChangeDetected variable stays false, what happens?
AThe browser updates automatically
BNo updates are sent or applied
CThe server sends updates anyway
DThe server restarts
💡 Hint
Refer to variable_tracker row 'fileChangeDetected' and execution_table steps 1-2
Concept Snapshot
Run 'npm run dev' to start the Svelte development server.
The server watches your files for changes.
When you save, it sends updates via HMR.
The browser updates only changed parts, no full reload.
This makes development fast and smooth.
Full Transcript
Starting the Svelte development server runs a local server that serves your app and watches your files. When you edit and save a file, the server detects the change and sends a hot module replacement (HMR) update to the browser. The browser applies this update instantly, refreshing only the changed parts of the app without reloading the whole page. This process repeats as you continue editing, making development fast and interactive.