Repository navigation
fix: stop a superseded latest_wins call from changing the page - #324
Merged
Merged
Conversation
With @event(latest_wins=True), a newer call cancelled the older one and rejected its promise, but the bridge kept running the older call's remaining actions. A blocking delay, a delayed Render included, held the newer call back in the queue until it ended. After that, the delayed Dispatch, State, URL, Redirect and Data actions still ran, and wait=False actions still fired, even after the older call had finished. $loading() and citry:events:after reported the call as a success. A cancelled call now records its cancellation error (Job.cancelError), and cancelling a call also stops the delays of its wait=False actions, even when the call has already finished; the bridge keeps finished calls that still have such actions pending (detachedJobs), so a newer call can supersede them. The delay helper stops waiting when the call is cancelled, so the queue moves on to the newer call at once, and continuationCurrent, the hoisted State commits and the step after preflight reject a cancelled call, so none of its remaining actions start. Each wait=False action that had not finished fires citry:events:stale with reason superseded, without a console error. A call cancelled after its last action ran reports as cancelled, not as a success. Delays of applyActions calls made without a component are now stopped by dispose(). The Events spec gains a "Superseded calls" section that states this for every action type, Redirect included, and what supersession does not change. The latest_wins docstring and the stale-reason table say the same. Fixes #306 Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
added a commit
that referenced
this pull request
Oct 24, 2026
…ives When an Events handler's Render replaced its component, the bridge marked the call as having remounted its own sender and kept running its later actions, so a delayed wait=False Dispatch, URL change or State refresh still ran after the page accepted a newer result from the component that replaced it. The check compared only the retired instance's count of accepted results, which the new component's results never raise. The bridge now also counts the results it accepted at each spot on the page (stableId), whichever instance is mounted there, and records the count when a call's own result is accepted. After that call's Render replaced the caller, a delayed action other than Redirect runs only while the count is unchanged. With no newer result, the delayed actions still run, as before. An applyActions on the new component counts once its citry:events:before listeners let it apply, and dispose() clears the counts. A delayed Redirect now survives a newer result in every case, with or without a replacement: it reports a result the server already produced. Like every action of a cancelled call, it is dropped when its call is superseded, its caller is removed, or the client is disposed. The Events spec's "Order and timing" section states the two rules once (a cancelled call changes nothing on the page; a newer result drops the rest of an older one, except a redirect), then gives one table of what happens in each case and the details: error results count, only results for the component at the caller's place count, actions listed before the Render, applyActions, and unknown action types. The browser APIs page and the actions page say when a delayed action is dropped. The superseded row describes the behavior from the #306 fix (#324). Fixes #307 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.
Fixes #306
What changes
With
@event(latest_wins=True), a newer call cancels the older one and rejects its promise. Before this change, the bridge kept running the older call's remaining actions anyway:Dispatch, State, URL changes,RedirectandDatastill ran.wait=Falseactions still fired, even after the older call had finished.$loading()andcitry:events:afterreported the call as a success.Now a superseded call changes nothing more on the page. That follows the maintainer's decision for this issue, which includes
wait=Falseactions andRedirect.How the bridge (
packages/js/citry-client/src/citry-events-vue.ts) does it:Job.cancelError). Cancelling also stops the delays of itswait=Falseactions, even when the call has already finished. The bridge keeps calls whosewait=Falseactions have not finished (detachedJobs), so a newer call can supersede them too.continuationCurrent, the hoisted State commits, and the step after preflight reject a cancelled call, so none of its remaining actions start. The preflight check comes before the accepted-result count moves, so a cancelled result does not count as a newer one.wait=Falseaction that had not finished firescitry:events:stalewith reasonsuperseded, with no console error. A call cancelled after its last action ran is reported as cancelled, not as a success.dispose()stops sourceless delays. It now stops the delays ofapplyActionscalls made without a component.The committed bundles
packages/py/citry/citry/_vue/events.jsandruntime.jsare rebuilt from the source.Spec and docs
packages/protocol/events/v1/spec.mdhas a new "Superseded calls" section. It says what happens to a queued call, an in-flight call and an accepted result, for every action type,Redirectincluded. It also says when the stale events fire, and that supersession takes effect when the newer call is queued, even if the newer call fails. Finally, it lists what supersession does not change:applyActionsis never superseded.latest_winsdocstring and thesupersededrow of the stale reasons table indocs_site/content/reference/browser-apis.mdsay the same.Tests
There are 17 new tests in
packages/js/citry-client/test/vue-events.test.mjs:wait=Falseaction, for each of Dispatch, Redirect, PushUrl, ReplaceUrl and State;dispose()stopping a sourcelessapplyActions.The
wait=Falsetests make the newer result arrive after the old action is due, so only supersession can stop the action. The tests that wait for acceptance use a deterministic signal frompreflightResult.Against main's bridge source, all 16 tests that cover the fix fail. Against this branch, all 78 tests in the file pass.
Evidence
Run locally, all passing. These are the non-cargo phases of
scripts/check.py, run by hand:uv lock --check, ruff check, ruff format --check--platform linuxscripts/validate.pyPR CI runs pytest and the cargo phases. This change has no Python logic and no Rust, and the local Python suite would first need a citry_core rebuild for #318.
Review
An independent adversarial review, run twice with prose passes. It found these problems, all now fixed:
wait=Falseaction was still running;#307 is stacked on this branch and must merge after it.
🤖 Generated with Claude Code