bigskysoftware / bigskysoftware/htmx

hx-sse:close does not work when there is no data

Open Beginner friendly
#3,920 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

I am using/testing HTMX `v4.0.0-beta6` right now, and I have the following test file (runnable via `uv`):

```python
#! /usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "sse-starlette~=3.0",
# "starlette~=1.0",
# "uvicorn[standard]~=0.51.0",
# ]
# ///
import asyncio
import collections.abc

import sse_starlette
import starlette.applications
import starlette.requests
import starlette.responses
import starlette.routing
import uvicorn

CONTENT = """







HTMX SSE Playground



"""

async def homepage(_: starlette.requests.Request) -> starlette.responses.HTMLResponse:
return starlette.responses.HTMLResponse(content=CONTENT)

async def sse_endpoint(
_: starlette.requests.Request,
) -> sse_starlette.EventSourceResponse:
async def values() -> collections.abc.AsyncIterable[sse_starlette.ServerSentEvent]:
for idx in range(10):
yield sse_starlette.ServerSentEvent(data=f"data {idx}")
await asyncio.sleep(1)

# if data=None, `hx-sse:close` does not work
# yield sse_starlette.ServerSentEvent(event="done")
yield sse_starlette.ServerSentEvent(event="done", data="")

return sse_starlette.EventSourceResponse(content=values())

app = starlette.applications.Starlette(
routes=[
starlette.routing.Route("/sse", sse_endpoint, methods=["GET"]),
starlette.routing.Route("/", homepage, methods=["GET"]),
]
)

if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8080)
```

Currently, `hx-sse:close` does not close the long-running `hx-sse:connect` session when an event `done` is received with _no_ data. Is this expected behavior? For it to work properly, I need to send an empty string.

Contributor guide

Open the contributing guide

Research direction

Start by running the provided uv script and reproduce the SSE stream from sse_endpoint, comparing the done event with data="" against the event with no data. Inspect the hx-sse extension loaded from dist/ext/hx-sse.min.js and verify that receiving done closes the hx-sse:connect session in both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.