Skip to content

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

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

reiern70 wants to merge 2 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.01%. Comparing base (c7a21a5) to head (5eadfe8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1997      +/-   ##
============================================
+ Coverage     62.99%   63.01%   +0.01%     
- Complexity    11662    11671       +9     
============================================
  Files          1255     1255              
  Lines         48864    48887      +23     
  Branches       6910     6912       +2     
============================================
+ Hits          30783    30804      +21     
- Misses        15397    15399       +2     
  Partials       2684     2684              
🚀 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).

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.

* *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.

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