Skip to main content

Crate wabot_feature_ui_controller

Crate wabot_feature_ui_controller 

Source
Expand description

§wabot-feature-ui-controller

Server-rendered pages with islands — port of wabot-ts/src/feature/ui-controller. Renderer-agnostic: this crate owns routing, the document shell, the island protocol, actions and boosted navigation, and knows nothing about how a view’s HTML was produced. wabot-addon-ui-maud is the default renderer.

ⓘ
#[singleton]
#[derive(Default)]
pub struct PanelController;

#[ui_controller("/panel", app, layout)]
impl PanelController {
    fn layout(&self, outlet: ViewBody) -> ViewBody {
        html! { nav { a href="/panel" { "Home" } } (outlet) }.into_view()
    }

    #[view("/")]
    async fn index(&self) -> UiResult<ViewBody> {
        Ok(html! { h1 { "Panel" } (island("counter", &Props { start: 0 }, html! { … })) }
            .into_view())
    }

    #[action("save")]
    async fn save(&self, req: SaveRequest) -> UiResult<Saved> { … }
}

let router = PanelController::register_ui_routes(&c, ui_router());
run_ui_controllers(router, RestServerConfig::from_env()).await?;

§Shape of a request

  • GET <controller><view> — middleware, handler, render, document. With X-Wabot-Nav: 1 on an app controller it answers a JSON fragment instead, and both forms carry an ETag so a repeat visit gets a 304.
  • POST <controller>/_action/<name> — middleware, handler, JSON.

§Not ported

The esbuild bundler, CSS modules, the dev server, and StaticPageCache (SSG/ISR). Islands here are plain JS the app serves; there is no build step. See docs/ui-renderer-review.md.

Re-exports§

pub use assets::content_type_for;
pub use assets::embedded_assets;
pub use assets::EmbeddedAsset;
pub use assets::EmbeddedAssets;
pub use document::escape_attr;
pub use document::escape_html;
pub use document::render_document;
pub use document::AttrValue;
pub use document::DocumentOptions;
pub use island::island_host;
pub use island::outlet_host;
pub use island::serialize_props;
pub use island::IslandRef;
pub use nav::app_bootstrap_script;
pub use nav::etag_for;
pub use nav::FragmentPayload;
pub use nav::CLIENT_RUNTIME_JS;
pub use nav::CLIENT_RUNTIME_PATH;
pub use nav::NAV_HEADER;
pub use runtime::action_route;
pub use runtime::client_runtime_response;
pub use runtime::join_route;
pub use runtime::page_response;
pub use runtime::redirect_response;
pub use runtime::render_view_page;
pub use runtime::render_view_response;
pub use runtime::static_variant;
pub use runtime::synthetic_parts;
pub use runtime::version_precondition;
pub use runtime::wants_fragment;
pub use runtime::with_version_etag;
pub use runtime::RenderedView;
pub use runtime::ViewRenderConfig;
pub use scope::add_script;
pub use scope::add_style;
pub use scope::in_scope;
pub use scope::record_island;
pub use scope::set_meta;
pub use scope::set_title;
pub use scope::with_scope;
pub use scope::with_scope_async;
pub use scope::RenderScope;
pub use static_cache::StaticPage;
pub use static_cache::StaticPageCache;
pub use static_cache::StaticVariant;
pub use tsx::TsxConfig;
pub use tsx::TsxError;
pub use view::Redirect;
pub use view::UiError;
pub use view::UiResult;
pub use view::ViewBody;
pub use view::ViewOutcome;
pub use axum;

Modules§

assets
Serving static assets from inside the binary.
dev
Development server: edit a .tsx view, a stylesheet or an island and see it without restarting the process.
document
HTML escaping + the document shell. Port of feature/ui-controller/document/ (escape.ts, renderDocument.ts).
island
The island protocol — the contract between server markup and the client runtime. Port of feature/ui-controller/island/.
nav
Boosted navigation — server half. Port of the fragment protocol in runUiControllers.ts plus the client runtime it drives.
runtime
Per-request orchestration, called by the code #[ui_controller] emits. Port of the request path in runUiControllers.ts.
scope
The render scope — how a view communicates back to the framework.
static_cache
Static generation + ISR. Port of StaticPageCache.ts and the serveStatic / regenerate path in runUiControllers.ts.
tsx
Server-rendering TSX views through an embedded QuickJS runtime.
view
What a #[view] method returns.

Structs§

HandlerContext
Per-controller, per-request context handed to every macro-generated handler via axum’s State.
RestServerConfig
Server configuration.

Enums§

RestError

Constants§

DEFAULT_MAX_BODY
Maximum request body size, in bytes, when an endpoint does not say otherwise.

Traits§

Middleware

Functions§

decompose_request
Decompose an axum request into the pieces handlers need.
extract_typed
Extract a typed T and run Validate::validate() on it.
ok_json
Build a 200 JSON response from any serializable value, matching the TS res.status(200).json(response ?? null) line.
run_middlewares
Resolve a middleware chain from the request-scoped child container, run each one, and short-circuit on the first error. Mirrors the TS for (const middleware of middlewares) { await middleware.handle(...) } loop in runRestControllers.
run_ui_controllers
Serve the UI router. Thin alias over the REST server so a process exposing both uses one listener; call wabot_feature_rest_controller::run_rest_controllers directly if you merged the routers yourself.
ui_router
A router pre-loaded with the framework’s own routes — currently the client runtime at /_wabot/client.js. Start from this instead of Router::new() so islands and boosted navigation work.

Type Aliases§

MiddlewareInstance
Type-erased handle so the macro-generated registration code can stash per-endpoint middleware lists without knowing the concrete types.