From 47bfa4dd6ba36a929022e08bbb174ab245a8e9f3 Mon Sep 17 00:00:00 2001 From: liuly Date: Sun, 13 Sep 2026 01:42:02 +0800 Subject: [PATCH 1/2] perf: load agent workspace asynchronously --- src/components/App.tsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index f0bc2d16..907047c1 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -29,7 +29,6 @@ import { ModalOpen } from "./modals/ModalOpen"; import { ModalShortcuts } from "./modals/ModalShortcuts"; import { ModalDebug } from "./modals/ModalDebug"; import { ModalGlobalState } from "./modals/ModalGlobalState"; -import { ModalAgentWorkspace } from "./modals/ModalAgentWorkspace"; import {downloadGlyphsMetadata, downloadSpriteMetadata} from "../libs/metadata"; import { emptyStyle, replaceAccessTokenInUrl, replaceAccessTokens } from "../libs/style"; @@ -44,6 +43,14 @@ import { type MappedError, type OnStyleChangedOpts, type StyleSpecificationWithI import { DatasetStore } from "../libs/dataset-store"; import type { MapOpenLayers } from "./MapOpenLayers"; +// Keep the agent workspace out of the initial bundle, while still loading it +// by default because the lazy component is rendered with the other modals. +const LazyModalAgentWorkspace = React.lazy(() => + import("./modals/ModalAgentWorkspace").then(({ModalAgentWorkspace}) => ({ + default: ModalAgentWorkspace, + })) +); + // Buffer must be defined globally for @maplibre/maplibre-gl-style-spec validate() function to succeed. window.Buffer = buffer.Buffer; @@ -1036,16 +1043,18 @@ export class App extends React.Component { isOpen={this.state.isOpen.globalState} onOpenToggle={() => this.toggleModal("globalState")} /> - this.toggleModal("agentConsole")} - getMap={this.getAgentMap} - getMaputnikStyle={this.getAgentMaputnikStyle} - updateMaputnikStyle={this.updateAgentMaputnikStyle} - datasetStore={this.datasetStore} - onDatasetsChange={this.onDatasetsChange} - renderer={this._getRenderer()} - /> + + this.toggleModal("agentConsole")} + getMap={this.getAgentMap} + getMaputnikStyle={this.getAgentMaputnikStyle} + updateMaputnikStyle={this.updateAgentMaputnikStyle} + datasetStore={this.datasetStore} + onDatasetsChange={this.onDatasetsChange} + renderer={this._getRenderer()} + /> + ; return Date: Sun, 13 Sep 2026 02:04:06 +0800 Subject: [PATCH 2/2] fix: show agent workspace loading state --- src/components/App.tsx | 14 +++++++++++++- src/styles/_agent-workspace.scss | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 907047c1..726e2092 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -51,6 +51,18 @@ const LazyModalAgentWorkspace = React.lazy(() => })) ); +const AgentWorkspaceLoading = () =>
+ + {i18next.t("Loading")} +
; + // Buffer must be defined globally for @maplibre/maplibre-gl-style-spec validate() function to succeed. window.Buffer = buffer.Buffer; @@ -1043,7 +1055,7 @@ export class App extends React.Component { isOpen={this.state.isOpen.globalState} onOpenToggle={() => this.toggleModal("globalState")} /> - + : null}> this.toggleModal("agentConsole")} diff --git a/src/styles/_agent-workspace.scss b/src/styles/_agent-workspace.scss index 42e34c7a..02afff5a 100644 --- a/src/styles/_agent-workspace.scss +++ b/src/styles/_agent-workspace.scss @@ -63,6 +63,22 @@ $agent-workspace-map-offset: vars.$layout-list-width + vars.$layout-editor-width cursor: pointer; } +.maputnik-agent-workspace-loading { + position: fixed; + top: 50%; + left: 50%; + z-index: 1051; + max-width: calc(100vw - 32px); + margin: 0; + padding: vars.$margin-3 vars.$margin-4; + transform: translate(-50%, -50%); + border: 1px solid rgba(164, 164, 164, 0.34); + border-radius: 9px; + background-color: vars.$color-black; + box-shadow: 0 24px 72px rgba(0, 0, 0, 0.48), 0 2px 12px rgba(0, 0, 0, 0.34); + pointer-events: none; +} + body.maputnik-modal-open { overflow: hidden; }