middleware.debug_fragment_validator

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

Debug-mode validator for fragment responses.

Catches silent failure modes where a fragment response would paint a broken page in the browser:

  • <!DOCTYPEin fragment body (a full page rendered into an outlet).…

Debug-mode validator for fragment responses.

Catches silent failure modes where a fragment response would paint a broken page in the browser:

  • <!DOCTYPEin fragment body (a full page rendered into an outlet).
  • Duplicateid="..."for registered shell-region ids (would collide with the live DOM after the swap).

Only active whenAppConfig.debug=True; auto-registered during _collect_builtin_middlewarewhen an OOB registry is present. Warns by default;strict=Trueraises instead for CI enforcement.

middleware.debug_fragment_validator

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

FragmentValidationError
class

Raised byDebugFragmentValidatorin strict mode when a fragment response leaks full-page markup or duplicate ids.

DebugFragmentValidator
class

Middleware that inspects fragment responses for breakage patterns.

Only inspects bufferedResponse objects with text/htmlcontent whenrender_intent == "fragment" (or "unknown"on an htmx request, matchingHTMLInject's skip rule).

Streaming responses are skipped — buffering them would defeat the point of streaming and the body is rarely available as a single string anyway.

_count_id_occurrences
function
def _count_id_occurrences(body: str, target_id: str) -> int

Countid="target_id" and id='target_id'occurrences.

Parameters

Name Type Default Description
body str
target_id str
_is_selectable_shell_outlet_response
function
def _is_selectable_shell_outlet_response(body: str, request: Request) -> bool

True for app-shell boosted responses meant to be narrowed by hx-select.

The browser owns the inheritedhx-select="#page-content"attribute; it is not sent as a request header. In debug mode this validator sees the pre-selection response, so a correctly selectable shell-outlet response can look like a full document with duplicate shell-region ids. Treat the canonical app-shell shape as valid when the response contains the selector target htmx will extract.

Parameters

Name Type Default Description
body str
request Request

View source · /home/runner/work/chirp/chirp/site/../src/chirp/middleware/debug_fragment_validator.py:1