Skip to content

fix(ui): render whole-page Handler dot as template data, not a tag#190

Merged
linkdata merged 3 commits into
mainfrom
fix/178-page-dot-not-tag
Jul 20, 2026
Merged

fix(ui): render whole-page Handler dot as template data, not a tag#190
linkdata merged 3 commits into
mainfrom
fix/178-page-dot-not-tag

Conversation

@linkdata

Copy link
Copy Markdown
Owner

Summary

Fixes #178. ui.Handler(jw, name, dot) documents that each request renders the named template with dot exposed through With.Dot, with no tag-eligibility restriction. In practice a primitive dot such as a string produced HTTP 200 with an empty body.

Whole-page rendering flowed through Template.render, which unconditionally tag-expands Dot. A string is rejected with tag.ErrIllegalTagType, so render returned before writing anything and ServeHTTP logged-and-discarded the error.

Changes

  • Page dot is no longer a tag. pageTemplate gets its own JawsRender that looks up and executes the template directly (reusing Template.lookup/Template.execute), bypassing tag expansion. The page element cannot re-render itself — its JawsUpdate is a deliberate no-op — so deriving tag identity from the page dot was always inert. Partial ui.Template values are untouched and keep deriving tag identity from their dot.
  • Render failures are observable. ServeHTTP wraps the ResponseWriter in a small recorder; a failure before any output (e.g. a missing template) now returns a clean 500 instead of a blank 200. Once bytes are committed the partial body is left as-is, matching the best-effort execution semantics documented on Template.

Acceptance criteria

  • ui.Handler accepts ordinary html/template data, including strings.
  • Whole-page rendering does not derive tag identity from the page dot.
  • Render failures produce observable HTTP error behavior rather than a blank 200.
  • Preserve partial ui.Template tag behavior.
  • Add public-API regression tests under go test -race.

Testing

  • go test -race ./lib/ui/ and go test -race ./... — pass
  • go vet, gofmt -l, gofumpt -l, staticcheck ./lib/ui/ — clean
  • go test -cover ./lib/ui/ — 100.0% of statements

linkdata added 3 commits July 20, 2026 20:35
ui.Handler documents that each request renders the named template with dot
exposed through With.Dot, with no tag-eligibility restriction. Whole-page
rendering went through Template.render, which tag-expands the dot; a primitive
value such as a string was rejected with ErrIllegalTagType and ServeHTTP logged
and discarded the error, yielding HTTP 200 with an empty body.

Give pageTemplate its own JawsRender that looks up and executes the template
directly, so the page dot is treated as ordinary html/template data and never
as a JaWS tag. The page element cannot re-render itself (JawsUpdate is a no-op),
so its tag registration was always inert; partial ui.Template values keep
deriving tag identity from their dot.

Wrap the ResponseWriter so ServeHTTP sends a 500 for a render failure that
occurs before any output (for example a missing template) instead of a blank
200. Once bytes are committed the partial body is left as-is, matching the
best-effort execution semantics documented on Template.

Fixes #178
Add public-API regression tests for ui.Handler: a string dot and a struct
dot render (the issue #178 repro), a missing template returns HTTP 500 with a
logged error, an execute error after output keeps the partial 200 body, a
partial ui.Template still rejects a string dot, and a tag-valued page dot still
renders. Package coverage stays at 100% under -race.
Render each request through a fresh per-request *pageTemplate so the UI stays
comparable as a map key regardless of the page dot. Ordinary html/template data
such as a slice or map is not usable as a tag; a bare pageTemplate value
carrying it in its Dot any field is not comparable at runtime and trips the
comparability check in Request.NewElement, which panics under -race. This
matches the pointer-UI convention used by the html widgets (for example *Div).

Add a regression test rendering slice and map page dots (guarded with
tag.NewErrNotComparable so it exercises the non-comparable path), and reword the
handler tests to describe current behavior.
@linkdata
linkdata marked this pull request as ready for review July 20, 2026 18:54
@linkdata
linkdata merged commit 5d38e35 into main Jul 20, 2026
7 checks passed
@linkdata
linkdata deleted the fix/178-page-dot-not-tag branch July 20, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui.Handler rejects ordinary page-template dot values as illegal tags

1 participant