vite-hmr

Explain Vite HMR API usage, module disposal, and React Fast Refresh integration.

8|2|Updated Jan 15, 2026
One-click install
npx skills add https://github.com/bradtaylorsf/alphaagent-team --skill vite-hmr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vite-hmr
Source: https://github.com/bradtaylorsf/alphaagent-team/tree/main/plugins/aai-stack-vite/skills/vite-hmr
Command: npx skills add https://github.com/bradtaylorsf/alphaagent-team --skill vite-hmr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers understand and leverage Vite's Hot Module Replacement (HMR) capabilities to achieve faster development cycles with instant feedback without full page reloads.

Core Features & Use Cases

  • HMR API Usage: Learn how to accept updates, dispose of old modules, and handle state preservation.
  • React Fast Refresh: Understand how HMR integrates with React for seamless component updates.
  • Debugging: Discover techniques for verbose logging and monitoring HMR events.
  • Use Case: When making changes to a React component, HMR allows you to see the update instantly in the browser without losing the component's current state (like a form input value or a counter).

Quick Start

Use the vite-hmr skill to understand how to accept updates to a module.

Frequently Asked Questions about vite-hmr

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does Vite Hot Module Replacement work for preserving React component state?

Vite HMR works by accepting module updates and disposing of old modules to preserve React component state during fast refresh. It intercepts updates to prevent full page reloads, maintaining current state values like form inputs without resetting the component.

How do I accept updates and dispose of old modules using the Vite HMR API?

To use the Vite HMR API, you need to accept updates for a specific module and define disposal logic to clean up side effects. This pattern allows the new module to replace the old one seamlessly during development without triggering a full page reload.

Why does my React state reset when using Vite Fast Refresh?

React state resets during Vite Fast Refresh when modules are not properly accepted or when side effects from old modules are not cleaned up. Disposing of previous modules and correctly handling state preservation ensures that updates apply instantly without losing current values.

Can I use custom events with Vite HMR to monitor module replacement?

Yes, you can use custom events with Vite HMR to monitor module replacement. By enabling verbose logging and tracking these events, you can debug the HMR lifecycle, observe update propagation, and identify issues with side effects or state reset during development.

What is the best way to handle side effects during Vite module replacement?

The best way to handle side effects during Vite module replacement is to implement module disposal logic. By explicitly cleaning up side effects in the disposal hook before accepting new updates, you prevent memory leaks and ensure the new module initializes cleanly.