Skip to content

Publish Ajax topics for calls that wait in their channel and calls that never run - #1997

Open
reiern70 wants to merge 3 commits into
masterfrom
ajax-queued-dropped-1942
Open

reiern70 wants to merge 3 commits into
masterfrom
ajax-queued-dropped-1942

Conversation

@reiern70

@reiern70 reiern70 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1942

An Ajax call handed to a busy channel waited in its queue (s), replaced the calls waiting there (d) or was ignored (a), and none of this was published. A throttled call that a later one replaced was forgotten too. Those calls had published /ajax/call/init and then never published /ajax/call/done, and /ajax/call/beforeSend came only once a waiting call finally ran. A busy indicator, a veil or a guard against double submits written on the global topics could not see a call waiting behind a running one, nor tell when a call it had seen start was gone. The only way around it was to wrap the internal Wicket.Channel#schedule() and Wicket.Throttler#throttle().

What it does now

  • /ajax/call/queued (Wicket.Event.Topic.AJAX_CALL_QUEUED) is published, with the call's attributes and the channel's name, when the channel makes the call wait.
  • /ajax/call/dropped (Wicket.Event.Topic.AJAX_CALL_DROPPED) is published, with the attributes and a reason, when a call will never run: 'drop' when a later call replaces it in the queue of a dropping channel, 'active' when an active channel ignores it, 'throttle' when a later call replaces it in the throttler. In the 'drop' case the new call's queued comes before the old call's dropped, so a counter never touches zero.
  • IAjaxCallListener gets the default methods getQueuedHandler(Component) and getDroppedHandler(Component), AjaxCallListener gets onQueued/onDropped, and AjaxAttributeName gets QUEUED_HANDLER (qh) and DROPPED_HANDLER (drh), rendered as function(attrs, channel) and function(attrs, reason).
  • The guarantee: every call that publishes init or queued ends with exactly one done or dropped, which receive the same attributes object.
  • Both engines, wicket-ajax-jquery.js and wicket-ajax.js, behave the same. Wicket.Channel#schedule(), Wicket.ChannelManager#schedule() and Wicket.Throttler#throttle() take the listeners as optional arguments; an error thrown by one is logged and does not keep the channel from telling the other calls.
  • The Ajax chapter of the user guide lists the two handlers (ajax_5.adoc) and the two topics with the guarantee (ajax_6.adoc).

/ajax/call/init stays where it is. The issue says calls made with Wicket.Ajax.get()/post() publish nothing until doAjax; they do publish init, because they go through Wicket.Ajax.ajax() (a test now shows it). Publishing init from Wicket.Ajax.Call#ajax() would publish it twice for those calls, or move it behind the throttling delay and lose it for the calls the throttler replaces. A call made with new Wicket.Ajax.Call().ajax(attrs) has never run its init handlers; it publishes queued when it waits, so the guarantee holds for it too.

What applications see

The existing topics and handlers come in the same order as before; the two new topics come in between, and * subscribers receive them too. Callers of the channel manager and the throttler that pass no listeners, such as the WebSocket messages and the autocomplete field, work as before. A Wicket.Channel now keeps objects rather than functions in its internal callbacks array, so code that reached into it, or wrapped schedule() to find these cases, should subscribe to the new topics instead. A class implementing IAjaxCallListener that already had a getQueuedHandler(Component) or getDroppedHandler(Component) now overrides the new default methods.

Not in this PR

Backport

To wicket-11.x in #2005, a clean cherry-pick; the new API is therefore @since 11.1.0, the first release that carries it. Not to wicket-10.x: it has only the jQuery engine and a different channels.js, and the change conflicts there.

Tests

  • QUnit (channels.js): the channel manager on s, d and a channels, a listener that throws, a channel whose type changes, the throttler, and real Ajax calls held on a busy channel for a d channel, an a channel, a throttled call, and an s channel with Wicket.Ajax.get() plus a direct Call#ajax(), each asserting the exact sequence of topics and handlers. Run against jQuery 4.0.0, jQuery 3.7.1 and the plain engine, in Chrome and Firefox. channels.js is now wrapped in a function, which re-indents it (git diff -w shows the real change).
  • AbstractDefaultAjaxBehaviorTest#renderQueuedAndDroppedHandlers and AjaxAttributeNameTest for the Java side.
  • mvn clean verify -Pjs-test is green.

…at never run

An Ajax call handed to a busy channel waited in its queue ('s'), replaced
the calls waiting there ('d') or was ignored ('a'), and none of this was
published. A throttled call that a later one replaced was forgotten too.
Those calls had published /ajax/call/init and then never published
/ajax/call/done, and /ajax/call/beforeSend came only once a waiting call
finally ran.

A script that follows Ajax calls on the global topics, such as a busy
indicator, a veil or a guard against double submits, could therefore not
see a call waiting behind a running one, and could not tell when a call it
had seen start was gone. The only way around it was to wrap the internal
Wicket.Channel#schedule() and Wicket.Throttler#throttle().

Now /ajax/call/queued (Wicket.Event.Topic.AJAX_CALL_QUEUED) is published,
with the call's attributes and the name of the channel, when the channel
makes the call wait. /ajax/call/dropped (AJAX_CALL_DROPPED) is published,
with the attributes and a reason, when a call will never run: 'drop' when a
later call replaces it in the queue of a dropping channel, 'active' when an
active channel ignores it, and 'throttle' when a later call replaces it in
the throttler. IAjaxCallListener and AjaxCallListener have handlers for
both, getQueuedHandler()/onQueued() and getDroppedHandler()/onDropped(),
rendered as the attributes 'qh' and 'drh'. Every call that publishes init
or queued ends with exactly one done or dropped, which receive the same
attributes object. Both Ajax engines, wicket-ajax-jquery.js and
wicket-ajax.js, behave the same.

/ajax/call/init is still published only by the handlers Wicket.Ajax.ajax()
binds, which Wicket.Ajax.get() and post() go through as well. Publishing it
from Wicket.Ajax.Call#ajax() would publish it twice for those calls, or
move it behind the throttling delay and lose it for the calls the throttler
replaces, and the init handlers of a call made with
new Wicket.Ajax.Call().ajax(attrs) have never run. Such a call publishes
queued when it waits, so the guarantee holds for it as well.

Wicket.Channel#schedule(), Wicket.ChannelManager#schedule() and
Wicket.Throttler#throttle() take the listeners as optional arguments. An
error thrown by one is logged, so that it cannot keep the channel from
telling the other calls.

An application that relied on the old behaviour sees the existing topics
and handlers in the same order as before; the two new topics come in
between, and '*' subscribers receive them too. The callers of the channel
manager and the throttler that pass no listeners, such as the WebSocket
messages and the autocomplete field, work as before. A Wicket.Channel now
keeps objects rather than functions in its internal callbacks array, so
code that reached into it, or wrapped its schedule() to find these cases,
should subscribe to the new topics instead. A class implementing
IAjaxCallListener that already had a method getQueuedHandler(Component) or
getDroppedHandler(Component) now overrides the new default methods.

GitHub issue #1942
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.13%. Comparing base (c7a21a5) to head (6ba5e36).
⚠️ Report is 38 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1997      +/-   ##
============================================
+ Coverage     62.99%   63.13%   +0.14%     
- Complexity    11662    11725      +63     
============================================
  Files          1255     1255              
  Lines         48864    49003     +139     
  Branches       6910     6937      +27     
============================================
+ Hits          30783    30940     +157     
+ Misses        15397    15371      -26     
- Partials       2684     2692       +8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The new handlers and attribute names are backported to wicket-11.x, so
11.1.0 is the first release that carries them, not 12.0.0.

GitHub issue #1942
const recorder = function () {
const events = [];
const subscriptions = [];
const nameOf = function (attrs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guide (ajax_6.adoc) promises that /ajax/call/done and /ajax/call/dropped receive the same attrs object as init/queued, and tells scripts to keep track of calls by their attrs. The recorder identifies calls by nameOf(attrs), so these tests would keep passing if the attrs were copied somewhere along the way, e.g. by an Object.assign({}, attrs) in Call#ajax. Could the recorder check identity as well? For example: add the attrs to a Set on init/queued, assert.ok(pending.delete(attrs)) on done/dropped, and assert the set is empty when the test finishes (adjusting assert.expect).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6ba5e36. The recorder now keeps the attrs of every call in a Set when it publishes init or queued, asserts pending.delete(attrs) on done and dropped, and stop() asserts that the set is empty; the assert.expect counts are raised to match. I checked that it bites: with /ajax/call/done published with jQuery.extend({}, attrs), the tests fail on both assertions while the event lists still match.

Comment thread wicket-core/src/test/js/channels.js Outdated
done();
});

Wicket.Ajax.ajax(calls.attributes({ e: 'event1', ch: 'throttleChannel|s',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ajax-level tests cover each case on its own, but not some combinations a real page runs into:

  • a throttled call that then lands on a busy channel, where the throttler's dropped is followed by the channel's queued/dropped
  • throttling with postponeTimerOnUpdate (tr.p)
  • a channel whose type changes between calls, which is only tested at the ChannelManager level

A throttled call on a busy d channel would be the most valuable of these, since it exercises both drop paths in one stream of calls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 6ba5e36, all three:

  • a throttled call on a busy dropping channel: the throttler drops round 0, round 1 waits in the channel, and round 2 replaces it there, so the stream has dropped 0 throttle, queued 1, queued 2, dropped 1 drop and then only round 2 runs;
  • the throttling test now runs with postponeTimerOnUpdate false and true;
  • a channel whose type changes between calls at the Ajax level: a queued call, then a d call that replaces it, then an a call that is dropped as active, and only the d call runs.

* *getFailureHandler(Component)*: returns the JavaScript code that will be executed if the AJAX call has returned with a failure. The code is executed in a scope where it can use variable attrs, which is the same variable seen for getBeforeHandler.
* *getCompleteHandler(Component)*: returns the JavaScript that will be invoked after success or failure handler has been executed. The code is executed in a scope where it can use variables attrs, jqXHR and textStatus which are the same variables seen for getSuccessHandler.
* *getDoneHandler(Component)*: returns the JavaScript code that will be executed after the Ajax call is done, regardless whether it was sent or not. The code is executed in a scope where it can use variable attrs, which is an array containing the JSON parameters passed to Wicket.Ajax.ajax.
* *getDoneHandler(Component)*: returns the JavaScript code that will be executed after the Ajax call is done, regardless whether it was sent or not (for example because a precondition stopped it). The code is executed in a scope where it can use variable attrs, which is an array containing the JSON parameters passed to Wicket.Ajax.ajax.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things in this paragraph. Both are older than this PR, but they are in text it edits:

  • The new "for example because a precondition stopped it" matches the code (doAjax calls done when the precondition returns false). But the getPrecondition entry a few lines up still says that "neither the Ajax call nor the other handlers will be executed", so the two now contradict each other. That entry should say that the done handler still runs.
  • attrs is described as "an array containing the JSON parameters". It is an object. The init and before handler entries say the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fixed in 6ba5e36. The getPrecondition entry now says that when it returns false the call is not sent and, of the handlers that follow the precondition, only the done handler runs. attrs is described as an object in the init, before and done entries. While there I also added qh and drh to the table of attributes, which still listed only the older handlers.

…els together

The recorder of the Ajax-level channel tests named a call by its round, so
the tests would have kept passing had done or dropped received a copy of
the attrs that init or queued published, although the guide tells scripts
to keep track of the calls by those attrs. It now keeps the attrs of every
call that publishes init or queued, asserts that done or dropped receives
that very object, and asserts at the end that no call is left without one.

New tests cover what a page runs into beyond each case on its own: a
throttled call on a busy dropping channel, where the throttler drops the
first call and the channel then queues the next and drops it in turn;
throttling with postponeTimerOnUpdate, which takes the other branch of
Wicket.Throttler#throttle(); and a channel whose type changes between the
calls of a queue, a drop and an active one.

The guide said that a precondition returning false keeps every other
handler from running, but the done handler still runs, as the done
handler's own entry now says. It also described attrs as an array, which
it is not, and its table of attributes now lists qh and drh.

GitHub issue #1942
@reiern70

Copy link
Copy Markdown
Contributor Author

@papegaaij thanks for the review. 6ba5e36 addresses the three comments; the details are in their threads. The QUnit suites pass for both engines. Could you have another look?

@reiern70
reiern70 requested a review from papegaaij November 27, 2026 23:23
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.

Ajax: publish a topic when a call waits in its channel's queue, and when a call is dropped without being sent

3 participants