contracts.rules_suspense_defer

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

Undiscoverable Suspense deferred-block contract.

Suspense(...)defers awaitable context values: the shell renders with each deferred key set to theDEFERREDsentinel, then every block whose depends_onreferences a deferred key is re-rendered…

Undiscoverable Suspense deferred-block contract.

Suspense(...)defers awaitable context values: the shell renders with each deferred key set to theDEFERREDsentinel, then every block whose depends_onreferences a deferred key is re-rendered and streamed as an OOB swap. Blocks are discovered automatically via kida'sblock_metadata().

When a deferred key is used by the template (it self-declares the key via "<NAME>" in __chirp_defer_pending__ or the <NAME> is deferredtest) but no block depends on it, auto-discovery finds nothing to re-render. At runtimerender_suspense already fails loud (ConfigurationErrorbefore any shell bytes flush), but the developer only learns when a request hits the route. This rule promotes that failure to a startupapp.check() WARNINGand recommends thedefer_blocks=(...)escape hatch.

Detection is scoped to templates that self-declare their defer keys (the same reliable static signalchirp.contracts.rules_defer_falsyuses), so it cannot statically know whichSuspensekwargs are awaitable but also never false-positives on arbitrary{% if x %} or sync-only Suspenseusage. Templates whose route handler passesdefer_blocks=bypass auto-discovery entirely, so they are exempt. Severity isWARNING-- the rule ships informational by default and can be promoted toERRORvia app.override_contract_severity("suspense_defer", Severity.ERROR)in CI.

contracts.rules_suspense_defer

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

_declared_defer_keys
function
def _declared_defer_keys(source: str) -> set[str]

Collect keys a template self-declares as deferred.

Mirrorscheck_defer_falsy_conditionals: a key counts as declared when the template references it via"<NAME>" in __chirp_defer_pending__or the<NAME> is deferredtest.

Parameters

Name Type Default Description
source str
_discoverable_root_keys
function
def _discoverable_root_keys(env: Environment, template_name: str) -> set[str] | None

Return the set of context-key roots any block depends on.

Mirrors_find_deferred_blocks in templating/suspense.py: a deferred key is auto-discoverable when some block'sdepends_onpath has it as the root (dep_path.split(".")[0]). Returns Nonewhen the template cannot be loaded/analyzed so the caller skips silently rather than false-positive.

Parameters

Name Type Default Description
env Environment
template_name str
check_suspense_undiscoverable
function
def check_suspense_undiscoverable(template_sources: Mapping[str, str], kida_env: Environment | None, *, defer_blocks_templates: frozenset[str] = frozenset()) -> list[ContractIssue]

Flag Suspense templates whose declared defer keys are undiscoverable.

Only fires when a template explicitly declares a key as deferred (via __chirp_defer_pending__ membership or the is deferredtest) and no block'sdepends_on has that key as its root. One WARNINGper (template, key) pair.

defer_blocks_templateslists templates whose route handler passes defer_blocks= to Suspense(...); those bypass auto-discovery, so they are exempt from the check.

Parameters

Name Type Default Description
template_sources Mapping[str, str]
kida_env Environment | None
defer_blocks_templates frozenset[str] frozenset()

View source · /home/runner/work/chirp/chirp/site/../src/chirp/contracts/rules_suspense_defer.py:1