examples/

directory
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT

README

Examples

Location: examples/

This directory contains the framework examples and shared static assets.

Current Status

  • The example catalog is now a first-class documented surface rather than a loose folder listing.
  • go run ./tools/gwc examples is the primary current way to browse the catalog from the repo root.

Serve Examples

From the repo root:

go run ./tools/gwc examples

Then open:

  • http://127.0.0.1:8090/examples
  • http://127.0.0.1:8090/examples/public-examples-site/

The /examples route redirects into the public examples site. If you need the raw auto-generated folder listing for diagnostics, use /examples/list.

Build Public Site WASM

To refresh the public examples site shell and the first embedded example binary locally:

go run ./tools/gwc examples build-public-site

That command builds:

  • public-examples-site.wasm into the launcher examples wasm directory
  • counter.wasm into the launcher examples wasm directory
  • mirrored copies into examples/static/bin/ for direct static preview tools such as VS Code Live Server
  • a staged embedded copy at examples/public-examples-site/assets/bins/counter.wasm
  • a refreshed source mirror of examples/public/ under examples/public-examples-site/assets/code/

Example Inventory

The example set is now organized as a catalog. Use the grouped landing page at /examples for browsing, and use the mapping below when you want the quickest reference for a specific public API.

Every feature-isolated catalog page is expected to answer three questions clearly: what the tool is for, what the user-facing behavior looks like, and how the implementation is wired. If an example stops doing one of those jobs, it should be treated as documentation debt rather than just a cosmetic issue.

Current Boundary

  • Shipped: a browsable example catalog, dedicated example browser coverage via Playwright-Go wrappers, and integrated examples that act as reference surfaces for larger app shapes.
  • Not shipped: a promise that every example is a production starter template or that every example is kept runnable through every possible serving path.
  • Use the examples to understand supported APIs and composed flows; use the package docs and workflow docs for policy boundaries.
Integrated Apps

Larger, multi-feature reference surfaces. These combine several primitives to show how they compose in realistic apps:

  • examples/public/single-shell-auth: one running WASM shell that keeps marketing, sign-in, and a guarded workspace in one router tree with bounded return-to recovery and no full-page auth detour.
  • examples/server/server-side-rendering-routing: the metadata-heavy SSR routing reference — request-time HTML, route bootstrap reuse, head.Render(...) output, and the ownership boundary between first-paint SSR metadata and later hydrated navigation.
  • examples/server/atlas-commerce-os: the production-shaped SSR reference server — shared UI, SSR, hydration, server-owned routes, mutations, static assets, and reviewer-facing docs.
  • examples/server/server-side-rendering-secure-forms: request-time rendered forms with CSRF validation, multipart uploads, validation round-trips, 303 redirects, and the progressive half of the server-action contract.

Use the integrated apps to see how multiple primitives compose in one realistic surface. Use the feature-isolated pages when you want the clearest statement of a single API or tool's purpose.

Feature-Isolated Catalog

Every public API has a dedicated, slug-named example under examples/public/<slug>/ (for example examples/public/use-state, examples/public/route-loaders, examples/public/async-boundary). The authoritative, generated catalog — title, API surface, tags, and source links for every example — is examples/public-examples-site/assets/data/catalog.json, browsable via:

go run ./tools/gwc examples

The catalog is generated from the example sources, so it never drifts from the on-disk set. Prefer it over a hand-maintained list: an enumerated inventory here would silently rot the next time an example is renamed — the failure this section used to demonstrate when it still listed the removed numbered (NN-slug) layout.

Hot Reload Workflow

For a single app surface, enable the public hotreload package in that app and run the dev server:

go run ./tools/gwc dev -app .\examples\public\hot-reload\main.go -root .\examples\public\hot-reload

Use gwc examples when you want to browse many examples. Use gwc dev when you want rebuild-on-save and state-preserving reload for one specific app.

Shared Static Assets

examples/static/ contains assets shared across example pages, including:

  • script/wasm_exec.js
  • shared CSS
  • shared images
  • common HTML entrypoints

Generated wasm binaries for examples belong under bin/examples/ and should not be committed unless there is a deliberate reason to do so. Example pages still load them via /static/bin/... through the local example servers.

Running Example Browser Tests

The examples/ directory has dedicated browser smoke suites for example-oriented testing, powered by Go playwright-go wrappers under test/playwrightgo/examples.

If you are working on the main framework regression suites, use test/ instead. If you are specifically validating example pages, use these commands from the repo root:

  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestExamplesAll -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestCatalog -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestSSRServerRouting -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestAtlasSSR -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestStartup -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestAtlasStartup -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestChatWizard -v
  • go test -tags playwrightgo ./test/playwrightgo/examples -run TestExample201BrowserBenchmarkReport -v

From the repo root, go run ./tools/gwc test -lane browser now runs the main browser lane.

For the developer-facing manual verification checklist that covers the example catalog, see examples/MANUAL_TESTING.md.

Notes

  • Older docs referenced ad hoc live reload commands as the primary example workflow. The primary documented path is now gwc examples.
  • The browser-compiler example may generate a large local package archive tree under examples/public/browser-compiler/static/pkg/. That output is ignored and should stay out of git.

Directories

Path Synopsis
internal
public
advanced-form command
agent-demo command
Command agent-demo is a tiny app whose entire visible state lives in atoms, so an AI agent can change the title, counter, message, and colors live over the agent bridge while you watch in the browser.
Command agent-demo is a tiny app whose entire visible state lives in atoms, so an AI agent can change the title, counter, message, and colors live over the agent bridge while you watch in the browser.
async-boundary command
bind-to command
blog command
browser-interop command
browser-router command
calculator command
code-splitting command
context-api command
counter command
create-element command
cross-tab-sync command
devtools command
devtools-panel command
disclosure-demo command
Command disclosure-demo renders the WAI-ARIA disclosure pattern (the `gwc add disclosure` component shape) as a real wasm app, so the browser-lane test can drive the interaction: a button toggles aria-expanded and shows/hides the controlled region.
Command disclosure-demo renders the WAI-ARIA disclosure pattern (the `gwc add disclosure` component shape) as a real wasm app, so the browser-lane test can drive the interaction: a button toggles aria-expanded and shows/hides the controlled region.
dom-ref command
Command dom-ref is the runnable e2e fixture for the G2 DOM-ref primitive (ui.UseDOMRef + shorthand.Ref).
Command dom-ref is the runnable e2e fixture for the G2 DOM-ref primitive (ui.UseDOMRef + shorthand.Ref).
error-boundary command
error-overlay command
feature-flags command
fetch command
flip-demo command
Command flip-demo renders a keyed list that reorders on click and computes the FLIP invert transform for each item from its measured before/after rects (via anim.ComputeFLIP), so the browser-lane test can verify keyed-list FLIP in a real browser.
Command flip-demo renders a keyed list that reorders on click and computes the FLIP invert transform for each item from its measured before/after rects (via anim.ComputeFLIP), so the browser-lane test can verify keyed-list FLIP in a real browser.
flip-keyed-list command
form command
fragment command
global-events command
Command global-events is the e2e fixture for G9 (ui.UseGlobalKey): a child component owns a document-level keydown listener and increments a counter that lives in the parent (so it survives the child's unmount/remount).
Command global-events is the e2e fixture for G9 (ui.UseGlobalKey): a child component owns a document-level keydown listener and increments a counter that lives in the parent (so it survives the child's unmount/remount).
goroutines command
hash-router command
hot-reload command
html-forms command
html-tag command
hydration command
lazy-loading command
locale-routing command
locale-switcher command
localfirst-crdt command
named-slots command
nested-routes command
omi command
overlay-anchor command
overlay-stack command
plugin-host command
portal-selector command
portal-target command
portals command
portfolio-site command
radiogroup command
Command radiogroup is the e2e fixture for U5: an interactive WAI-ARIA radio group built by composing ui.UseCompositeNavigation (the existing roving- tabindex engine) with role=radio/aria-checked and the G2 DOM ref for focus-follows-selection — no per-control reimplementation.
Command radiogroup is the e2e fixture for U5: an interactive WAI-ARIA radio group built by composing ui.UseCompositeNavigation (the existing roving- tabindex engine) with role=radio/aria-checked and the G2 DOM ref for focus-follows-selection — no per-control reimplementation.
raw-handler command
raw-html command
Command raw-html is the e2e fixture for the G3 markup nodes (html.RawHTML / RawHTMLUnsafe): it renders sanitized rich text and a trusted inline SVG, each parsed into real nodes (never innerHTML).
Command raw-html is the e2e fixture for the G3 markup nodes (html.RawHTML / RawHTMLUnsafe): it renders sanitized rich text and a trusted inline SVG, each parsed into real nodes (never innerHTML).
ready-signal command
Command ready-signal is the e2e fixture for G16 (ui.OnReady + the gwc:ready DOM event): it records the Go ready callback firing, and the host page listens for the dispatched gwc:ready event — both after the first commit.
Command ready-signal is the e2e fixture for G16 (ui.OnReady + the gwc:ready DOM event): it records the Go ready callback firing, and the host page listens for the dispatched gwc:ready event — both after the first commit.
route-loaders command
route-params command
route-query command
router-guards command
router-metadata command
semantic-html command
snapshot-now command
state-atoms command
static-islands command
text-input command
third-party-js
Package thirdpartyjs is a worked example of integrating a third-party JavaScript library behind a TYPED Go bridge using interop.ImportModule, with a pure-Go fallback so the exact same code runs on the server (SSR/native) where no JS module loader exists.
Package thirdpartyjs is a worked example of integrating a third-party JavaScript library behind a TYPED Go bridge using interop.ImportModule, with a pure-Go fallback so the exact same code runs on the server (SSR/native) where no JS module loader exists.
todo-advanced command
todo-basic command
toggle command
typed-css command
Command typed-css is the runnable demo for the F3 typed-CSS package.
Command typed-css is the runnable demo for the F3 typed-CSS package.
typed-css-tokens-demo
Package typedcsstokensdemo shows `gwc css gen` against a real theme: theme.json is the source of truth, `gwc css gen -theme theme.json` writes the typed token constants in css_tokens_gen.go, and a typo'd token reference is then a compile error instead of a silent transparent fallback.
Package typedcsstokensdemo shows `gwc css gen` against a real theme: theme.json is the source of truth, `gwc css gen -theme theme.json` writes the typed token constants in css_tokens_gen.go, and a typo'd token reference is then a compile error instead of a silent transparent fallback.
typed-events command
typed-routes-demo
Package typedroutesdemo shows `gwc routes gen` against a real package: declare route contracts as exported package vars, run `gwc routes gen`, and get typed Link* constructors in routes_gen.go that turn a typo'd path param into a compile error.
Package typedroutesdemo shows `gwc routes gen` against a real package: declare route contracts as exported package vars, run `gwc routes gen`, and get typed Link* constructors in routes_gen.go that turn a typo'd path param into a compile error.
ui-render command
use-atom command
use-callback command
use-channel command
use-computed command
use-debounced command
use-derived command
use-effect command
use-fetch command
use-form command
use-head command
Command use-head is the runnable e2e fixture for head.UseHead: it applies a Document's title and head tags (description, canonical, OpenGraph) to the live document on mount, and changes them when a button switches the logical page — exercised by the playwright e2e to prove client-side head updates (not just title) without a full reload.
Command use-head is the runnable e2e fixture for head.UseHead: it applies a Document's title and head tags (description, canonical, OpenGraph) to the live document on mount, and changes them when a button switches the logical page — exercised by the playwright e2e to prove client-side head updates (not just title) without a full reload.
use-id command
use-inspect command
use-lazy-node command
use-navigate command
use-previous command
use-query command
use-reducer command
use-ref command
use-resource command
use-revalidator command
use-snapshot command
use-state command
use-task command
use-throttled command
web-components command
assets/code/agent-demo command
Command agent-demo is a tiny app whose entire visible state lives in atoms, so an AI agent can change the title, counter, message, and colors live over the agent bridge while you watch in the browser.
Command agent-demo is a tiny app whose entire visible state lives in atoms, so an AI agent can change the title, counter, message, and colors live over the agent bridge while you watch in the browser.
assets/code/disclosure-demo command
Command disclosure-demo renders the WAI-ARIA disclosure pattern (the `gwc add disclosure` component shape) as a real wasm app, so the browser-lane test can drive the interaction: a button toggles aria-expanded and shows/hides the controlled region.
Command disclosure-demo renders the WAI-ARIA disclosure pattern (the `gwc add disclosure` component shape) as a real wasm app, so the browser-lane test can drive the interaction: a button toggles aria-expanded and shows/hides the controlled region.
assets/code/dom-ref command
Command dom-ref is the runnable e2e fixture for the G2 DOM-ref primitive (ui.UseDOMRef + shorthand.Ref).
Command dom-ref is the runnable e2e fixture for the G2 DOM-ref primitive (ui.UseDOMRef + shorthand.Ref).
assets/code/flip-demo command
Command flip-demo renders a keyed list that reorders on click and computes the FLIP invert transform for each item from its measured before/after rects (via anim.ComputeFLIP), so the browser-lane test can verify keyed-list FLIP in a real browser.
Command flip-demo renders a keyed list that reorders on click and computes the FLIP invert transform for each item from its measured before/after rects (via anim.ComputeFLIP), so the browser-lane test can verify keyed-list FLIP in a real browser.
assets/code/global-events command
Command global-events is the e2e fixture for G9 (ui.UseGlobalKey): a child component owns a document-level keydown listener and increments a counter that lives in the parent (so it survives the child's unmount/remount).
Command global-events is the e2e fixture for G9 (ui.UseGlobalKey): a child component owns a document-level keydown listener and increments a counter that lives in the parent (so it survives the child's unmount/remount).
assets/code/omi command
assets/code/radiogroup command
Command radiogroup is the e2e fixture for U5: an interactive WAI-ARIA radio group built by composing ui.UseCompositeNavigation (the existing roving- tabindex engine) with role=radio/aria-checked and the G2 DOM ref for focus-follows-selection — no per-control reimplementation.
Command radiogroup is the e2e fixture for U5: an interactive WAI-ARIA radio group built by composing ui.UseCompositeNavigation (the existing roving- tabindex engine) with role=radio/aria-checked and the G2 DOM ref for focus-follows-selection — no per-control reimplementation.
assets/code/raw-html command
Command raw-html is the e2e fixture for the G3 markup nodes (html.RawHTML / RawHTMLUnsafe): it renders sanitized rich text and a trusted inline SVG, each parsed into real nodes (never innerHTML).
Command raw-html is the e2e fixture for the G3 markup nodes (html.RawHTML / RawHTMLUnsafe): it renders sanitized rich text and a trusted inline SVG, each parsed into real nodes (never innerHTML).
assets/code/ready-signal command
Command ready-signal is the e2e fixture for G16 (ui.OnReady + the gwc:ready DOM event): it records the Go ready callback firing, and the host page listens for the dispatched gwc:ready event — both after the first commit.
Command ready-signal is the e2e fixture for G16 (ui.OnReady + the gwc:ready DOM event): it records the Go ready callback firing, and the host page listens for the dispatched gwc:ready event — both after the first commit.
assets/code/third-party-js
Package thirdpartyjs is a worked example of integrating a third-party JavaScript library behind a TYPED Go bridge using interop.ImportModule, with a pure-Go fallback so the exact same code runs on the server (SSR/native) where no JS module loader exists.
Package thirdpartyjs is a worked example of integrating a third-party JavaScript library behind a TYPED Go bridge using interop.ImportModule, with a pure-Go fallback so the exact same code runs on the server (SSR/native) where no JS module loader exists.
assets/code/typed-css command
Command typed-css is the runnable demo for the F3 typed-CSS package.
Command typed-css is the runnable demo for the F3 typed-CSS package.
assets/code/typed-css-tokens-demo
Package typedcsstokensdemo shows `gwc css gen` against a real theme: theme.json is the source of truth, `gwc css gen -theme theme.json` writes the typed token constants in css_tokens_gen.go, and a typo'd token reference is then a compile error instead of a silent transparent fallback.
Package typedcsstokensdemo shows `gwc css gen` against a real theme: theme.json is the source of truth, `gwc css gen -theme theme.json` writes the typed token constants in css_tokens_gen.go, and a typo'd token reference is then a compile error instead of a silent transparent fallback.
assets/code/typed-routes-demo
Package typedroutesdemo shows `gwc routes gen` against a real package: declare route contracts as exported package vars, run `gwc routes gen`, and get typed Link* constructors in routes_gen.go that turn a typo'd path param into a compile error.
Package typedroutesdemo shows `gwc routes gen` against a real package: declare route contracts as exported package vars, run `gwc routes gen`, and get typed Link* constructors in routes_gen.go that turn a typo'd path param into a compile error.
assets/code/use-head command
Command use-head is the runnable e2e fixture for head.UseHead: it applies a Document's title and head tags (description, canonical, OpenGraph) to the live document on mount, and changes them when a button switches the logical page — exercised by the playwright e2e to prove client-side head updates (not just title) without a full reload.
Command use-head is the runnable e2e fixture for head.UseHead: it applies a Document's title and head tags (description, canonical, OpenGraph) to the live document on mount, and changes them when a button switches the logical page — exercised by the playwright e2e to prove client-side head updates (not just title) without a full reload.
server
ai-chat-wizard/client/cachecore
Package cachecore provides reusable client-side cache and outbox mechanics.
Package cachecore provides reusable client-side cache and outbox mechanics.
ai-chat-wizard/client/catalog
Package catalog provides the WASM-side emergency fallback localization bundle.
Package catalog provides the WASM-side emergency fallback localization bundle.
ai-chat-wizard/server/app
auth_rpc.go owns the session bootstrap and auth RPC cluster.
auth_rpc.go owns the session bootstrap and auth RPC cluster.
The GoWebComponents docs site, written entirely in Go as a GWC application.
The GoWebComponents docs site, written entirely in Go as a GWC application.
testing
runtime2-status command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL