@coolon/angular-ui-powerups 16.1.0-alpha.223 → 16.1.0-alpha.224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/place/navigation/session/navigation-session.mjs +10 -1
- package/esm2022/lib/place/place-component.mjs +17 -13
- package/esm2022/lib/place/place-router.mjs +90 -15
- package/fesm2022/coolon-angular-ui-powerups.mjs +113 -25
- package/fesm2022/coolon-angular-ui-powerups.mjs.map +1 -1
- package/lib/place/navigation/session/navigation-session.d.ts +7 -0
- package/lib/place/place-router.d.ts +17 -0
- package/package.json +1 -1
|
@@ -7961,6 +7961,15 @@ class NavigationSession extends GarbageCollector {
|
|
|
7961
7961
|
get isInteractionSync() {
|
|
7962
7962
|
return false;
|
|
7963
7963
|
}
|
|
7964
|
+
/**
|
|
7965
|
+
* Interruptible sessions are internal housekeeping navigations (e.g. interaction-id
|
|
7966
|
+
* synchronisation) that a real user- or model-driven navigation is allowed to queue behind
|
|
7967
|
+
* and supersede, rather than being rejected. Real navigations (Navigating, PopState) are not
|
|
7968
|
+
* interruptible.
|
|
7969
|
+
*/
|
|
7970
|
+
get isInterruptible() {
|
|
7971
|
+
return this.isInteractionSync;
|
|
7972
|
+
}
|
|
7964
7973
|
get name() {
|
|
7965
7974
|
return this.constructor.name;
|
|
7966
7975
|
}
|
|
@@ -9182,6 +9191,11 @@ class PlaceRouter extends GarbageCollector {
|
|
|
9182
9191
|
_activeVisit$ = new MutableValueModel();
|
|
9183
9192
|
routerInteractionAdapter;
|
|
9184
9193
|
sessionFinishedJobs = [];
|
|
9194
|
+
// A navigation triggered while an interruptible session is in flight is parked here and run when
|
|
9195
|
+
// that session finishes. Only the most recent pending navigation is retained (coalescing).
|
|
9196
|
+
pendingNavigation;
|
|
9197
|
+
queuedNavigationDepth = 0;
|
|
9198
|
+
static MAX_QUEUED_NAVIGATION_DEPTH = 5;
|
|
9185
9199
|
authService = new PlaceAuthService();
|
|
9186
9200
|
_ready$ = this.registerDisposable(new DelegatingValueModel().withDefault(true));
|
|
9187
9201
|
ready$ = this._ready$.readonly$;
|
|
@@ -9345,17 +9359,11 @@ class PlaceRouter extends GarbageCollector {
|
|
|
9345
9359
|
// @Trace()
|
|
9346
9360
|
async doNavigation(visit, runNavigationCommands) {
|
|
9347
9361
|
if (this.navigationInProgress$.value) {
|
|
9348
|
-
|
|
9349
|
-
visit: visit,
|
|
9350
|
-
session: this.navigationSession,
|
|
9351
|
-
});
|
|
9352
|
-
lang.illegalState('Navigation already in progress');
|
|
9353
|
-
}
|
|
9354
|
-
else {
|
|
9355
|
-
const navigation = this.createNavigationSession(this.urlService.getCurrentRouterUrl());
|
|
9356
|
-
navigation.initialiseVisitSegments(visit);
|
|
9357
|
-
this.transitionTo(navigation);
|
|
9362
|
+
return this.handleOverlappingNavigation(visit, runNavigationCommands);
|
|
9358
9363
|
}
|
|
9364
|
+
const navigation = this.createNavigationSession(this.urlService.getCurrentRouterUrl());
|
|
9365
|
+
navigation.initialiseVisitSegments(visit);
|
|
9366
|
+
this.transitionTo(navigation);
|
|
9359
9367
|
try {
|
|
9360
9368
|
await runNavigationCommands(this.angularRouter);
|
|
9361
9369
|
}
|
|
@@ -9367,6 +9375,80 @@ class PlaceRouter extends GarbageCollector {
|
|
|
9367
9375
|
}
|
|
9368
9376
|
}
|
|
9369
9377
|
}
|
|
9378
|
+
/**
|
|
9379
|
+
* Handles a navigation triggered while another is already in flight.
|
|
9380
|
+
*
|
|
9381
|
+
* This used to throw `illegalState('Navigation already in progress')`, which killed the
|
|
9382
|
+
* triggering action - occasionally seen in production when a user click collided with an
|
|
9383
|
+
* in-flight interaction-id sync. Instead we warn with diagnostic context and decide based on the
|
|
9384
|
+
* in-progress session:
|
|
9385
|
+
* - interruptible session in progress (internal housekeeping, e.g. interaction-id sync) -> queue
|
|
9386
|
+
* the incoming navigation and run it once the current session finishes (coalescing to latest).
|
|
9387
|
+
* - real navigation in progress -> keep it and drop the incoming one (logging full context).
|
|
9388
|
+
*/
|
|
9389
|
+
handleOverlappingNavigation(visit, runNavigationCommands) {
|
|
9390
|
+
const current = this.navigationSession;
|
|
9391
|
+
const debug = {
|
|
9392
|
+
inProgress: {
|
|
9393
|
+
session: current?.name,
|
|
9394
|
+
state: current?.toString(),
|
|
9395
|
+
isInteractionSync: current?.isInteractionSync,
|
|
9396
|
+
isInterruptible: current?.isInterruptible,
|
|
9397
|
+
isPopState: current?.isPopState,
|
|
9398
|
+
segments: current?.getVisitSegments().map(s => s.toDebugString()),
|
|
9399
|
+
},
|
|
9400
|
+
incoming: visit?.toDebugString(),
|
|
9401
|
+
currentUrl: this.urlService.getCurrentRouterUrl(),
|
|
9402
|
+
};
|
|
9403
|
+
if (current?.isInterruptible) {
|
|
9404
|
+
Logger.get(this).warn(`Navigation triggered while interruptible session '${current.name}' is in progress; ` +
|
|
9405
|
+
`queueing the incoming navigation to run once it finishes.`, debug);
|
|
9406
|
+
return this.queueNavigation(visit, runNavigationCommands);
|
|
9407
|
+
}
|
|
9408
|
+
// NOTE (interim policy): when a *real* navigation is already in progress we keep the first and
|
|
9409
|
+
// drop the incoming one, logging full context so we can see what actually collides in
|
|
9410
|
+
// production. We deliberately do NOT queue+coalesce here yet - once production logs show which
|
|
9411
|
+
// real-vs-real collisions occur we can decide whether "latest wins (queued)" is the better
|
|
9412
|
+
// behaviour. See the implementation plan for the queue+coalesce alternative.
|
|
9413
|
+
Logger.get(this).warn(`Navigation already in progress ('${current?.name}'); ignoring the incoming navigation. ` +
|
|
9414
|
+
`Review this if it occurs in production - it may need to be queued instead.`, debug);
|
|
9415
|
+
return Promise.resolve();
|
|
9416
|
+
}
|
|
9417
|
+
queueNavigation(visit, runNavigationCommands) {
|
|
9418
|
+
const flushAlreadyScheduled = !!this.pendingNavigation;
|
|
9419
|
+
if (this.pendingNavigation) {
|
|
9420
|
+
// Coalesce: supersede the previously queued navigation so only the most recent target runs.
|
|
9421
|
+
this.pendingNavigation.resolve();
|
|
9422
|
+
}
|
|
9423
|
+
return new Promise((resolve, reject) => {
|
|
9424
|
+
this.pendingNavigation = { visit, runNavigationCommands, resolve, reject };
|
|
9425
|
+
if (!flushAlreadyScheduled) {
|
|
9426
|
+
this.runAfterRoutingSessionFinishes(() => this.flushPendingNavigation());
|
|
9427
|
+
}
|
|
9428
|
+
});
|
|
9429
|
+
}
|
|
9430
|
+
flushPendingNavigation() {
|
|
9431
|
+
const pending = this.pendingNavigation;
|
|
9432
|
+
if (!pending) {
|
|
9433
|
+
return;
|
|
9434
|
+
}
|
|
9435
|
+
this.pendingNavigation = undefined;
|
|
9436
|
+
if (this.queuedNavigationDepth >= PlaceRouter.MAX_QUEUED_NAVIGATION_DEPTH) {
|
|
9437
|
+
Logger.get(this).warn(`Dropping queued navigation after ${this.queuedNavigationDepth} consecutive deferrals to ` +
|
|
9438
|
+
`avoid a navigation loop.`, { visit: pending.visit?.toDebugString() });
|
|
9439
|
+
this.queuedNavigationDepth = 0;
|
|
9440
|
+
pending.resolve();
|
|
9441
|
+
return;
|
|
9442
|
+
}
|
|
9443
|
+
this.queuedNavigationDepth++;
|
|
9444
|
+
this.doNavigation(pending.visit, pending.runNavigationCommands).then(() => {
|
|
9445
|
+
this.queuedNavigationDepth = 0;
|
|
9446
|
+
pending.resolve();
|
|
9447
|
+
}, (error) => {
|
|
9448
|
+
this.queuedNavigationDepth = 0;
|
|
9449
|
+
pending.reject(error);
|
|
9450
|
+
});
|
|
9451
|
+
}
|
|
9370
9452
|
navigateByUrl(urlSnapshot, navigationExtras) {
|
|
9371
9453
|
// console.log(`### navigationByUrl -> ${urlSnapshot.urlTree.toString()}`);
|
|
9372
9454
|
return this.angularRouter.navigateByUrl(urlSnapshot.urlTree, navigationExtras);
|
|
@@ -9384,13 +9466,15 @@ class PlaceRouter extends GarbageCollector {
|
|
|
9384
9466
|
// FIXME: no route id -> route id duplicates route parameters
|
|
9385
9467
|
const visit = this.activeVisit$.value.copyAndReplaceSegment(is);
|
|
9386
9468
|
if (is.hasRoutingChangedFrom(was)) {
|
|
9387
|
-
//
|
|
9388
|
-
//
|
|
9469
|
+
// An in-place parameter change (model -> route) is a refinement of the current view rather
|
|
9470
|
+
// than a new destination - e.g. a selection model writing its selected id, including the
|
|
9471
|
+
// auto-select-first / select-nearest corrections. We update the URL with replaceUrl so the
|
|
9472
|
+
// selection never accrues spurious back-stack entries.
|
|
9389
9473
|
await this.doNavigation(visit, () => {
|
|
9390
9474
|
const urlSnapshot = this.urlService
|
|
9391
9475
|
.parseUrl(this.angularRouter.routerState.snapshot.url)
|
|
9392
9476
|
.updateVisitSegment(is);
|
|
9393
|
-
return this.navigateByUrl(urlSnapshot);
|
|
9477
|
+
return this.navigateByUrl(urlSnapshot, { replaceUrl: true });
|
|
9394
9478
|
});
|
|
9395
9479
|
}
|
|
9396
9480
|
}
|
|
@@ -11611,22 +11695,24 @@ class PlaceComponent extends LoadableComponent {
|
|
|
11611
11695
|
const { when } = Dsl.disposeWith(this);
|
|
11612
11696
|
this.visit$.value = visit;
|
|
11613
11697
|
DebugContext.getOrCreate(this.visit$).tag(`${this.placeDefinition.component.name}.visit$`);
|
|
11614
|
-
// we track if
|
|
11615
|
-
// route
|
|
11616
|
-
|
|
11698
|
+
// we track if any of the bindings updated the route (e.g. a selection model that auto-selected
|
|
11699
|
+
// the first item during construction while the route had no value). If so we update the route
|
|
11700
|
+
// once, after wiring up the change listener below.
|
|
11701
|
+
const routeUpdatedByBinding = this.placeDefinition
|
|
11617
11702
|
.getVisitParameterDefs()
|
|
11618
|
-
.
|
|
11703
|
+
.map(parameterDef => this.installAndInitialiseBinding(visit, parameterDef))
|
|
11704
|
+
.some(Boolean);
|
|
11619
11705
|
when(this.visit$).changes((current, previous) => {
|
|
11620
11706
|
notifyVisitChanged(current, previous);
|
|
11621
11707
|
}, { unless: this._inVisitUpdate });
|
|
11622
|
-
//
|
|
11623
|
-
//
|
|
11624
|
-
//
|
|
11625
|
-
//
|
|
11626
|
-
//
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11708
|
+
// The binding process can update the visit when the route had no value (e.g. a selection model
|
|
11709
|
+
// with autoSelectFirstItemOnLoad that already selected during component construction). Propagate
|
|
11710
|
+
// that to the router now so the URL reflects the selection. PlaceRouter applies in-place
|
|
11711
|
+
// parameter updates with replaceUrl (see PlaceRouter.notifyVisitSegmentChanged), so the
|
|
11712
|
+
// auto-selected value doesn't create a spurious history entry.
|
|
11713
|
+
if (routeUpdatedByBinding && this.visit$.value.hasRoutingChangedFrom(visit)) {
|
|
11714
|
+
notifyVisitChanged(this.visit$.value, visit);
|
|
11715
|
+
}
|
|
11630
11716
|
}
|
|
11631
11717
|
get childPlaces() {
|
|
11632
11718
|
return this.childPlaces$.value;
|
|
@@ -11669,9 +11755,11 @@ class PlaceComponent extends LoadableComponent {
|
|
|
11669
11755
|
const isInModel = !isNil(model.value);
|
|
11670
11756
|
if (!isInVisit && isInModel) {
|
|
11671
11757
|
binding.writeLeft(); // push it to the route
|
|
11758
|
+
return true; // the model (e.g. an auto-selected selection) updated the route
|
|
11672
11759
|
}
|
|
11673
11760
|
else {
|
|
11674
11761
|
binding.writeRight(); // push it to the model
|
|
11762
|
+
return false;
|
|
11675
11763
|
}
|
|
11676
11764
|
}
|
|
11677
11765
|
get placeDefinition() {
|