Skip to content

Commit 9dc391c

Browse files
authored
perf(ui): keep config render helpers lazy (#126754)
Restore the cross-platform Control UI startup gzip budget by keeping render-only sensitive-path helpers outside the startup config-draft graph. Preserve existing behavior and caller APIs while moving generic schema, search, and path helpers to their existing startup owner.
1 parent 695c16b commit 9dc391c

7 files changed

Lines changed: 112 additions & 115 deletions

File tree

‎ui/src/components/config-form.array-items.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { schemaType, type JsonSchema } from "./config-form.shared.ts";
1+
import { schemaType, type JsonSchema } from "../lib/config-form-utils.ts";
22

33
export function collectAllOfSchemas(schema: JsonSchema): JsonSchema[] {
44
const result: JsonSchema[] = [];

‎ui/src/components/config-form.search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
22
import type { ConfigUiHints } from "../api/types.ts";
3+
import { hintForPath, humanize, schemaType, type JsonSchema } from "../lib/config-form-utils.ts";
34
import { arrayItemSchema, arrayItemSchemaIndexes } from "./config-form.array-items.ts";
4-
import { hintForPath, humanize, schemaType, type JsonSchema } from "./config-form.shared.ts";
55

66
export type ConfigSearchCriteria = {
77
text: string;

‎ui/src/components/config-form.shared.ts‎

Lines changed: 9 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,16 @@
11
import { isSensitiveConfigPath } from "../../../src/config/sensitive-paths.js";
22
import type { ConfigUiHint, ConfigUiHints } from "../api/types.ts";
3-
// Control UI view renders config form.shared screen content.
43
import { t } from "../i18n/index.ts";
4+
import { hintForPath, pathKey } from "../lib/config-form-utils.ts";
55

6-
export type JsonSchema = {
7-
type?: string | string[];
8-
title?: string;
9-
description?: string;
10-
tags?: string[];
11-
"x-tags"?: string[];
12-
properties?: Record<string, JsonSchema>;
13-
required?: string[];
14-
items?: JsonSchema | JsonSchema[];
15-
additionalItems?: JsonSchema | boolean;
16-
additionalProperties?: JsonSchema | boolean;
17-
enum?: unknown[];
18-
enumIncludesNull?: boolean;
19-
const?: unknown;
20-
default?: unknown;
21-
minimum?: number;
22-
maximum?: number;
23-
exclusiveMinimum?: number;
24-
exclusiveMaximum?: number;
25-
multipleOf?: number;
26-
minLength?: number;
27-
maxLength?: number;
28-
pattern?: string;
29-
minItems?: number;
30-
maxItems?: number;
31-
uniqueItems?: boolean;
32-
anyOf?: JsonSchema[];
33-
oneOf?: JsonSchema[];
34-
allOf?: JsonSchema[];
35-
nullable?: boolean;
36-
};
37-
38-
export function schemaType(schema: JsonSchema): string | undefined {
39-
if (!schema) {
40-
return undefined;
41-
}
42-
if (Array.isArray(schema.type)) {
43-
return schema.type.find((type) => type !== "null") ?? schema.type[0];
44-
}
45-
return schema.type;
46-
}
47-
48-
export function schemaMayAcceptString(schema: JsonSchema): boolean {
49-
const declaredTypes = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
50-
if (declaredTypes.length > 0 && !declaredTypes.includes("string")) {
51-
return false;
52-
}
53-
if (schema.const !== undefined && typeof schema.const !== "string") {
54-
return false;
55-
}
56-
if (schema.enum && !schema.enum.some((entry) => typeof entry === "string")) {
57-
return false;
58-
}
59-
if (schema.allOf && !schema.allOf.every(schemaMayAcceptString)) {
60-
return false;
61-
}
62-
if (schema.anyOf && !schema.anyOf.some(schemaMayAcceptString)) {
63-
return false;
64-
}
65-
if (schema.oneOf && !schema.oneOf.some(schemaMayAcceptString)) {
66-
return false;
67-
}
68-
return true;
69-
}
6+
export {
7+
hintForPath,
8+
humanize,
9+
pathKey,
10+
schemaMayAcceptString,
11+
schemaType,
12+
type JsonSchema,
13+
} from "../lib/config-form-utils.ts";
7014

7115
export function configFieldId(path: Array<string | number>, suffix: string): string {
7216
const key =
@@ -86,47 +30,6 @@ export function configFieldId(path: Array<string | number>, suffix: string): str
8630
return `config-field-${key}-${suffix}`;
8731
}
8832

89-
export function pathKey(path: Array<string | number>): string {
90-
return path.filter((segment) => typeof segment === "string").join(".");
91-
}
92-
93-
export function hintForPath(path: Array<string | number>, hints: ConfigUiHints) {
94-
const key = pathKey(path);
95-
const direct = hints[key];
96-
if (direct) {
97-
return direct;
98-
}
99-
const segments = path.map(String);
100-
for (const [hintKey, hint] of Object.entries(hints)) {
101-
if (!hintKey.includes("*")) {
102-
continue;
103-
}
104-
const hintSegments = hintKey.split(".");
105-
if (hintSegments.length !== segments.length) {
106-
continue;
107-
}
108-
let match = true;
109-
for (let i = 0; i < segments.length; i += 1) {
110-
if (hintSegments[i] !== "*" && hintSegments[i] !== segments[i]) {
111-
match = false;
112-
break;
113-
}
114-
}
115-
if (match) {
116-
return hint;
117-
}
118-
}
119-
return undefined;
120-
}
121-
122-
export function humanize(raw: string) {
123-
return raw
124-
.replace(/_/g, " ")
125-
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
126-
.replace(/\s+/g, " ")
127-
.replace(/^./, (m) => m.toUpperCase());
128-
}
129-
13033
const ENV_VAR_PLACEHOLDER_PATTERN = /^\$\{[^}]*\}$/;
13134

13235
export function redactedPlaceholder(): string {

‎ui/src/components/config-form.tiers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ConfigUiHints } from "../api/types.ts";
2-
import { hintForPath, type JsonSchema } from "./config-form.shared.ts";
2+
import { hintForPath, type JsonSchema } from "../lib/config-form-utils.ts";
33

44
type ConfigSchemaTierSplit = {
55
common: JsonSchema | null;

‎ui/src/lib/config-form-utils.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,101 @@
11
// Control UI controller manages form utils gateway state.
22
import { isRecord } from "@openclaw/normalization-core/record-coerce";
3+
import type { ConfigUiHints } from "../api/types.ts";
4+
5+
export type JsonSchema = {
6+
type?: string | string[];
7+
title?: string;
8+
description?: string;
9+
tags?: string[];
10+
"x-tags"?: string[];
11+
properties?: Record<string, JsonSchema>;
12+
required?: string[];
13+
items?: JsonSchema | JsonSchema[];
14+
additionalItems?: JsonSchema | boolean;
15+
additionalProperties?: JsonSchema | boolean;
16+
enum?: unknown[];
17+
enumIncludesNull?: boolean;
18+
const?: unknown;
19+
default?: unknown;
20+
minimum?: number;
21+
maximum?: number;
22+
exclusiveMinimum?: number;
23+
exclusiveMaximum?: number;
24+
multipleOf?: number;
25+
minLength?: number;
26+
maxLength?: number;
27+
pattern?: string;
28+
minItems?: number;
29+
maxItems?: number;
30+
uniqueItems?: boolean;
31+
anyOf?: JsonSchema[];
32+
oneOf?: JsonSchema[];
33+
allOf?: JsonSchema[];
34+
nullable?: boolean;
35+
};
36+
37+
export function schemaType(schema: JsonSchema): string | undefined {
38+
if (!schema) {
39+
return undefined;
40+
}
41+
if (Array.isArray(schema.type)) {
42+
return schema.type.find((type) => type !== "null") ?? schema.type[0];
43+
}
44+
return schema.type;
45+
}
46+
47+
export function schemaMayAcceptString(schema: JsonSchema): boolean {
48+
const declaredTypes = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
49+
if (declaredTypes.length > 0 && !declaredTypes.includes("string")) {
50+
return false;
51+
}
52+
if (schema.const !== undefined && typeof schema.const !== "string") {
53+
return false;
54+
}
55+
if (schema.enum && !schema.enum.some((entry) => typeof entry === "string")) {
56+
return false;
57+
}
58+
if (schema.allOf && !schema.allOf.every(schemaMayAcceptString)) {
59+
return false;
60+
}
61+
if (schema.anyOf && !schema.anyOf.some(schemaMayAcceptString)) {
62+
return false;
63+
}
64+
return !schema.oneOf || schema.oneOf.some(schemaMayAcceptString);
65+
}
66+
67+
export function pathKey(path: Array<string | number>): string {
68+
return path.filter((segment) => typeof segment === "string").join(".");
69+
}
70+
71+
export function hintForPath(path: Array<string | number>, hints: ConfigUiHints) {
72+
const direct = hints[pathKey(path)];
73+
if (direct) {
74+
return direct;
75+
}
76+
const segments = path.map(String);
77+
for (const [hintKey, hint] of Object.entries(hints)) {
78+
if (!hintKey.includes("*")) {
79+
continue;
80+
}
81+
const hintSegments = hintKey.split(".");
82+
if (
83+
hintSegments.length === segments.length &&
84+
hintSegments.every((segment, index) => segment === "*" || segment === segments[index])
85+
) {
86+
return hint;
87+
}
88+
}
89+
return undefined;
90+
}
91+
92+
export function humanize(raw: string) {
93+
return raw
94+
.replace(/_/g, " ")
95+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
96+
.replace(/\s+/g, " ")
97+
.replace(/^./, (m) => m.toUpperCase());
98+
}
399

4100
export function cloneConfigObject<T>(value: T): T {
5101
return structuredClone(value);

‎ui/src/lib/config/config-draft-model.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ import {
55
import { GatewayRequestError } from "../../api/gateway.ts";
66
import type { ConfigSnapshot } from "../../api/types.ts";
77
import { coerceConfigFormNumberString } from "../../components/config-form.numeric.ts";
8-
import {
9-
schemaMayAcceptString,
10-
schemaType,
11-
type JsonSchema,
12-
} from "../../components/config-form.shared.ts";
138
import { t } from "../../i18n/index.ts";
149
import {
1510
cloneConfigObject,
1611
removePathValue,
1712
sanitizeRedactedFormForSubmit,
13+
schemaMayAcceptString,
14+
schemaType,
1815
serializeConfigForm,
1916
setPathValue,
17+
type JsonSchema,
2018
} from "../config-form-utils.ts";
2119
import { formatUiError } from "../format-error.ts";
2220
import { parseJson5Text, warmJson5 } from "../json5-runtime.ts";

‎ui/src/pages/config/settings-search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
matchesConfigSectionSearch,
1111
parseConfigSearchQuery,
1212
} from "../../components/config-form.search.ts";
13-
import { schemaType, type JsonSchema } from "../../components/config-form.shared.ts";
1413
import { splitConfigSchemaByTier } from "../../components/config-form.tiers.ts";
1514
import { t } from "../../i18n/index.ts";
15+
import { schemaType, type JsonSchema } from "../../lib/config-form-utils.ts";
1616
import { configPageForSection } from "./config-sections.ts";
1717
import { memoryVisibleSchemaKeys } from "./memory-schema.ts";
1818
import { SETTINGS_SEARCH_TARGETS, type SettingsSearchTarget } from "./settings-targets.ts";

0 commit comments

Comments
 (0)