From 20528f3e4287149fbc7123f75e170cb5663f0a76 Mon Sep 17 00:00:00 2001 From: Vladyslav Prykhodko Date: Thu, 26 Nov 2026 11:27:26 +0200 Subject: [PATCH] Improved loading speed of code editors and fixed shifted or failing dashboard image screenshots (#16813) * UI: Load Ace modes, snippets and themes on demand The first editor used to load all 14 modes, 11 snippet files and 2 themes up front (901 KB, 29 requests). Ace now loads only what an editor uses through config.setModuleLoader; a JSON editor loads 534 KB in 5 requests. - Once a module is defined, its loader is removed, so Ace resolves it synchronously again, as before. - getAce() accepts modules to preload for editors that read the session mode synchronously after setMode; js-func preloads javascript and tbel. - mode-c_cpp and snippets/protobuf are no longer loaded: no editor uses the C/C++ mode, mode-protobuf bundles its own copy, and the protobuf mode takes its snippets from snippets/c_cpp. * UI: Load the SystemJS modules map lazily and cut eager imports of home code - The SystemJS modules map, which imports most of the application, now loads only when a widget or rule node loads an extension module. Pages and dashboards no longer carry it. - WidgetService, DashboardUtilsService and HomeService no longer import the widget config component, the dashboard component models and the router tabs component, which kept them in the login bundle: the basic config base class is passed to registerBasicWidgetConfigComponents, the gridster limits moved to shared dashboard models (re-exported from the old place), and router tabs are detected by a flag instead of instanceof. - BlobEntitiesComponent reads the header actions panel from the widget context instead of injecting WidgetComponent. That import closed the only NgModule import cycle (SharedHomeComponentsModule -> WidgetComponentsModule), which crashed startup with "Cannot read properties of undefined (reading 'ngModule')" when the module init order changed. * UI: Take dashboard screenshots with modern-screenshot, loaded on demand The dashboard image dialog used html2canvas, which is no longer maintained. It shifted and cropped the captured area and failed on dashboards that use the CSS color() function (charts, gauges, maps). - modern-screenshot (MIT, no dependencies, 10 KB gzip instead of 44 KB) renders the dashboard through the browser itself, so the thumbnail matches the page. It loads only when a screenshot is taken. - The whole dashboard is captured and the selected area is cut out of the canvas; the development notice is still stamped before the image is serialised. - Elements marked with data-html2canvas-ignore are still left out, and videos with no source are skipped, since the capture would wait for them forever. * UI: Import entity type models directly in entity chips instead of the shared public API barrel The barrel re-exports report-component.models, which imports the time series chart models and with them echarts and zrender. Any eager import path to entity chips would pull ~1.7 MB of chart code into the startup bundle, as happened in PE through the AI audit log dialog. --- .../DevelopmentNoticeCaptureStampTest.java | 2 +- ui-ngx/package.json | 2 +- ui-ngx/src/app/core/http/widget.service.ts | 9 +- .../core/services/dashboard-utils.service.ts | 2 +- ui-ngx/src/app/core/services/home.service.ts | 7 +- .../app/modules/common/lazy-modules-map.ts | 18 +++ .../blob-entity/blob-entities.component.html | 2 +- .../blob-entity/blob-entities.component.ts | 5 +- .../dashboard-image-dialog.component.ts | 42 ++++-- .../entity/entity-chips.component.ts | 2 +- .../home/components/home-components.module.ts | 4 +- .../home/components/router-tabs.component.ts | 2 + .../basic/basic-widget-config.module.ts | 3 +- .../home/models/dashboard-component.models.ts | 3 +- .../shared/components/js-func.component.ts | 2 +- .../src/app/shared/models/ace/ace.models.ts | 121 +++++++++++------- .../src/app/shared/models/dashboard.models.ts | 3 + ui-ngx/yarn.lock | 39 +----- 18 files changed, 151 insertions(+), 117 deletions(-) create mode 100644 ui-ngx/src/app/modules/common/lazy-modules-map.ts diff --git a/application/src/test/java/org/thingsboard/server/controller/DevelopmentNoticeCaptureStampTest.java b/application/src/test/java/org/thingsboard/server/controller/DevelopmentNoticeCaptureStampTest.java index 6a0631fd98..bf401d10fe 100644 --- a/application/src/test/java/org/thingsboard/server/controller/DevelopmentNoticeCaptureStampTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/DevelopmentNoticeCaptureStampTest.java @@ -62,7 +62,7 @@ public class DevelopmentNoticeCaptureStampTest { .as("no subscribing call to %s in the capture path to order against", STAMP_METHOD) .isTrue(); - int captured = capture.indexOf("html2canvas("); + int captured = capture.indexOf("domToCanvas("); int serialised = capture.indexOf("toDataURL"); assertThat(captured).as("no capture call found to order against").isNotNegative(); assertThat(serialised).as("no serialisation call found to order against").isNotNegative(); diff --git a/ui-ngx/package.json b/ui-ngx/package.json index 0364996e3c..bd9ce3d1b1 100644 --- a/ui-ngx/package.json +++ b/ui-ngx/package.json @@ -63,7 +63,6 @@ "flot": "https://github.com/thingsboard/flot.git#0.9-work", "flot.curvedlines": "https://github.com/MichaelZinsmaier/CurvedLines.git#master", "font-awesome": "^4.7.0", - "html2canvas": "^1.4.1", "hugerte": "~1.0.14", "jquery": "^3.7.1", "jquery-sparkline": "^2.4.0", @@ -82,6 +81,7 @@ "libphonenumber-js": "^1.13.15", "maplibre-gl": "6.15.0", "marked": "~16.4.2", + "modern-screenshot": "^4.7.0", "moment": "^2.31.0", "moment-timezone": "^0.6.5", "ngx-captcha": "^14.0.0", diff --git a/ui-ngx/src/app/core/http/widget.service.ts b/ui-ngx/src/app/core/http/widget.service.ts index 0f25a0b2f0..47f7923b9b 100644 --- a/ui-ngx/src/app/core/http/widget.service.ts +++ b/ui-ngx/src/app/core/http/widget.service.ts @@ -26,10 +26,7 @@ import { filter, map, mergeMap, tap } from 'rxjs/operators'; import { WidgetTypeId } from '@shared/models/id/widget-type-id'; import { NULL_UUID } from '@shared/models/id/has-uuid'; import { ActivationEnd, Router } from '@angular/router'; -import { - BasicWidgetConfigComponent, - IBasicWidgetConfigComponent -} from '@home/components/widget/config/widget-config.component.models'; +import type { BasicWidgetConfigComponent, IBasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; import { ResourcesService } from '@core/services/resources.service'; import { UserPermissionsService } from '@core/http/user-permissions.service'; import { Operation, Resource } from '@shared/models/security.models'; @@ -301,8 +298,8 @@ export class WidgetService { this.widgetsInfoInMemoryCache.set(widgetInfo.fullFqn, widgetInfo); } - public registerBasicWidgetConfigComponents(module: any) { - Object.assign(this.basicWidgetSettingsComponentsMap, this.resourcesService.extractComponentsFromModule(module, BasicWidgetConfigComponent)); + public registerBasicWidgetConfigComponents(module: any, baseType: typeof BasicWidgetConfigComponent) { + Object.assign(this.basicWidgetSettingsComponentsMap, this.resourcesService.extractComponentsFromModule(module, baseType)); } public getBasicWidgetSettingsComponentBySelector(selector: string): Type { diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index a121cddf28..ffa249754c 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -65,7 +65,7 @@ import { BackgroundType, colorBackground, isBackgroundSettings } from '@shared/m import { MediaBreakpoints } from '@shared/models/constants'; import { TranslateService } from '@ngx-translate/core'; import { DashboardPageLayout } from '@home/components/dashboard-page/dashboard-page.models'; -import { maxGridsterCol, maxGridsterRow } from '@home/models/dashboard-component.models'; +import { maxGridsterCol, maxGridsterRow } from '@shared/models/dashboard.models'; import { findWidgetModelDefinition, widgetHasTimewindow, diff --git a/ui-ngx/src/app/core/services/home.service.ts b/ui-ngx/src/app/core/services/home.service.ts index f90ee379df..82a35e4fca 100644 --- a/ui-ngx/src/app/core/services/home.service.ts +++ b/ui-ngx/src/app/core/services/home.service.ts @@ -1,10 +1,11 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { EventEmitter, Injectable } from '@angular/core'; import { ActiveComponentService } from '@core/services/active-component.service'; import { BehaviorSubject, Observable, shareReplay, Subject } from 'rxjs'; import { distinctUntilChanged } from 'rxjs/operators'; -import { RouterTabsComponent } from '@home/components/router-tabs.component'; +import type { RouterTabsComponent } from '@home/components/router-tabs.component'; import { isDefinedAndNotNull } from '@core/utils'; import { PageComponent } from '@shared/components/page.component'; @@ -43,7 +44,7 @@ export class HomeService { private activeComponentChanged(activeComponent: any) { this.hideMainToolbarSubject.next(false); let hideLoadingBar = false; - if (activeComponent && activeComponent instanceof RouterTabsComponent + if (activeComponent && (activeComponent as RouterTabsComponent).isRouterTabsComponent && isDefinedAndNotNull(activeComponent.activatedRoute?.snapshot?.data?.showMainLoadingBar)) { hideLoadingBar = !activeComponent.activatedRoute.snapshot.data.showMainLoadingBar; } else if (activeComponent && activeComponent instanceof PageComponent diff --git a/ui-ngx/src/app/modules/common/lazy-modules-map.ts b/ui-ngx/src/app/modules/common/lazy-modules-map.ts new file mode 100644 index 0000000000..ce46d971b3 --- /dev/null +++ b/ui-ngx/src/app/modules/common/lazy-modules-map.ts @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { defer, map, Observable, shareReplay, switchMap } from 'rxjs'; +import { IModulesMap } from '@modules/common/modules-map.models'; + +class LazyModulesMap implements IModulesMap { + + private modulesMap$: Observable = defer(() => import('@modules/common/modules-map')).pipe( + switchMap(module => module.modulesMap.init().pipe(map(() => module.modulesMap))), + shareReplay(1) + ); + + init(): Observable { + return this.modulesMap$; + } +} + +export const lazyModulesMap = new LazyModulesMap(); diff --git a/ui-ngx/src/app/modules/home/components/blob-entity/blob-entities.component.html b/ui-ngx/src/app/modules/home/components/blob-entity/blob-entities.component.html index 7d170239bc..3352070adf 100644 --- a/ui-ngx/src/app/modules/home/components/blob-entity/blob-entities.component.html +++ b/ui-ngx/src/app/modules/home/components/blob-entity/blob-entities.component.html @@ -20,7 +20,7 @@ asButton historyOnly> @if (widgetMode) { - + } @else {