0
0
Svelteframework~20 mins

Development server and HMR in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte HMR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you save a Svelte component during development?

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?

Svelte
<script>
  let count = 0;
</script>
<button on:click={() => count++}>
  Clicked {count} times
</button>
AOnly the changed component updates in the browser, preserving the count state.
BThe browser reloads the entire page, resetting the count to zero.
CThe browser shows an error because HMR is not supported in Svelte.
DThe component does not update until you manually refresh the browser.
Attempts:
2 left
💡 Hint

Think about what Hot Module Replacement means for state and UI updates.

📝 Syntax
intermediate
1:30remaining
Which command starts the Svelte development server with HMR enabled?

You want to start a Svelte project development server that supports Hot Module Replacement.

Which command should you run?

Anpm run build
Bnpm start
Csvelte-hmr serve
Dnpm run dev
Attempts:
2 left
💡 Hint

Check the default scripts in a Svelte project created with Vite.

🔧 Debug
advanced
2:00remaining
Why does the Svelte component not update after saving changes during development?

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?

AThe browser cache is preventing updates; you need to clear it manually.
BThe development server crashed and needs to be restarted.
CHMR is disabled or misconfigured in the project setup.
DSvelte components require a full page reload to update during development.
Attempts:
2 left
💡 Hint

Consider the role of HMR in live updates.

state_output
advanced
2:00remaining
What happens to component state during HMR in Svelte?

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?

Svelte
<script>
  let count = 0;
</script>
<button on:click={() => count++}>
  Count: {count}
</button>
AThe counter resets to 0 because the component reloads fully.
BThe counter remains at 5 because HMR preserves component state.
CThe counter value becomes undefined due to state loss.
DThe counter increments automatically by 1 after update.
Attempts:
2 left
💡 Hint

Think about how HMR handles component state during updates.

🧠 Conceptual
expert
2:30remaining
Which statement best describes the role of the development server in Svelte with HMR?

Choose the statement that correctly explains how the development server and Hot Module Replacement work together in a Svelte project.

AThe development server watches files, recompiles changed modules, and HMR injects updates into the running app preserving state.
BThe development server disables caching and forces full reloads on every file save to simulate HMR.
CThe development server only serves the app; HMR is handled by the browser independently without recompilation.
DThe development server compiles Svelte code once and serves static files; HMR reloads the entire page on changes.
Attempts:
2 left
💡 Hint

Consider how live updates happen without full reloads.