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 2 commits into
wicket-11.xfrom
ajax-queued-dropped-1942-11.x
Open

reiern70 wants to merge 2 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

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.72%. Comparing base (6014597) to head (51adc3e).

Additional details and impacted files
@@              Coverage Diff               @@
##             wicket-11.x    #2005   +/-   ##
==============================================
  Coverage          62.71%   62.72%           
- Complexity         11510    11515    +5     
==============================================
  Files               1254     1254           
  Lines              48665    48687   +22     
  Branches            6845     6847    +2     
==============================================
+ Hits               30519    30537   +18     
- Misses             15471    15473    +2     
- Partials            2675     2677    +2     
🚀 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.

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