Ranvier.View.WebCore.Hmr.Traced
0.5.0
dotnet add package Ranvier.View.WebCore.Hmr.Traced --version 0.5.0
NuGet\Install-Package Ranvier.View.WebCore.Hmr.Traced -Version 0.5.0
<PackageReference Include="Ranvier.View.WebCore.Hmr.Traced" Version="0.5.0" />
<PackageVersion Include="Ranvier.View.WebCore.Hmr.Traced" Version="0.5.0" />
<PackageReference Include="Ranvier.View.WebCore.Hmr.Traced" />
paket add Ranvier.View.WebCore.Hmr.Traced --version 0.5.0
#r "nuget: Ranvier.View.WebCore.Hmr.Traced, 0.5.0"
#:package Ranvier.View.WebCore.Hmr.Traced@0.5.0
#addin nuget:?package=Ranvier.View.WebCore.Hmr.Traced&version=0.5.0
#tool nuget:?package=Ranvier.View.WebCore.Hmr.Traced&version=0.5.0
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.5.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] [-panel] [-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 |
Puts the CSS of the classes the project's templates apply on the page (see "Styles"). |
-panel |
Opens no window: the page streams to the editor's panel through the pipe, and the panel's input comes back to it (see "The panel"). It needs -pipe. -hidden and -software are then ignored. |
-size <w>x<h> |
The page's size in CSS pixels. The default is 480x640. Each side is brought into 16..8192, and so is each side of a resize the editor sends. A window also keeps each side to at most 8192 device pixels on a display that scales; the panel lowers its scale instead (see "The panel"). |
-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. |
-nobatch |
For the host's own tests and measurements: evaluate each file of a save in its own FSI evaluation (see "What a save reloads"). |
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.templatevalue, with its props type in the same file or in another; - an
ofMembersorofClasstype, 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 givesrestartingwith the reason, and the host exits with 3. App mode has the same limit, and reportsrestart. - The host reads the project's
Compileitems once, at its start. When a save of the project file changes them (a file added, removed, renamed or moved), the host sendsrestartingand 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, withfailedand 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
openof 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
ofClasstype, 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
openmounts 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, and to a host
with -panel the requests of "The panel". 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.
The panel
With -panel, the host opens no window. The page runs on a page host of its own, is painted into an
image for the editor's panel, and takes the panel's input. hello says surface: panel, and
-hidden and -software are ignored.
Frames
What goes. The page goes to the editor as binary frames of pixels (kind 1), which
Protocol.Pixelswrites and reads: a 36-byte header with the frame's number, the image's size in device pixels, a rectangle of it and the device scale, then the rectangle's RGBA rows. The first paint after the start, aresize, a new connection or arepaintis the whole image; each later paint is the rectangle that changed.When. The host runs a frame of the page at most every 16 ms. It paints only while an editor is connected and the warm-up has ended, and each connection numbers its frames from 1. A connection's first frame can come before the status of the component
-opennames.How many. At most 2 frames wait for the editor's
drawnwith their number. While 2 wait, the host runs no frame of the page and paints nothing; its timers and posted work still run. The next frame, after adrawn, covers everything the page changed meanwhile.repaintmakes the next frame whole and sends it without waiting fordrawn.Scale.
resizesets the page's size in CSS pixels and its device scale. When a whole frame at that scale would be over 64 MiB, or over 8192 device pixels a side, the host lowers the scale in steps of 1/64, to 0.25 at the least, until the frame fits, and logs the scale it took. A frame's header carries the scale it was painted at.Rectangles. A changed rectangle in device pixels is the page's rectangle in CSS pixels times the scale, rounded outward to whole device pixels and clipped to the image.
Input
The host passes the panel's input to the page once the warm-up has ended, and drops it before.
Coordinates are CSS pixels, and the page gets the pixel a coordinate falls in. modifiers holds the
bits 1 Shift, 2 Control, 4 Alt and 8 Meta.
| Request | What the page gets |
|---|---|
mouse |
A move, or a press or release of button (-1 none, 0 left, 1 middle, 2 right) with its clicks. leave is a move to -1, -1. |
wheel |
A wheel turn at x, y that scrolls by dx, dy CSS pixels, positive right and down. |
key |
down, up or char, with key and code as KeyboardEvent has them. A char types its text. |
focus |
Focus, as a window's focus changes; the page starts without it. |
compose |
An input method's composition: update with text and the selection start..end in it, commit with the final text, or cancel. |
paste |
text as the clipboard's text/plain, then the paste shortcut: Control+V, or Meta+V on macOS. |
A host with a window answers each of these requests with the note
request ignored: <request>, the panel's input, while the preview shows in a window.
Cursor and clipboard
cursorcarries the CSS name of the page's cursor when it changes after input or a frame, and once after a connection's first frame. An image cursor isdefault.clipboardcarries the text the page copies or cuts. The paste shortcut that apastepresses reads itstext; any other paste in the page reads an empty clipboard.- A WebCore without the clipboard feature logs it at the start, and copy and paste then do nothing.
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">. - A stylesheet that throws keeps the preview running. Its note,
stylesheet <name>: <message>, 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 recogniseswaitingby its state, not its detail.
With -css, the host puts the rules of each class that the project's templates apply into
<style id="ranvier-preview-extracted">. That element comes after the named one, so its rules win
between rules of equal specificity. Without -css, the element stays empty.
Where the rules come from. Ranvier.Css.View 0.2.0 and later keep
AppliedStyles, the process's log of each class their template parts applied. The host reads it, with the textStylesheet.rendergives for each class's rules, which is the textranvier-css-compilewrites. No tool runs.When. The host adds the classes new to the log after the first mount and after each applied reload, before the reload's status goes. A style edit is on the page when its
appliedarrives.What stays. The rules of a class no longer used stay. A class's name is a hash of its rules, so a stale rule matches nothing the project renders now.
The log. Each change of the element logs
styles: <count> classes, <added> added.An older Ranvier.Css.View. When the project's Ranvier.Css.View has no
AppliedStyles, does not load, or its log fails to read, the host shows no new classes and sends this note once:styles: this project's Ranvier.Css.View does not report its styles to the preview; update Ranvier.Css.View to see themA class that does not render. A class whose rules fail to render stays off the page, and the classes taken with it go on. The status of the reload that applied it carries the note
styles: the rules of <class> did not render: <message>, or, for several classes,styles: the rules of <n> classes did not render; <class>: <message>.
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> | <memory>. The outcome is patch, unchanged, fallback-remount, error or restart. The memory is the
host's private bytes on Windows (private 812 MiB) and its working set elsewhere (working set 812 MiB);
the ready line ends with the same figure.
The files of a save that reload as shadow modules (their lets, not the whole file) are evaluated together,
up to four in one FSI evaluation, and the line notes 60 files in 15 FSI evaluations. Larger evaluations
slow down every later evaluation of the session. When an evaluation fails, each of its files is evaluated
alone, so an error names its file, and a line before the save's reads [hmr] #n 4 files failed as one FSI evaluation after 412 ms, so each is evaluated alone. The FSI baselines of the files a save touches for the
first time are evaluated together in the same way.
| 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 asLib.Pagethat the reloaded generation ofLibdoes not hold, so its qualified names read the compiledLib.open Libavoids 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.mounteddoes 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 | Versions 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. |
-
net10.0
- FSharp.Core (>= 10.0.100)
- Ranvier.FSharp.Checker.Traced (>= 0.1.2)
- Ranvier.View.Dom.Traced (>= 0.9.0)
- Ranvier.View.Preview.Traced (>= 0.2.0)
- Ranvier.View.Traced (>= 0.9.0)
- Ranvier.View.WebCore.Sdl.Traced (>= 0.3.0)
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.