From 454b22179bb076ecb496dfc57a694c375e15cb7b Mon Sep 17 00:00:00 2001
From: Jane Chu <7559015+janechu@users.noreply.github.com>
Date: Wed, 1 Apr 2026 10:17:48 -0700
Subject: [PATCH 1/2] Add webui-todo-app example with declarative FAST HTML and
webui prerendering
Adds a new example in examples/webui-todo-app that:
- Converts the todo-app to use declarative FAST HTML syntax (f-template,
f-repeat, {{}}/{} bindings) via @microsoft/fast-html
- Prerenders the DOM content using @microsoft/webui (build + render)
- The Express server calls build() at startup to compile the HTML template
into a binary protocol, then render() on each request to inject
prerendered todo items and component templates as raw HTML
- Client-side hydration uses RenderableFASTElement and TemplateElement
from @microsoft/fast-html, seeded with window.__INITIAL_STATE__
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
examples/webui-todo-app/package.json | 31 ++++
examples/webui-todo-app/server.js | 127 +++++++++++++++
examples/webui-todo-app/src/index.html | 68 ++++++++
examples/webui-todo-app/src/main.ts | 24 +++
examples/webui-todo-app/src/todo-app.ts | 6 +
examples/webui-todo-app/src/todo-form.ts | 12 ++
examples/webui-todo-app/src/todo-list.ts | 69 ++++++++
examples/webui-todo-app/todo-data.json | 5 +
examples/webui-todo-app/tsconfig.json | 19 +++
examples/webui-todo-app/vite.config.ts | 19 +++
package-lock.json | 191 +++++++++++++++--------
package.json | 3 +-
12 files changed, 504 insertions(+), 70 deletions(-)
create mode 100644 examples/webui-todo-app/package.json
create mode 100644 examples/webui-todo-app/server.js
create mode 100644 examples/webui-todo-app/src/index.html
create mode 100644 examples/webui-todo-app/src/main.ts
create mode 100644 examples/webui-todo-app/src/todo-app.ts
create mode 100644 examples/webui-todo-app/src/todo-form.ts
create mode 100644 examples/webui-todo-app/src/todo-list.ts
create mode 100644 examples/webui-todo-app/todo-data.json
create mode 100644 examples/webui-todo-app/tsconfig.json
create mode 100644 examples/webui-todo-app/vite.config.ts
diff --git a/examples/webui-todo-app/package.json b/examples/webui-todo-app/package.json
new file mode 100644
index 00000000000..2fd42c5e69e
--- /dev/null
+++ b/examples/webui-todo-app/package.json
@@ -0,0 +1,31 @@
+{
+ "name": "@microsoft/fast-webui-todo-app-example",
+ "version": "1.0.0",
+ "description": "",
+ "main": "dist/exports.js",
+ "type": "module",
+ "private": true,
+ "scripts": {
+ "build": "vite build",
+ "start": "npm run build && node server.js",
+ "test": "npm run build"
+ },
+ "author": {
+ "name": "Microsoft",
+ "url": "https://discord.gg/FcSNfg4"
+ },
+ "homepage": "https://www.fast.design/",
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/Microsoft/fast.git",
+ "directory": "examples/webui-todo-app"
+ },
+ "dependencies": {
+ "@microsoft/fast-element": "^2.10.2",
+ "@microsoft/fast-html": "*",
+ "@microsoft/webui": "^0.0.2",
+ "express": "4.22.1",
+ "tslib": "^2.6.3"
+ }
+}
diff --git a/examples/webui-todo-app/server.js b/examples/webui-todo-app/server.js
new file mode 100644
index 00000000000..87755ed7f31
--- /dev/null
+++ b/examples/webui-todo-app/server.js
@@ -0,0 +1,127 @@
+import fs from "node:fs";
+import { build, render } from "@microsoft/webui";
+import express from "express";
+
+const app = express();
+const port = 8081;
+
+// Build templates into a binary protocol at startup (build-time compilation)
+const result = build({ appDir: "./src", plugin: "fast" });
+
+// The f-template elements define the declarative FAST component templates for
+// client-side hydration. They use single-brace {} bindings so the SSR step
+// does not attempt to fill them in — FAST-html resolves them in the browser.
+const COMPONENT_TEMPLATES = `
+FAST Todos
+
+
+
+
", + ``, + ); + + res.send(withState); +}); + +app.listen(port, () => { + console.log(`WebUI Todo app listening on port ${port}`); +}); diff --git a/examples/webui-todo-app/src/index.html b/examples/webui-todo-app/src/index.html new file mode 100644 index 00000000000..849c9bfdace --- /dev/null +++ b/examples/webui-todo-app/src/index.html @@ -0,0 +1,68 @@ + + +
+ +
+ +
+