Skip to content

fix: drop a replaced caller's delayed actions once a newer result arrives - #326

Merged
JuroOravec merged 1 commit into
mainfrom
fix/remounted-call-delayed-actions
Oct 24, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/remounted-call-delayed-actions

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Fixes #307

What changes

A handler's Render can replace its own component while the same response also schedules a delayed action with wait=False. If the page then accepted a newer result from the component that replaced it, the old call's delayed action still ran on the new component, after the newer result. A Dispatch, a URL change and a State refresh all behaved this way.

The cause: the bridge compared only the retired instance's count of accepted results, and the new component's results never raise that count.

Fix, in packages/js/citry-client/src/citry-events-vue.ts:

  • The bridge now also counts the results it accepted at each spot on the page (stableId), whatever instance is mounted there. When a call's own result is accepted, the bridge records that count on the call.
  • After the call's own Render replaced the caller, its delayed actions run only while that count is unchanged.
  • With no newer result, they still run as before.
  • An applyActions on the new component also counts, once its citry:events:before listeners let it apply.
  • dispose() clears the counts.

A delayed Redirect survives a newer result in every case, with or without a replacement. It reports a result the server already produced, such as "saved, now go to the list". Like every action of a cancelled call, it is still dropped when its call is superseded, when its caller is removed, or when the client is disposed. This was the maintainer's decision for this issue.

Spec and docs

The "Order and timing" section of packages/protocol/events/v1/spec.md now starts with the two rules, once:

  1. A cancelled call changes nothing on the page.
  2. A newer result drops the rest of an older one, except a redirect.

A single table then says what happens to a delayed action in each case. A list of details follows:

  • error results count as newer results;
  • only results for the component at the caller's place count;
  • actions listed before the Render;
  • the superseded row takes precedence;
  • blocking actions;
  • results that hold an unknown action type are rejected whole;
  • applyActions.

The protocol version stays at 1.

The epoch row in docs_site/content/reference/browser-apis.md, and the toast example in docs_site/content/events/actions.md, now say when a delayed action is dropped.

Tests

There are 8 new tests in packages/js/citry-client/test/vue-events.test.mjs. With a newer result after a replacement:

  • Dispatch, PushUrl, ReplaceUrl and State are dropped;
  • Redirect runs.

Also covered:

  • with no newer result, the delayed actions run;
  • a delayed Redirect runs after a newer result for a caller that is still mounted;
  • an applyActions on the new component counts as a newer result.

The four drop tests fail on main's bridge (which includes #324). The applyActions test fails without its counter bump. The other tests guard behaviour that is kept. The attachment acceptance path has no test of its own, because saveAttachment needs DOM stubs.

Evidence

These non-cargo phases of scripts/check.py were run by hand locally, and all pass:

  • uv lock --check, ruff check, ruff format --check;
  • mypy on the gate's paths, plus mypy --platform linux;
  • the citry-client phase: vue-types check, tsc, biome, node tests (191 pass);
  • protocol contracts, protocol Python copies, events protocol JavaScript;
  • scripts/validate.py.

PR CI runs pytest and the cargo phases. This change has no Python logic and no Rust.

Review

An independent adversarial review ran three rounds, each with a prose pass. Its findings are folded in:

  • spec rows that did not match the code (actions listed before the Render, applyActions, unknown types, the blocking claim, error results);
  • two acceptance paths with no tests;
  • an applyActions that a before listener cancelled still counted as a newer result;
  • the counts map was never cleared;
  • tight test timings.

🤖 Generated with Claude Code

@JuroOravec
JuroOravec force-pushed the fix/remounted-call-delayed-actions branch from 24832a9 to 5123d91 Compare October 24, 2026 15:24
…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]>
@JuroOravec
JuroOravec force-pushed the fix/remounted-call-delayed-actions branch from 5123d91 to db39fe8 Compare October 24, 2026 15:24
@JuroOravec
JuroOravec merged commit 503c9ec into main Oct 24, 2026
20 of 26 checks passed
@JuroOravec
JuroOravec deleted the fix/remounted-call-delayed-actions branch October 24, 2026 15:35
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.

After a Render replaces the caller, its delayed wait=False actions run even after a newer result

1 participant