Ranvier.View.WebCore.Hmr.Traced 0.3.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.3.0
                    
NuGet\Install-Package Ranvier.View.WebCore.Hmr.Traced -Version 0.3.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.3.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.3.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.3.0
                    
#r "nuget: Ranvier.View.WebCore.Hmr.Traced, 0.3.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.3.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.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Ranvier.View.WebCore.Hmr.Traced&version=0.3.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.3.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 -> ...). A component's props file is <key>.fs; it is evaluated in FSI when the component opens, the one -open names during the warm-up, and again when it changes or a reload redefines what it names. When the folder has no <key>.fs, or that file defines another key, an open that names no file evaluates the folder's other files to find the one that defines the key; a key that has a props file keeps it. A props file names the project's modules, not another props file's, and its top level runs again only when its text changes or a reload redefines what it names.
-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. Each side is brought into 16..8192, and to at most 8192 device pixels on a display that scales, and so is each side of a resize the editor sends.
-hidden Keeps the window off screen, for tests.
-software Renders with the software renderer, for tests on a machine without a GPU.
-bench <json> Plays the scenario of edits, clicks and expectations in the file, writes its results beside it, and closes.
-nochecker Reloads without the checker: only the saved files are evaluated (see "What a save reloads").
-baseline, -nobaseline, -nolazybaseline For the host's own tests: take the FSI baseline of every file at the start (a preview takes none, since each file is baselined at its first edit, and so does a build the dev compiler stamped), take none, or skip the baseline a file gets at its first edit.

The host refuses an argument that is not one of these flags or a flag's value. -props names a folder of props files alone: the project's folder, a folder that holds it, and a folder that holds one of its sources are refused. The preview reloads with fine alone. The host writes its log to its standard output as UTF-8.

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 sends the status restarting with the reason, then exits. The editor starts a new host.
2 The host cannot start, or cannot go on. The reason is the last line of its standard error, and an exception's trace is in the log on its standard output. The arguments are invalid (the flags are printed after the reason); the pipe name is in use or not allowed; the project file is not XML, or one of its Compile items is not a file on disk (the host reads each Include as a path, and evaluates no $(...) property, wildcard or condition); the project's assembly is not one the harness references; the warm-up failed, as when FSI does not start; or the host met an error it does not handle.

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 the text below. A reload says it in its own status. A knob and a reset say it in a note: the last status again, its state kept, with set <path>: ... or reset: ... and this text after its detail.

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.

A reset whose build or mount fails leaves the component, its state and its knobs as they were, and its note says why.

An open of another component mounts it fresh: a component that both trees render, such as a shared row, starts from its setup. An open of the component that is already open 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, and its errors as diagnostics. 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, and every later status says so: a save that evaluates nothing, such as a comment or another component's props file, repeats failed with the errors. A knob set while a structural change waits for the props file is stored and noted in that status, and the remount takes it; any other knob set applies through the last preview that loaded.

An open, and -open, do not wait: a props file that fails gives one failed status at once, with the file's errors as diagnostics and what stays in the window (<key> stays mounted, or no component is open). While no component is open, the key that was asked for stands for the open one: every later status repeats its props file's failure, and it mounts as soon as its props file loads, with the status open: opened <key>, mounted in <ms> ms.

A preview whose build throws gives failed with the detail the preview of <key> failed to build: <message>, and a diagnostic of its props file at the line of the trace's frame in that file (line 1 when no frame is in it). A reload's other components are patched all the same. A save that evaluates nothing, and a save of another component's props file, repeat the failure until the preview builds or another component opens, and the open root takes the reload once its preview builds again. An open whose preview throws as it builds fails the same way, and while no component is open its key mounts once its props file loads and builds.

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 restarting with the reason, and the host exits with 3. App mode has the same limit, and reports restart.
  • The host reads the project's Compile items once, at its start. When a save of the project file changes them (a file added, removed, renamed or moved), the host sends restarting and exits with 3. Other edits to the project file, such as a package reference, are not seen: restart the preview after them.
  • A source that is deleted or renamed while the project file still lists it fails the next save, of a source or of a props file, and every open, with failed and the file's name. Reloads go on once the file is back, and a props file saved meanwhile is evaluated then.
  • A props file that is deleted or renamed away is forgotten. When it is the open component's, the window keeps its last render, and an open of that component says that the file does not exist. When the props folder itself is deleted, the host goes on, and it evaluates the folder's files again once the folder is back.
  • 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.
  • At its warm-up the host compares each source with the checksum the build's portable PDB holds for it, or, without a PDB, the source's write time with the assembly's. The compiler takes those checksums when it writes the PDB, at the end of the project's compile. So a source saved after the project compiled (while the rest of the build, the copy, the host's start or its warm-up ran) is caught: it reloads once the host is ready, as if each of its declarations changed. A source saved while the project compiles is not seen: the running code keeps the text the compiler read, and a later edit of that source does not bring the earlier one in (the reload compares with the text on disk). The editor that runs the build rebuilds when it saw a save during the compile.
  • 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: no knobs and no other status comes before it. The component -open names mounts during the warm-up, and its knobs and its status, that of an open, follow ready. A client that connects after the warm-up 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: a full path, or a file name alone, of 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>, mounted in <ms> ms, where <ms> is the mount and the status's ms the whole open, and one that fails sends failed with the reason. The status of an open is published in the order of the reloads around it.

The host answers a request it does not serve with a note: the last status again, its state and diagnostics kept, with the note after its detail; before any other status, a note repeats ready. A set the knob rejects gives set <path>: <reason>; a set or a restore stored while a structural change waits for the open props file gives ...: stored; the preview takes it once its props file loads; a restore for a key that is not open, a request without the fields it needs (a resize without a width and a height included) and a message with an unknown t say that they were left out. The next request that succeeds sends the last status again without the note.

A status detail is one line. It names each error of its diagnostics by file and position (Counter.fs(25,15)), and the error's text is in the diagnostics. An exception's stack trace is in the fault message and in the host's log.

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>: <the first line of its error output>, ranvier-css-compile timed out after 120 s, ranvier-css-compile wrote no <path>, ranvier-css-compile did not start: <reason>; install the ranvier-css-compile dotnet tool, or set RANVIER_PREVIEW_CSS_TOOL to its command line) is appended to the detail of the reload's status. The tool's whole output is in the host's log. 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.

An error report of an exception carries the exception's message on one line; the stack trace is in the host's log. A source that is deleted while the project file lists it gives an error report with its name at the next save, where it ended the host before, and reloads go on once the file is back. A watched folder that is deleted and created again is watched again. The host reads sources without holding off an editor's save. A project file with a Compile item that is not a file on disk is refused at the start, with the item.

A reload whose setup throws, and a props change whose setup throws, leave each instance on a live run of the setup it had, with the props it had: the view goes on following the instance's state, and the report is the exception's message. A source saved after the project compiled reloads once the host is ready; a save during the compile is the build's to repeat (see "Limits" under "Preview mode"). On Windows and macOS, a Compile item in another case than the file on disk reloads at the file's save.

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.