Skip to content

feat(events): let a detached handler take wait: false calls outside the queue - #426

Merged
JuroOravec merged 4 commits into
mainfrom
feat/events-detached-calls
Oct 27, 2026
Merged

JuroOravec merged 4 commits into
mainfrom
feat/events-detached-calls

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Closes #155.

What this does

A handler declared with @event(detached=True) never renders and never
changes State. Browser code can call it with
$sendEvent(name, args, {wait: false}) (or Citry.events.send(..., {wait: false})),
and the call goes out at once instead of waiting behind the app's queued
calls:

class Events:
    @event(detached=True)
    def spell_check(self, data: SpellCheckIn):
        return {"typos": find_typos(data.text)}
const result = await this.$sendEvent(
  "spell_check", {text: this.draft}, {wait: false},
);

A detached handler may read State and return data, Dispatch, Redirect,
PushUrl/ReplaceUrl, or Download (with bundle=False).

The rules follow the handler, not the call

The limits apply to every call to a detached handler, whether the browser
sent it at once or queued it. Only wait: false takes a call out of the
queue.

  • The server answers handler_error when a detached handler renders,
    changes State, or ends up with a render or state action from an
    on_event_result extension (that message blames the extension). The
    handler's own renders are checked before encoding, so a forbidden render
    is never built.
  • A call to a detached handler that carries stateUpdates (even {})
    answers invalid_args. The browser never attaches pending $state
    writes to such a call; they wait for the next call to a handler that is
    not detached.
  • The browser rejects a detached result that holds render or state
    before any action runs, and never counts a detached result as a newer
    result for the caller. A detached action without a delay always runs; a
    delayed one follows the usual newer-result rules.
  • latest_wins on a detached handler supersedes across queued and
    wait: false calls to it from the same instance.
  • wait: false on any other handler still rejects with a TypeError that
    names @event(detached=True).

How the build differs from the approved design note

  1. No call-envelope detached field and no detachedCalls capability.
    The server trusts the handler's declaration, so a per-call field would
    only be a second copy that could disagree with it. The only new wire
    field is the manifest handler option detached: true. GET, form, and
    API calls need nothing new.
  2. handler_error instead of a new invalid_result code. The server
    already uses handler_error for results a program gets wrong, such as
    a render with no target.
  3. stateUpdates on a detached call is invalid_args, and the browser
    never sends pending State writes with one.
    Otherwise the writes would
    be applied and then lost, because the result returns no new token.

What changed

  • Protocol (citry-events/1, still version 1): detached handler hint in
    both schemas, both validators, types.ts, the shipped Python copy, the
    constraint registry, a mutation case, the descriptor fixture, and two
    new golden exchanges (detached_data, error_detached_state_updates)
    for a new peek handler on the conformance component. The spec gains a
    "Detached calls" section and updates to the timing, superseding, and
    handler-hint sections.
  • Server: @event(detached=...), the manifest hint, and the dispatcher
    checks.
  • Browser: checkSendOptions, the out-of-queue path in the Vue Events
    bridge, rebuilt events.js and runtime.js, and client.js comments.
  • Editor: the LSP worker reports detached handlers (reading the option
    softly, so an app on citry 0.6.0 still loads), and the generated types
    allow wait: false only for them, in component JavaScript and in
    template expressions.
  • Docs: a "Skip the call queue" section on the actions page, the
    $sendEvent options in the browser API reference, notes on $state, the
    upgrade guide, the migration parity table, and both changelogs.

docs/design/events.md now describes the shipped wait: false (handler
table, queue rules, and the passages that referenced the old rendering
behaviour).

Verification

  • Bridge: 203 node tests, including new tests for the out-of-queue path,
    pending State, newer-result rules both ways, a same-tick custom
    transport, queued calls to detached handlers, mixed superseding, and
    retire/dispose. The key assertions were checked by reverting each fix
    and watching the matching test fail.
  • Python: dispatcher, decorator, manifest, conformance, and LSP tests
    (1405 passed across the Events and LSP suites); e2e page-API tests in
    Chromium; a citry check --types test for templates.
  • Fast gate on the earlier base: green apart from an LSP JSDoc expectation
    this PR changed (updated) and two failures fixed on main since (fix(ui): list citry_ui/components/_reveal.py among the wheel's shipped files #417,
    fix: give the Vue parity check's Node render enough stack for deep pages #408); after rebasing onto 00e447c both pass (the citry_ui wheel
    boundary test, and the render-parity run of the deep-template pages).
  • mypy --platform linux: clean.
  • Two rounds of independent technical review, a separate prose review,
    and a docs cold read; their findings are folded in.

🤖 Generated with Claude Code

JuroOravec and others added 4 commits October 25, 2026 17:26
A handler declared with @event(detached=True) never renders or changes
State, so browser code may call it with $sendEvent(name, args, {wait: false})
without waiting for the component's queued calls. The manifest marks such a
handler with detached: true. The server answers handler_error when a detached
handler renders or changes State, and invalid_args when a call to one carries
stateUpdates. The browser rejects wait: false for any other handler, never
attaches pending State writes to a detached call, and never counts a detached
result as a newer result for the caller.

Closes #155.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Type wait: false as allowed for detached handlers in the editor, keep a
detached result's immediate actions when a queued result lands between
them, check renders before encoding, reject an empty stateUpdates object,
and cover queued calls to detached handlers with tests. Update the docs
and the spec wording the reviews flagged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read the detached option softly in the LSP worker so an app on an older
citry still loads, blame an on_event_result extension for a render or
State action it adds, describe a non-JSON wait value safely, and state
precisely which newer-result rule a detached action without a delay
escapes. Add tests for the worker, the source-analysis flag, the template
type check, the extension messages, and the render refused before encoding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 9f8ee0d into main Oct 27, 2026
20 of 31 checks passed
@JuroOravec
JuroOravec deleted the feat/events-detached-calls branch October 27, 2026 12:28
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.

Events: support sending a call without waiting for earlier calls (wait: false)

1 participant