Skip to content

Introduce delay and expand path matching on Backoffice router for lazy-loaded routes #19409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ export class UmbDashboardElement extends UmbElementMixin(LitElement) {
},
{
path: '',
pathMatch: 'full',
redirectTo: 'tab1',
},
];
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ export class UmbExampleModal extends UmbModalBaseElement {
},
{
path: '',
pathMatch: 'full',
redirectTo: 'modalOverview',
},
];
Original file line number Diff line number Diff line change
@@ -63,8 +63,10 @@ export class UmbBackofficeMainElement extends UmbLitElement {

if (newRoutes.length > 0) {
newRoutes.push({
path: '',
pathMatch: 'full',
awaitStability: true,
redirectTo: newRoutes[0].path,
path: ``,
});

newRoutes.push({
Original file line number Diff line number Diff line change
@@ -123,6 +123,7 @@ export class UmbBlockWorkspaceViewEditElement extends UmbLitElement implements U
if (!this._hasRootGroups) {
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[0]?.path,
});
}
Original file line number Diff line number Diff line change
@@ -205,12 +205,14 @@
});
routes.push({
path: '',
pathMatch: 'full',
redirectTo: 'root',
guards: [() => this.#processingTabId === undefined],
});
} else {
routes.push({
path: '',
pathMatch: 'full',

Check warning on line 215 in src/Umbraco.Web.UI.Client/src/packages/content/content-type/workspace/views/design/content-type-design-editor.element.ts

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/16.0)

❌ Getting worse: Complex Method

UmbContentTypeDesignEditorElement.createRoutes already has high cyclomatic complexity, and now it increases in Lines of Code from 76 to 78. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
redirectTo: routes[0]?.path,
guards: [() => this.#processingTabId === undefined],
});
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@ export class UmbContentWorkspaceViewEditElement extends UmbLitElement implements
if (routes.length !== 0) {
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[0].path,
});

Original file line number Diff line number Diff line change
@@ -75,6 +75,9 @@ export interface IRedirectRoute<D = any> extends IRouteBase<D> {
// The paths the route should redirect to. Can either be relative or absolute.
redirectTo: string;

// First redirect when the routes appears stable. Delaying the redirect so other routes get the change to resolve first.
awaitStability?: boolean;

// Whether the query should be preserved when redirecting.
preserveQuery?: boolean;
}
Original file line number Diff line number Diff line change
@@ -314,6 +314,24 @@
}
}

private getRedirectDelay() {
if ('connection' in navigator) {
const connection =
navigator.connection || (navigator as any).mozConnection || (navigator as any).webkitConnection;

switch (connection.effectiveType) {
case 'slow-2g':
case '2g':
return 1200;
case '3g':
return 800;
case '4g':
return 200;
}
}
return 400;
}

/**
* Loads a new path based on the routes.
* Returns true if a navigation was made to a new page.
@@ -387,6 +405,14 @@
// Redirect if necessary
if (isRedirectRoute(route)) {
cleanup();
if (route.awaitStability === true) {
// await until browser is done loading, based on a guess:
const delay = this.getRedirectDelay();
await new Promise((resolve) => setTimeout(resolve, delay));
if (navigationInvalidated) {
return cancel();
}
}

Check warning on line 415 in src/Umbraco.Web.UI.Client/src/packages/core/router/router-slot/router-slot.ts

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/16.0)

❌ Getting worse: Complex Method

RouterSlot.renderPath increases in cyclomatic complexity from 17 to 19, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 415 in src/Umbraco.Web.UI.Client/src/packages/core/router/router-slot/router-slot.ts

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/16.0)

❌ Getting worse: Bumpy Road Ahead

RouterSlot.renderPath increases from 4 to 5 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
handleRedirect(this, route);
return false;
}
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ export class UmbDocumentBlueprintWorkspaceEditorElement extends UmbLitElement {
// Using first single view as the default route for now (hence the math below):
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[variants.length * variants.length]?.path,
});
}
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ export class UmbMediaDashboardElement extends UmbLitElement {
},
{
path: '',
pathMatch: 'full',
redirectTo: 'collection',
},
{
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ export class UmbMediaWorkspaceEditorElement extends UmbLitElement {
// Using first single view as the default route for now (hence the math below):
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[variants.length * variants.length]?.path,
});
}
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ export class UmbMemberWorkspaceEditorElement extends UmbLitElement {
// Using first single view as the default route for now (hence the math below):
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[options.length * options.length]?.path,
});
}
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ export class UmbCreatedPackagesSectionViewElement extends UmbLitElement implemen

routes.push({
path: '',
pathMatch: 'full',
redirectTo: 'overview',
});
routes.push({