You have a Svelte component running on the development server with Hot Module Replacement (HMR) enabled. You change the text inside the component and save the file.
What is the expected behavior in the browser?
<script> let count = 0; </script> <button on:click={() => count++}> Clicked {count} times </button>
Think about what Hot Module Replacement means for state and UI updates.
With HMR enabled, Svelte updates only the changed component in the browser without a full page reload. This preserves the component's state like the count variable.
You want to start a Svelte project development server that supports Hot Module Replacement.
Which command should you run?
Check the default scripts in a Svelte project created with Vite.
In a Svelte project using Vite, the npm run dev command starts the development server with HMR enabled by default.
You edit a Svelte component and save it, but the browser does not reflect the changes. The development server is running.
What is the most likely cause?
Consider the role of HMR in live updates.
If HMR is disabled or not set up correctly, saving changes won't update the component live. The development server may still run, but no hot updates occur.
Consider a Svelte component with a counter state. You increment the counter to 5, then save a code change with HMR enabled.
What is the value of the counter after the update?
<script> let count = 0; </script> <button on:click={() => count++}> Count: {count} </button>
Think about how HMR handles component state during updates.
Svelte's HMR preserves the component's local state during updates, so the counter stays at 5 after saving changes.
Choose the statement that correctly explains how the development server and Hot Module Replacement work together in a Svelte project.
Consider how live updates happen without full reloads.
The development server watches for file changes and recompiles only the changed modules. HMR then injects these updates into the running app, preserving the app state and avoiding full reloads.