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