Repository navigation
feat(events): let a detached handler take wait: false calls outside the queue - #426
Merged
Merged
Conversation
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #155.
What this does
A handler declared with
@event(detached=True)never renders and neverchanges State. Browser code can call it with
$sendEvent(name, args, {wait: false})(orCitry.events.send(..., {wait: false})),and the call goes out at once instead of waiting behind the app's queued
calls:
A detached handler may read State and return data,
Dispatch,Redirect,PushUrl/ReplaceUrl, orDownload(withbundle=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: falsetakes a call out of thequeue.
handler_errorwhen a detached handler renders,changes State, or ends up with a
renderorstateaction from anon_event_resultextension (that message blames the extension). Thehandler's own renders are checked before encoding, so a forbidden render
is never built.
stateUpdates(even{})answers
invalid_args. The browser never attaches pending$statewrites to such a call; they wait for the next call to a handler that is
not detached.
renderorstatebefore 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_winson a detached handler supersedes across queued andwait: falsecalls to it from the same instance.wait: falseon any other handler still rejects with aTypeErrorthatnames
@event(detached=True).How the build differs from the approved design note
detachedfield and nodetachedCallscapability.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, andAPI calls need nothing new.
handler_errorinstead of a newinvalid_resultcode. The serveralready uses
handler_errorfor results a program gets wrong, such asa render with no target.
stateUpdateson a detached call isinvalid_args, and the browsernever sends pending State writes with one. Otherwise the writes would
be applied and then lost, because the result returns no new token.
What changed
citry-events/1, still version 1):detachedhandler hint inboth schemas, both validators,
types.ts, the shipped Python copy, theconstraint registry, a mutation case, the descriptor fixture, and two
new golden exchanges (
detached_data,error_detached_state_updates)for a new
peekhandler on the conformance component. The spec gains a"Detached calls" section and updates to the timing, superseding, and
handler-hint sections.
@event(detached=...), the manifest hint, and the dispatcherchecks.
checkSendOptions, the out-of-queue path in the Vue Eventsbridge, rebuilt
events.jsandruntime.js, andclient.jscomments.softly, so an app on citry 0.6.0 still loads), and the generated types
allow
wait: falseonly for them, in component JavaScript and intemplate expressions.
$sendEventoptions in the browser API reference, notes on$state, theupgrade guide, the migration parity table, and both changelogs.
docs/design/events.mdnow describes the shippedwait: false(handlertable, queue rules, and the passages that referenced the old rendering
behaviour).
Verification
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.
(1405 passed across the Events and LSP suites); e2e page-API tests in
Chromium; a
citry check --typestest for templates.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.and a docs cold read; their findings are folded in.
🤖 Generated with Claude Code