Ranvier.View.WebCore.Hmr.Traced 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ranvier.View.WebCore.Hmr.Traced --version 0.2.0
                    
NuGet\Install-Package Ranvier.View.WebCore.Hmr.Traced -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ranvier.View.WebCore.Hmr.Traced" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ranvier.View.WebCore.Hmr.Traced" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Ranvier.View.WebCore.Hmr.Traced" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ranvier.View.WebCore.Hmr.Traced --version 0.2.0
                    
#r "nuget: Ranvier.View.WebCore.Hmr.Traced, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ranvier.View.WebCore.Hmr.Traced@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ranvier.View.WebCore.Hmr.Traced&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Ranvier.View.WebCore.Hmr.Traced&version=0.2.0
                    
Install as a Cake Tool

Ranvier.View.WebCore.Hmr

Hot reload for native Ranvier.View.WebCore apps in development. The dev host keeps the SDL window and the WebCore page alive for the whole session and patches edited components into them, keeping their state.

Experimental. It runs under the JIT only (FSI, reflection), so reference it from Debug builds; the app's normal path is unchanged and stays NativeAOT-compatible.

dotnet add package Ranvier.View.WebCore.Hmr --version 0.2.0

Usage

Replace Window.run in the entry point:

[<EntryPoint>]
let main argv =
    Ranvier.View.WebCore.Hmr.Dev.Run (argv, "My app", 640, 480, App.app, ())
dotnet run                       # the app
dotnet run -- dev                # the dev host, fine-grained patching
dotnet run -- dev -hmr fsi       # remount after an FSI evaluation of the edited file
dotnet run -- dev -hmr alc       # remount after an in-process compile into a collectible load context

Components stay ordinary Component.define code. The window title shows each reload's path and time.

A root whose props need the window (a GPU context, for instance) uses Dev.RunWith (argv, title, width, height, root, fun window -> props): the props are built once per window and survive every reload. Props that implement IDisposable belong to the host, which disposes them after the tree unmounts and before the window. examples/Ranvier.HmrWgpu hot-reloads a Ranvier.Wgpu scene this way.

Preview mode

Dev.Preview argv mounts one component of a project at a time and reloads the project as it changes. The editor extension writes a harness project for it, so nothing is added to the previewed project:

[<EntryPoint>]
let main argv = Ranvier.View.WebCore.Hmr.Dev.Preview argv
dotnet Preview.Host.dll -project <fsproj> -props <dir> [-open <key>] [-pipe <name>] [-css] [-size 480x640]
Flag Meaning
-project <fsproj> The project to reload. It may be a library, which has no entry file, so each of its sources reloads.
-props <dir> A folder of props files: F# files that each define a Preview of Ranvier.View.Preview, as let preview: Preview = Preview.create "<key>" (fun p -> ...). Each is evaluated in FSI after the project's FSI baseline, and again when it changes.
-open <key> Mounts the component of that key first: Namespace.Module.name for a module value or function, with the module's compiled name (CounterModule for a module beside a type Counter), or the full name of a component type. Without it, nothing is mounted until the editor sends open.
-pipe <name> The named pipe to the editor (see "The pipe").
-css Extracts the project's CSS with ranvier-css-compile (see "Styles").
-size <w>x<h> The window's size in CSS pixels. The default is 480x640.
-hidden, -software, -bench <json>, -nochecker As under dev. The preview reloads with fine alone.

A signal knob (p.Signal) is written in place. A value knob (p.Value) runs the preview again and patches the mounted instance with the new props, keeping its signals.

Exit codes

Code When
0 The window closed, or the editor sent close.
3 The host needs a restart. It publishes a restart report, then exits. The editor starts a new host.
2 The arguments are invalid, the pipe name is in use or not allowed, or the project's assembly is not one the harness references. The usage line is printed.

What keeps its state

A reload of the open component's file, and a knob rebuild, keep the instance's signals in these layouts:

  • a Component.template value, with its props type in the same file or in another;
  • an ofMembers or ofClass type, and an edit to its props type, including when a later file uses that type (the later file is left stale, see "Limits");
  • a file the preview does not reach: it comes after the open component's file.

These layouts mount the component fresh. Each says so in the status detail, which contains:

Layout Detail
The component's file starts with a namespace state reset: <File>.fs starts with a namespace
The preview renders a function's result state reset: a function's result
A knob of a function's argument that is not a string, int, float, bool or char knob (a decimal, choice, option, list or readonly knob, or a record or union field), or a part of one state reset: a function's result
The editor sent reset state reset: the editor reset the preview

A function's argument of kind string, int, float, bool or char reaches the setup and the readers of the mounted instance, which keeps its state.

Props files that fail

A props file that does not compile or evaluate gives waiting with the detail waiting for the project to reload. It is evaluated again after the next applied reload, since it is usually ahead of a props type the project is about to gain. After a reload that applied, with no edit pending, a props file that still fails gives failed with its errors. While the open props file fails, the window keeps its last render.

Limits

  • A file whose re-evaluated lets name a private or internal type of the built assembly cannot be evaluated in FSI. An edit to it gives restart with the reason, and the host exits with 3. App mode has the same limit.
  • A file that comes after the open component's file is left stale: an edit to it reports <File>.fs: after <Component>.fs, so left stale. It is evaluated when something the preview reaches uses it, or when the editor opens a component that does.
  • An edit to the entry file is reported as unchanged, with a note.
  • A named stylesheet reaches the file that declares it and the files that file's declarations use. When the checker cannot analyse that file (a file of one declaration, or a module rec), the stylesheet reaches that file alone, so a helper it uses in another file can be stale until that helper's file is evaluated.
  • Edits saved while the host warms up become part of its starting snapshot, and the running code misses them until that declaration changes again. Wait for status ready before saving.
  • A component instance of a class (an ofClass type, or a class that a setup returns) carries its signals across a reload, but a signal held in a private field of its base class starts over.
  • A reload that resets the state, held while the open props file fails, can keep the state instead when a knob change or a failed open mounts the preview before the props file is fixed.
  • Two sources with the same file name in different folders collide: reports, diagnostics and the reload plan tell files apart by file name, so an edit to one can be reported or evaluated as the other. Give sources distinct names.

The pipe

With -pipe <name>, the host creates the named pipe at start, so the editor can connect during the warm-up. It serves one client at a time. Ranvier.View.Preview.Protocol defines the frames and the messages. The host sends hello first on every connection, and status ready once the warm-up ends. A client that connects after that gets ready right after hello, and a client that connects as the warm-up ends can get it twice, so a client accepts a repeated ready. A reconnecting client then gets the last status the host sent, knobs at the next frame step, and every later message. The editor sends open, set, restore, reset, resize, front and close. The pipe reads one request at a time, and open holds it until the component has mounted. open evaluates the props file its file gives, which must be a file of the props folder; with an empty file, the host uses the file that last defined the key's preview, else <key>.fs. An open that mounts sends applied with the detail open: opened <key> in <ms> ms, and one that fails sends failed with the reason.

Styles

  • A named stylesheet is a function that a props file registers with p.Stylesheet(name, css). After each run of the preview, the host writes the text of every registered stylesheet into <style id="ranvier-preview-named">.
  • With -css, the host runs ranvier-css-compile in the project's folder: dotnet tool run ranvier-css-compile when a tool manifest at or above the project lists it, otherwise the global tool. RANVIER_PREVIEW_CSS_TOOL replaces the command line. The result goes into <style id="ranvier-preview-extracted">, which comes after the named element, so extracted rules win between rules of equal specificity.
  • The extraction runs after the first mount, and after each applied reload of a file whose text holds styles {. It runs on a background thread. A tool that runs for more than 120 s is killed with its process tree and noted.
  • A stylesheet that throws, and an extraction that fails, keep the preview running. The note (stylesheet <name>: <message>, ranvier-css-compile exited with <code>, ranvier-css-compile timed out after 120 s, ranvier-css-compile wrote no <path>) is appended to the detail of the reload's status. A note that no reload carries is sent as a status that repeats the last status's state, diagnostics and ms, with the note appended to its detail. A client recognises waiting by its state, not its detail.
  • Two settings exist for the host's own tests: RANVIER_PREVIEW_CSS_OUTPUT is the folder the tool writes app.css to, in place of preview-css beside the host, and RANVIER_PREVIEW_CSS_TIMEOUT_MS replaces the 120 s timeout.

Reports in app mode

The dev host now publishes every report of a burst of edits, in order. Before, a later report could replace an earlier one that was not yet published.

Strategies

Strategy Save to presented Keeps
fine (default) ~80–130 ms; comment-only edits ~22 ms DOM nodes, instances and their signals, public module-level values
fsi ~80–100 ms, growing with the remounted tree signal values; setups re-run on every save
alc ~550–700 ms signal values; any F# construct, every file recompiled

fine mounts each definition through an instrumented copy of its template: static attribute values and text are signal cells, and every reader, handler and region function goes through a swappable cell. A reload re-evaluates the changed declarations in FSI (only the lets, against the types in use, unless a type changed), writes the cells whose value or code changed, and remounts with state transplant when the template structure changed. Ranvier.FSharp.Checker gates reloads on errors and supplies the declarations that depend on a change, in any file; they are evaluated again with it.

An edit with compile errors never reloads; the next passing save is compared with the last applied text.

What a save reloads

Under fine, each save prints one line: [hmr] #n fine <files>: <outcome> | <timings> | <what was evaluated>. The outcome is patch, unchanged, fallback-remount, error or restart.

Edit Outcome
A let: a function, a value or a component Evaluated again, with every let that uses it, in its own file and in later files. Components that use any of them are patched.
A let inside a nested module that holds only lets and opens The same. The nested module is evaluated again as a whole.
Several files, saved together or one after another Applied together in compile order. A later file sees a function an earlier file gained, whichever was saved first.
A type, or any declaration other than a let or an open; a let in a nested module that also holds types The whole file is evaluated again and its module-level values start over. Every let in a later file that uses anything the file declares is evaluated again with it.
The same, when a type in another file uses what the edited file declares restart: the line reads restart needed: App.fs: Shelf:Type cannot be evaluated again in place, and the edit to Lib.fs redefines what they use. Nothing is applied, and every later save repeats the line until the app restarts or the edit is undone.
The entry file (the one holding [<EntryPoint>]) restart: restart needed: Program.fs is the entry file, which the host does not reload.
A compile error, in an edited file or in a file below it that the edit broke error, with the file, line and message. Nothing is applied; the next save delivers every file that is still unapplied.

What keeps its object across a reload: a public, immutable module-level value (a store, a cache), unless its own text changed or it uses a declaration that did. What starts over whenever its file is evaluated again: private or mutable module-level values, and private nested modules.

Three cases are named in the line instead of being reloaded:

  • names qualified with a reloaded module bind to the build: the file uses a name such as Lib.Page that the reloaded generation of Lib does not hold, so its qualified names read the compiled Lib. open Lib avoids it.
  • not checked by declaration: the checker could not split the file into declarations, so what it uses of the edit is unknown and it was not evaluated again.
  • With -nochecker, or when the checker fails to start, only the saved files are evaluated: nothing that depends on them is, in the same file or in others.

fsi evaluates each saved file whole and alc recompiles the project, so neither tracks dependents: fsi leaves other files on the old code, and alc reloads everything.

Constraints

  • Arm (matchWith/branch) components update when their parent is re-evaluated.
  • Hooks.mounted does not re-run on a patch.
  • Instances are paired by setup order on a remount; reordering instances of one component can cross their state.
  • A value re-evaluated because it uses a change runs its initializer again, side effects included.

The measurements, edge cases and design record are in docs/research/native-hmr.md.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 81 12/3/2026
0.4.0 86 12/2/2026
0.3.0 93 12/2/2026
0.2.0 95 12/1/2026
0.1.10 107 11/30/2026
0.1.9 97 11/30/2026
0.1.8 99 11/27/2026
0.1.7 95 11/27/2026
0.1.6 103 11/26/2026
0.1.5 108 11/23/2026
0.1.4 102 11/18/2026
0.1.3 98 11/16/2026
0.1.2 106 11/15/2026
0.1.1 100 11/14/2026
0.1.0 103 11/14/2026
0.1.0-alpha.2 70 11/14/2026

Experimental development tool. JIT only; reference it from Debug builds.