Skip to content

Publish Ajax topics for calls that wait in their channel and calls that never run (11.x) - #2005

Open
reiern70 wants to merge 3 commits into
wicket-11.xfrom
ajax-queued-dropped-1942-11.x
Open

reiern70 wants to merge 3 commits into
wicket-11.xfrom
ajax-queued-dropped-1942-11.x

Conversation

@reiern70

Copy link
Copy Markdown
Contributor

Backport of #1997 to wicket-11.x, for GitHub issue #1942.

The API changes are additions (two default interface methods, new methods and enum constants), binary-compatible; japicmp passes against 11.0.0. Existing topics and handlers come in the same order as before; * subscribers receive the two new topics too.

Not backported to wicket-10.x: it has only the jQuery engine and a different channels.js, and the change conflicts there.

Verified on this branch:

  • mvn clean verify -Pjs-test is green, japicmp included.

This goes in after #1997. If #1997 changes in review, this branch gets the same change.

…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
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
@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 62.71%. Comparing base (6014597) to head (8704df3).
⚠️ Report is 8 commits behind head on wicket-11.x.

Additional details and impacted files
@@              Coverage Diff               @@
##             wicket-11.x    #2005   +/-   ##
==============================================
  Coverage          62.71%   62.71%           
- Complexity         11510    11514    +4     
==============================================
  Files               1254     1254           
  Lines              48665    48691   +26     
  Branches            6845     6848    +3     
==============================================
+ Hits               30519    30538   +19     
- Misses             15471    15473    +2     
- Partials            2675     2680    +5     
🚀 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.

…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

(cherry picked from commit 6ba5e36)
@reiern70

Copy link
Copy Markdown
Contributor Author

Mirrored the review changes of #1997 here: 8704df3 is a clean cherry-pick of 6ba5e36, so the QUnit tests and the guide are identical to the master branch. The QUnit suites pass for both engines.

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.

2 participants