Maxime Mangel

Fable.Ripple: reactive UI for Fable without a virtual DOM

On this page
  1. A counter
  2. Start a project
  3. Configure the page
  4. Write the view
  5. Run it
  6. Signals without the DOM
  7. The packages
  8. Hot reload that keeps state
  9. Performance
  10. Links

Fable.Ripple is a set of F# libraries for building reactive web UIs with Fable, without a virtual DOM.

Fable compiles F# to JavaScript. In Fable.Ripple, a Var holds a value. Everything that reads a Var updates when it changes, and in the browser an update touches only the DOM nodes that read it. There is no virtual DOM.

The packages are in beta.

A counter

Program.fs
module Program

open Fable.Ripple
open Fable.Ripple.Dom

let count = Var.create 0

let view () =
    Html.div
        [
            Html.button
                [
                    on.click (fun _ -> count.Value <- count.Value + 1)
                    Html.text "Count"
                ]
            Html.output count
        ]

Html.mount "root" view |> ignore

view runs once. When you click, count changes and only the text of the output element is updated. Html.mount returns an IDisposable. Disposing it removes the element and stops every update the view set up.

Start a project

You need the .NET SDK 10.0 or later and Node.js 20.19 or later.

Terminal
dotnet new console -lang F# -o MyApp
cd MyApp
dotnet new tool-manifest
dotnet tool install fable
dotnet add package Fable.Ripple --prerelease
dotnet add package Fable.Ripple.Dom --prerelease
npm init -y
npm install --save-dev vite
  1. Configure the page

    Set "type": "module" in package.json, and create an index.html:

    index.html
    <div id="root"></div>
    <script type="module" src="/Program.fs.js"></script>
    
  2. Write the view

    Replace the content of Program.fs with the counter above.

  3. Run it

    Run dotnet fable watch in one terminal and npx vite in another.

Signals without the DOM

The core package, Fable.Ripple, does not depend on the DOM. You can use it on its own:

open Fable.Ripple

let price = Var.create 10.0
let quantity = Var.create 2

let total = Signal.computed (fun () -> price.Value * float quantity.Value)

// Runs immediately: total = 20.00
Signal.effect (fun () -> printfn "total = %.2f" total.Value) |> ignore

Updates are synchronous. A write settles before the next line runs, so there is no scheduler tick to wait for. They are also glitch-free: a computed signal or an effect runs once per write, after all its inputs are up to date.

The packages

Each library does one thing. Fable.Ripple works without the DOM layer, and Fable.UrlParser works without either. Install only the packages you need.

PackageWhat it does
Fable.RippleReactive values: Var, derived signals, effects, batching
Fable.Ripple.DomHTML and SVG elements, attributes and events bound to signals, routing helpers
Fable.Ripple.FormTyped forms: model, combinators, validation, wizards. Needs a renderer package
Fable.Ripple.Form.PlainA renderer for Fable.Ripple.Form, with rf-* classes and no CSS framework
Fable.Ripple.Dom.TestComponent tests in Chromium through Playwright
Fable.Ripple.PluginThe Fable compiler plugin behind [<Component>] hot reload
Fable.UrlParserTyped parsing and building of paths, query strings and fragments

Fable.Ripple.Dom brings in the plugin, and uses Glutinum.Web for the browser API.

Hot reload that keeps state

Mark a view with [<Component>]:

Counter.fs
module Counter

open Fable.Ripple
open Fable.Ripple.Dom

[<Component>]
let view () =
    let count = Var.create 0

    Html.div
        [
            Html.button
                [
                    on.click (fun _ -> count.Value <- count.Value + 1)
                    Html.text "Count"
                ]
            Html.output count
        ]

With dotnet fable watch and npx vite running, click the button five times, change the label to "Add", and save. The button says Add and the count still reads 5.

In Debug builds, the plugin rewrites each let binding of type Var in the component so its state survives the swap. Release builds are not changed. Some limits apply:

  • The component is rendered again in full.
  • State resets when you rename a Var, change its type, move or rename the component, or create the Var in a lambda or at module level.
  • inline members and members of [<AttachMembers>] types are skipped without a warning.

Performance

Fable.Ripple is in the official js-framework-benchmark results, as the keyed fable-ripple entry. These are the results of the Chrome 158 run:

Vanilla JSFable.Ripple 1.0.0-beta.6Solid 1.9.3Svelte 5.42.1React 19.2.0
Duration1.031.211.131.181.55
Memory1.051.521.281.472.58
Size and first paint2.257.062.664.9725.83

Each test compares an entry with the best result of all the entries, so 1.00 is the best score and lower is better. Each number in the table is the geometric mean of those factors. For duration, the mean is weighted.

More posts

Building a front end in F#?

I maintain Fable and wrote Fable.Ripple. If you are weighing it for a real project, I can help you try it on your code.

Write to me