server.sse_lifecycle

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

SSE lifecycle bridge — connection status for[sse-connect]elements.

htmx's SSE extension creates anEventSourceinternally but doesn't surface connection lifecycle to the DOM in a way that's easy to style or…

SSE lifecycle bridge — connection status for[sse-connect]elements.

htmx's SSE extension creates anEventSourceinternally but doesn't surface connection lifecycle to the DOM in a way that's easy to style or hook into. This script bridges that gap.

On everyhtmx:sseOpen and htmx:sseErrorevent, it updates a data-sse-state attribute on the [sse-connect]element:

  • "connected"— EventSource is open
  • "disconnected"— EventSource errored or closed

This enables pure-CSS connection indicators::

[data-sse-state="disconnected"] .sse-indicator { display: block; }
[data-sse-state="connected"] .sse-indicator { display: none; }

It also dispatcheschirp:sse:connected and chirp:sse:disconnected custom events on the element for JS hooks.

Injected into full-page HTML responses viaHTMLInjectmiddleware. Controlled byAppConfig(sse_lifecycle=True) (default: True).

server.sse_lifecycle

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

sse_lifecycle_snippet
function
def sse_lifecycle_snippet(nonce: str = '') -> str

Build the SSE-lifecycle inline<script>.

When nonce is non-empty the<script> carries a nonce="..." attribute so it survives a nonce-based CSP that no longer ships 'unsafe-inline'.

Parameters

Name Type Default Description
nonce str ''

View source · /home/runner/work/chirp/chirp/site/../src/chirp/server/sse_lifecycle.py:1