Repository navigation
Releases
NetWasm.UI 0.16.0
Changed
- Breaking: NetWasm.UI is built with NetWasm.Sdk 0.15.1 for
net10.0-netwasm, which replaces
netwasm0.1.NwUi,NwUi.BrowserandNwUi.Workersshipnet10.0-netwasmbuilds in place of
netwasm0.1ones, and the templates createnet10.0-netwasmapps. To upgrade an app, pin
NetWasm.Sdk 0.15.1, change its target framework and update the NwUi packages together; see
Upgrading fromnetwasm0.1. - The templates, samples and benchmarks set
NetWasmTypeNamestofalse: none of them reads type
names, and NetWasm.Sdk 0.15 would otherwise publish a type-names file the page fetches at startup.
Added
samples/Tsp: a route optimizer (traveling salesman) in a pool of Web Workers that stream
shorter tours while the page stays responsive. It is published on GitHub Pages under/tsp/and
linked from the examples page. See Web Workers.
NetWasm.UI 0.15.1
Added
NwUi.Workersalso targetsnetstandard2.1, with only the attributes andWorkerException, so a
contracts project can target .NET Standard and be shared with servers and unit tests.
samples/Workers.Contractsnow does. See Web Workers.
NetWasm.UI 0.15.0
Removed
NetWasmUIReusePrerender(NwUi.AspNetCore):UseNetWasmUIDevServerno longer keeps the pages
prerendered at startup across rebuilds. Putting them back did not reliably match what the new
build wrote. A client withNetWasmUIPrerendernow prerenders on every rebuild, which takes a
few seconds longer. Remove the property if you set it; to skip prerendering in development, set
NetWasmUIPrerenderonly forReleasein the client project, see
ASP.NET Core.
Added
NwUi.Workers(preview): C# services in Web Workers. Mark an interface[WorkerContract],
implement it in a worker project with[WorkerService]and register it in the app with
AddWorker<T>()(one stateful worker) orAddWorkerPool<T>()(parallel, stateless calls).
A source generator writes both sides. SupportsCancellationToken(cooperative, or
terminateOnCancel),IProgress<T>,IAsyncEnumerable<T>with back pressure, and JSON
arguments through aJsonSerializerContext. See Web Workers and
samples/Workers.- The page no longer preloads
netwasm.runtime.worker.*.mjs, which only runs inside workers. - Library assets: a component library declares stylesheets, JavaScript modules and fonts with
<NwUiAsset Include="…" />. Apps serve them at_content/<PackageId>/, bundle the modules
for[JSImport], and (with NwUi.Browser) link the stylesheets fromindex.html(in the project
folder or inwwwroot) at build time, before the app's own CSS, so prerendered pages are styled
on first paint. Opt out withNetWasmUIInjectAssets=false. Works for project and package
references, and anetstandard2.1library packs its assets too. See
Stylesheets, scripts and fonts. ListenerFlags.CaptureandListenerFlags.Passive(@onfocus:capture,
@onwheel:passive): the listener is added to the element instead of being delegated.
PassivewithPreventDefaultthrows.OnDocumentandOnWindowaccept them too.- Focus:
element.FocusFirst()andFocusLast()focus the first or last tabbable element
inside an element after the pending DOM updates, andHtml.Focus(id)focuses the element
ActiveElementId()returned.samples/Primitives.Kitbuilds aFocusScope(trap and
restore) and roving focus on them. - Exit animations:
When(…).AnimateExit()andEach(…).AnimateExit(),@if (…) animate-exit
and@foreach (…) animate-exitin templates. Removed content getsdata-state="closed"and
stays in the DOM until its CSS animations finish; shown content getsdata-state="open". See
Exit animations. NwUi.Testing(preview):TestRenderer.Render(component)renders components in a .NET test
without a browser, withFind,Click,Input,KeyDown,Focusedand more. See
Testing.NwUialso builds fornetstandard2.1, so a component library can targetnetstandard2.1and
work in browser apps, prerendering andnet10.0tests alike. See
Your own libraries.- Building a headless library: how to layer headless and
design-system libraries on these pieces, with API conventions, compound components, dialog and
menu patterns, an accessibility checklist and pitfalls. dotnet new netwasm-ui-lib(NwUi.Templates): anetstandard2.1headless component library with
aDisclosureand a test project onNwUi.Testing.- Build a component library: a tutorial from the template
to a themed library and packages.samples/Primitives.Kitgains aDisclosureand compound
Tabs(Tabs,TabList,Tab,TabPanel), andsamples/Primitives.Themeis a design-system
library on top of it, with its stylesheet as anNwUiAsset. EventChannel<T>: a typed, synchronous event channel for in-app pub/sub.Publishruns every handler in
one batch, and aSubscribemade while building a component ends with that component. Handler
errors go to the subscriber's error boundary. See Events.Services.AddServiceProvider(IServiceProvider):Inject<T>()falls back to any
IServiceProvider, such as aMicrosoft.Extensions.DependencyInjectioncontainer from
NetWasm.Microsoft.Extensions.DependencyInjection, for types that are not registered by type.
AddServiceProvider(Func<IServiceProvider>)creates the provider per providing scope and disposes
it with that scope, so() => root.CreateScope().ServiceProvidergives each subtree its own
container scope. See Using Microsoft.Extensions.DependencyInjection.
Changed
- A custom DOM host (
createDomHostreplacement or a host of your own) must handle two new ops:
RemoveAnimated(28) andFocusEdge(29). See the op table. The
hosts in NwUi.Browser and the prerenderer handle them. - The templates, samples and docs no longer declare an empty
MaininProgram.cs. A
JsModuleapp only needs its[JSExport]methods. Existing apps can delete theirs. - The benchmark runner waits until a page has made no request for 500 ms before the setup clicks,
as js-framework-benchmark does. Starting the warm-up right after the app is ready made some
cases of the JavaScript frameworks faster than the official benchmark measures them. The same
wait keeps the runner from polling the page while NetWasm.UI is still starting, which had added
about 5 ms to its startup figure. - A computation keeps its first two sources inline, and a signal its first two observers. A list
row whose bindings read two signals (its label and the selected key, say) no longer allocates
two arrays for the second one. - A
Scopekeeps its first registration inline. A list row's scope, which owns one thing, no
longer allocates an array of eight. - A template row whose bindings ask a
Selectorabout the row's own@key
(class="@(isSelected.Is(row.Id) ? "danger" : null)"on a row with@key="row.Id") is told
about selection changes through its list, instead of the selector keeping a node and a
dictionary entry per row. Only a selector with the default comparer does this; others work as
before. - The renderer no longer keeps a render batch buffer that one large batch grew (a list of thousands
of rows) for the small batches after it. It kept two of them, about 1 MB each after 10,000 rows;
a later large batch grows its buffer again.
NetWasm.UI 0.14.0
Changed
nwui.domkeeps the browser's compiled code for applying a batch across the browser's own
garbage collections. It created a reader object per batch, and when a collection freed the
shape of those short-lived readers (or of a cleared list's rows) the browser threw away the
code compiled for them, so the next batch ran slower while it was compiled again. One reader
now reads every batch, and each template keeps one node shaped like its clones' root.- A template clone releases its node ids with one op (new
ReleaseBlockop) instead of one per
node, and clones whose ids follow each other share that op. Clearing a list of 1,000 rows
sends 18 bytes instead of 25 KB, and replacing one sends a third less. A host of your own has
to handle the new op. - The keyed list builds no table of the old keys' positions when none of them stays in the new
list (a list replaced by new rows, or rows removed from one end). - The benchmark runner forces the same last-resort GC before the measured click as
js-framework-benchmark does, instead of a plain one.
NetWasm.UI 0.13.0
Added
TemplateRuntime.Rows,TemplateRowandTemplate.Listen: the rows of a keyed list as clones of
one template, filled in by functions of the row that all rows share. See
Rows. NewTemplateListenerop.benchmarks/WasmBench: the keyed benchmark's C# side under Wasmtime, with times that repeat
within about 1 % and exact allocation and batch sizes. See
Benchmarks.
Changed
.nwui: the element of an@foreachbody is compiled to rows of a template. A row is one
clone and one object: its@exprtext and bound attributes are one effect, and its@on…
handlers for delegated events are registered once for the whole list. Creating rows takes about
40 % less time on the C# side and sends about 40 % fewer bytes to the host. Templates need no
change. Two things behave differently, see
Rows of an@foreach:- A row whose key gets a different item in a new list (another object, or for a value type a
value that is not equal) now shows that item in all of its content. A row that is only
bindings and delegated handlers takes it in place; a row with a component, a block,@bind,
@refor other content that is applied once is built again for it. Before, the row kept the
object it was created for. Keep the same object to keep the row. - The bindings of a row are evaluated together when something one of them reads changes. Only
values that differ are written to the DOM.
- A row whose key gets a different item in a new list (another object, or for a value type a
Eachand every other keyed list follow the same rule: a key that stays but gets a different
item has its row disposed and rendered again for that item, in the same place. Before, the row
kept the object it was created for. Lists without@key(the items are the keys) are not
affected. See Conditionals and lists.nwui.domclones a template from its own inert document (a template with custom elements is
still imported first) and finds a clone's text holes when they are first written to, instead of
walking to every hole of every clone. Creating 10,000 rows spends about 8 ms less in the browser.- The keyed list reuses its keys and lookup tables from one list to the next, and it clears a list
or swaps two rows without building them. Swapping two of 1,000 rows no longer allocates per row. - The benchmark runner warms up every case the way js-framework-benchmark does: create 10,000
rows, append and select row were measured with less or no warm-up before. - The benchmark app is a
.nwuitemplate (benchmarks/NetWasmBench/BenchApp.nwui), so the
benchmark measures what the template compiler emits.
NetWasm.UI 0.12.0
Added
NwUi.AspNetCore: hosts a NetWasm.UI app in ASP.NET Core on the same origin as your API.
app.MapNetWasmUI()serves the client with the right MIME types and the prerendered page for
each route;app.UseNetWasmUIDevServer()adds live reload and the error overlay in
development (rebuilds useO0and reuse the startup prerender, about 5 s; turn that off with
NetWasmUIReusePrerender=false); setting
NetWasmUIClientProjectpublishes the client into the server on build
and publish. See ASP.NET Core
and the newsamples/Hosted.- Template:
dotnet new netwasm-ui-hostedcreates a client, an ASP.NET Core server and a
shared library (Home, Counter and Weather, prerendering, live reload). Needs .NET 11.
Changed
- Live reload also reloads the page when the connection to the dev server comes back, for
example afterdotnet watchrestarts the server.
NetWasm.UI 0.11.0
Added
- Attribute splatting: on a component tag, lowercase or dashed attributes (
class,aria-*,
data-*…) and@on…handlers go to the newComponent.Attributes, and@attributes="expr"
applies them to an element (or forwards them to another component).classandstylejoin
the element's own value. From C#, useHtml.Splat. See
Attribute splatting and the new
live example. TemplateInstance.Text(int, int)andText(int, Func<int>): integer text holes (also@exprof
typeintin.nwui) go to the host as a number (newSetTextIntop) instead of a C# string.- Primitives for component libraries (see
Building component libraries and the new
samples/Primitives):- Element calls:
Element.Call(method, args…)and the helpersShowModal,Show,Close,
ShowPopover,HidePopover,TogglePopover,Blur,Select,ScrollIntoView, applied in
order with the other DOM updates.BrowserDom.GetHandle(element)returns the element as a
JSObject. - Document and window listeners:
Html.OnDocument,Html.OnWindow(withwithinfor
outside-click detection) andHtml.OnResize, owned by the current component or effect run. - Synchronous DOM reads:
Element.GetRect,Contains,HasFocus,Html.ActiveElementIdand
Html.Viewport(newIDomQuerieshost interface). They flush pending updates first and
throw while building or inside an effect. DomEvent.TargetId,RelatedTargetId,Inside,RelatedInside,NewStateand
IsTarget(element).Html.Portal(target, …)and thePortalcomponent render content elsewhere in the document.Html.UseId(prefix)for unique ids.Slot<T>(slots with a parameter) with.With(arg).
- Element calls:
- Templates:
@typeparam T [where …]for generic components, generic component tags with
explicit type arguments (<Select TItem="Fruit">),<template slot="Row" context="item">for
Slot<T>properties,@render(slot, arg), and@bind-Prop="signal"on component tags.
inert,novalidate,formnovalidate,default,playsinlineandnomoduleare boolean
attributes.
Changed
- Breaking: on a component tag, an attribute whose name starts lowercase or contains
-is no
longer assigned to a property of that name; it goes toAttributes. Rename such properties to
PascalCase. A component property namedAttributesnow hides the base one. - Breaking: in
.nwuitemplates, aboolwritten into an attribute value
(aria-expanded="@open") renders as"true"/"false"instead of"True"/"False", which is
what ARIA and CSS selectors such as[aria-selected=true]expect. Update selectors and tests
that match the capitalized value. - Clearing or replacing a keyed list (
Each/For) removes the old rows with oneRemoveRangeop
instead of oneRemoveper row. When the list is its parent's only content, the browser host
empties the parent in one call.
NetWasm.UI 0.10.0
NetWasm.Sdk 0.14.2. NetWasm now includes its framework (LINQ, System.Text.Json, HttpClient,
regular expressions, XML and more) in every netwasm0.1 project, and apps can use NuGet
packages built for .NET Standard. The demo app's Wasm drops from 92 to 88 KB (Brotli).
Upgrading: set "NetWasm.Sdk": "0.14.2" under msbuild-sdks in your global.json, and
remove references to NetWasm.System.* packages such as NetWasm.System.Net.Http and
NetWasm.System.Text.Json: the framework includes them now.
Added
- Libraries and packages: NuGet and .NET Standard packages, what fails at
run time, component libraries with.nwuifiles, and what libraries cost in size.
Changed
- NetWasm.Sdk 0.13.0 → 0.14.2.
samples/Fetchno longer references theNetWasm.System.*
packages; its Wasm drops from 463 to 435 KB (Brotli).
NetWasm.UI 0.9.0
NetWasm 0.13.0 with its NetWasmGC collector, and the first per-row speedups from the profile in
#2, contributed by @zion-sati. The demo app's
Wasm drops from 108 to 92 KB (Brotli), and allocation-heavy work is up to 2× faster. See
Benchmarks.
Upgrading: set "NetWasm.Sdk": "0.13.0" under msbuild-sdks in your global.json, and any
NetWasm.System.* packages to 0.13.0. To use NetWasmGC like the template does, add
<NetWasmGarbageCollector>NetWasm</NetWasmGarbageCollector> to your app's project file.
Added
TemplateInstance.With(hole, content)overloads for one, two and three pieces of content, so the
common case allocates noparamsarray. Existing code, including the generated.nwui
templates, picks them up when it is rebuilt.benchmarks/Runner --gc NetWasm,Compactadds the Oz app built with each named NetWasm collector,
so a run compares collectors side by side.
Changed
- NetWasm.Sdk 0.13.0 (was 0.12.2). The Counter sample's Wasm is 17% smaller (Brotli, at
Oz, with
the same collector). - The template, the samples, the site and the benchmark app use NetWasm's NetWasmGC collector
(<NetWasmGarbageCollector>NetWasm</NetWasmGarbageCollector>): it allocates small objects inline
and collects faster than the default Compact collector, for about 1.6 KB more download. An app
that removes the property keeps Compact. - NetWasm 0.13.0 programs no longer carry type names, so
GetType().Namereadstype#<id>unless
NetWasmTypeNameswrites the names beside the program (on in Debug). NetWasm.UI does not read
type names. nwui.domkeeps the page's nodes in an array indexed by node id instead of aMap, and the
renderer reuses the ids of released nodes (a template clone reuses a released block of its size),
so the array stays dense in a long-running app. A node handle used after its scope disposed it
now reaches whichever node reuses the id rather than failing; as before, such use is a bug.Node.Dispose()andTemplateInstance.Dispose()release their ids at most once, so disposing
twice cannot hand one id to two live nodes. Disposing a template-hole handle (Root,
Element(hole)) does nothing; itsTemplateInstancereleases it.- Counter size budget tightened to 96 KiB Wasm / 144 KiB total (Brotli).
NetWasm.UI 0.8.0
The first screen can now be rendered into the HTML at publish time, so visitors see content
before the Wasm has loaded:
<PropertyGroup>
<NetWasmUIPrerender>true</NetWasmUIPrerender>
<NetWasmUIPrerenderShell>404.html</NetWasmUIPrerenderShell>
</PropertyGroup>
<ItemGroup>
<NetWasmUIPrerenderRoute Include="/about;/blog" />
</ItemGroup>This is a snapshot, not hydration: links work right away, but event handlers start with the
app, which then replaces the markup. Hydration is planned next. The build runs the published
Wasm in the Node that NetWasm ships, so nothing more needs to be installed. See
Why Node and not .NET?.
Added
- Prerendering (opt-in): with
NetWasmUIPrerender=true,dotnet publishruns the app in Node
for/and eachNetWasmUIPrerenderRoute, and writes the rendered HTML into the mount
element ofindex.html,about.htmland so on. Content shows before the Wasm has loaded, and
the app replaces it when it starts.NetWasmUIPrerenderShellwrites a bare page, e.g.
404.html, for the SPA fallback. See Prerendering. - The project website prerenders its home, examples and benchmarks pages.
nwui-devserves/aboutfromabout.htmlwhen it exists, then404.html, then
index.html, as static hosts do.