Volt.HMR.Boundary (Volt v0.8.4)

Copy Markdown View Source

Detect HMR boundaries by scanning for import.meta.hot.accept() calls.

When a file changes, walks the dependency graph upward from the changed file to find the nearest module that self-accepts HMR updates. If found, only that module is re-imported by the client. Otherwise, a full reload is triggered.

Summary

Functions

Find the HMR boundary for a changed file.

Check if a module's source code contains import.meta.hot.accept().

Functions

find_boundary(changed_path, read_source)

@spec find_boundary(String.t(), (String.t() -> String.t() | nil)) ::
  {:ok, String.t()} | :full_reload

Find the HMR boundary for a changed file.

Walks upward through the dependency graph from changed_path. Returns {:ok, boundary_path} if a self-accepting module is found, or :full_reload if the change bubbles up to the root without finding a boundary.

The read_source function is called with an absolute path and should return the module's source code for boundary detection.

self_accepting?(source)

@spec self_accepting?(String.t()) :: boolean()

Check if a module's source code contains import.meta.hot.accept().