Repository navigation
Conversation
…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 Report❌ Patch coverage is 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:
|
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) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
| done(); | ||
| }); | ||
|
|
||
| Wicket.Ajax.ajax(calls.attributes({ e: 'event1', ch: 'throttleChannel|s', |
There was a problem hiding this comment.
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
droppedis followed by the channel'squeued/dropped - throttling with
postponeTimerOnUpdate(tr.p) - a channel whose type changes between calls, which is only tested at the
ChannelManagerlevel
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.
There was a problem hiding this comment.
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 dropand then only round 2 runs; - the throttling test now runs with
postponeTimerOnUpdatefalse and true; - a channel whose type changes between calls at the Ajax level: a queued call, then a
dcall that replaces it, then anacall that is dropped as active, and only thedcall 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. |
There was a problem hiding this comment.
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 (
doAjaxcallsdonewhen the precondition returns false). But thegetPreconditionentry 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.
There was a problem hiding this comment.
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
|
@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? |
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/initand then never published/ajax/call/done, and/ajax/call/beforeSendcame 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 internalWicket.Channel#schedule()andWicket.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'squeuedcomes before the old call'sdropped, so a counter never touches zero.IAjaxCallListenergets the default methodsgetQueuedHandler(Component)andgetDroppedHandler(Component),AjaxCallListenergetsonQueued/onDropped, andAjaxAttributeNamegetsQUEUED_HANDLER(qh) andDROPPED_HANDLER(drh), rendered asfunction(attrs, channel)andfunction(attrs, reason).initorqueuedends with exactly onedoneordropped, which receive the same attributes object.wicket-ajax-jquery.jsandwicket-ajax.js, behave the same.Wicket.Channel#schedule(),Wicket.ChannelManager#schedule()andWicket.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.ajax_5.adoc) and the two topics with the guarantee (ajax_6.adoc)./ajax/call/initstays where it is. The issue says calls made withWicket.Ajax.get()/post()publish nothing untildoAjax; they do publishinit, because they go throughWicket.Ajax.ajax()(a test now shows it). PublishinginitfromWicket.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 withnew Wicket.Ajax.Call().ajax(attrs)has never run itsinithandlers; it publishesqueuedwhen 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. AWicket.Channelnow keeps objects rather than functions in its internalcallbacksarray, so code that reached into it, or wrappedschedule()to find these cases, should subscribe to the new topics instead. A class implementingIAjaxCallListenerthat already had agetQueuedHandler(Component)orgetDroppedHandler(Component)now overrides the new default methods.Not in this PR
PageVeilBehaviorstill raises its veil atbeforeSend. Raising it atqueuedandbeforeSend, and lowering it atdroppedas well asdone, comes as a follow-up on top of PageVeilBehavior: Enter or Space pressed twice on a focused button sends two requests #1943 and PageVeilBehavior: a click on a button that leaves a field updating on change is lost #1944, which change the same script.initis not the place: it comes before throttling, so a throttled text field would be veiled while the user types.doAjaxcan still leave a call withoutdone, as before.Backport
To
wicket-11.xin #2005, a clean cherry-pick; the new API is therefore@since 11.1.0, the first release that carries it. Not towicket-10.x: it has only the jQuery engine and a differentchannels.js, and the change conflicts there.Tests
channels.js): the channel manager ons,dandachannels, a listener that throws, a channel whose type changes, the throttler, and real Ajax calls held on a busy channel for adchannel, anachannel, a throttled call, and anschannel withWicket.Ajax.get()plus a directCall#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.jsis now wrapped in a function, which re-indents it (git diff -wshows the real change).AbstractDefaultAjaxBehaviorTest#renderQueuedAndDroppedHandlersandAjaxAttributeNameTestfor the Java side.mvn clean verify -Pjs-testis green.