Skip to content

Commit 4718cbe

Browse files
committed
fix route resolve race condition
1 parent 929ab5b commit 4718cbe

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

src/external/router-slot/router-slot.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ ensureAnchorHistory();
4545
* @event changestate - Dispatched when the router slot state changes.
4646
*/
4747
export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouterSlot<D, P> {
48+
/**
49+
* Method to cancel navigation if changed.
50+
*/
51+
private _cancelNavigation ?:() => void;
52+
4853
/**
4954
* Listeners on the router.
5055
*/
@@ -200,9 +205,13 @@ export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouter
200205
// If navigate is not determined, then we will check if we have a route match. If not then we will re-render. [NL]
201206
navigate = this._routeMatch === null;
202207
if (navigate === false) {
203-
const newMatch = this.getRouteMatch();
204-
// Check if this match matches the current match (aka. If the path has changed), if so we should navigate. [NL]
205-
navigate = this._routeMatch?.route.path !== newMatch?.route.path;
208+
if (this.isConnected) {
209+
const newMatch = this.getRouteMatch();
210+
// Check if this match matches the current match (aka. If the path has changed), if so we should navigate. [NL]
211+
if(newMatch) {
212+
navigate = shouldNavigate(this.match, newMatch);
213+
}
214+
}
206215
}
207216
}
208217

@@ -327,10 +336,17 @@ export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouter
327336
// Only change route if its a new route.
328337
const navigate = shouldNavigate(this.match, match);
329338
if (navigate) {
339+
340+
// If another navigation is still begin resolved in this very moment, then we need to cancel that so it does not end up overriding this new navigation.[NL]
341+
this._cancelNavigation?.();
330342
// Listen for another push state event. If another push state event happens
331343
// while we are about to navigate we have to cancel.
332344
let navigationInvalidated = false;
333-
const cancelNavigation = () => (navigationInvalidated = true);
345+
const cancelNavigation = () => {
346+
navigationInvalidated = true;
347+
this._cancelNavigation = undefined;
348+
};
349+
this._cancelNavigation = cancelNavigation;
334350
const removeChangeListener: EventListenerSubscription = addListener<Event, GlobalRouterEvent>(
335351
GLOBAL_ROUTER_EVENTS_TARGET,
336352
'changestate',

src/packages/core/content/workspace/views/edit/content-editor-properties.element.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class UmbContentWorkspaceViewEditPropertiesElement extends UmbLitElement
4141
);
4242
});
4343
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (datasetContext) => {
44-
console.log(this, datasetContext)
4544
this.#variantId = datasetContext.getVariantId();
4645
this.#generatePropertyDataPath();
4746
});

src/packages/core/workspace/components/workspace-editor/workspace-editor.element.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export class UmbWorkspaceEditorElement extends UmbLitElement {
4949
constructor() {
5050
super();
5151

52-
console.log("workspace editor created.")
53-
5452
new UmbExtensionsManifestInitializer(this, umbExtensionsRegistry, 'workspaceView', null, (workspaceViews) => {
5553
this._workspaceViews = workspaceViews.map((view) => view.manifest);
5654
this._createRoutes();

src/packages/core/workspace/components/workspace-split-view/workspace-split-view.context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { UMB_VARIANT_WORKSPACE_CONTEXT } from '../../contexts/index.js';
2-
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
31
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
42
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
53
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
64
import { UmbNumberState } from '@umbraco-cms/backoffice/observable-api';
5+
import { UMB_VARIANT_WORKSPACE_CONTEXT } from '../../contexts/index.js';
6+
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
77
import type { UmbPropertyDatasetContext } from '@umbraco-cms/backoffice/property';
88

99
export class UmbWorkspaceSplitViewContext extends UmbContextBase<UmbWorkspaceSplitViewContext> {

src/packages/core/workspace/components/workspace-split-view/workspace-split-view.element.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export class UmbWorkspaceSplitViewElement extends UmbLitElement {
3535

3636
override render() {
3737

38-
console.log("workspace split view render")
39-
4038
return html`
4139
<umb-workspace-editor
4240
alias=${this.alias}

src/packages/core/workspace/controllers/workspace-split-view-manager.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class UmbWorkspaceSplitViewManager {
2525
}
2626

2727
setActiveVariant(index: number, culture: string | null, segment: string | null) {
28-
console.log("setActiveVariant", index, culture, segment)
2928
this.#activeVariantsInfo.appendOneAt({ index, culture: culture ?? null, segment: segment ?? null }, index);
3029
}
3130

src/packages/documents/documents/workspace/document-workspace-split-view.element.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from './document-workspace.context-token.js';
21
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
32
import { css, html, nothing, customElement, state, repeat } from '@umbraco-cms/backoffice/external/lit';
43
import type { ActiveVariant } from '@umbraco-cms/backoffice/workspace';
54
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
5+
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from './document-workspace.context-token.js';
66

77
@customElement('umb-document-workspace-split-view')
88
export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
@@ -28,27 +28,11 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
2828
this._workspaceContext.splitView.activeVariantsInfo,
2929
(variants) => {
3030
this._variants = variants;
31-
console.log("______variants: ", variants[0])
3231
},
3332
'_observeActiveVariantsInfo',
3433
);
3534
}
3635

37-
override connectedCallback(): void {
38-
super.connectedCallback();
39-
console.log("connected callback------")
40-
}
41-
42-
override disconnectedCallback(): void {
43-
super.disconnectedCallback();
44-
console.log("DISconnected callback------")
45-
}
46-
47-
override destroy(): void {
48-
super.destroy();
49-
console.log("split view ot destroyed")
50-
}
51-
5236
override render() {
5337
return this._variants
5438
? html`<div id="splitViews">

0 commit comments

Comments
 (0)