fix(custom-widgets): fix v2 editor crash and definition-not-found race (#6377)

This commit is contained in:
Thomas authored and ajnart committed 2026-08-13 19:47:16 +02:00
1 parent f0963405ca
commit 3a1245cbc5
8 files changed
+194 -21

No files matched your search

@@ -253,6 +253,12 @@ export function buildDisplayConfigFromFormValues(values: CustomWidgetDisplayForm
}
function parseRequestManifest(value: string) {
const parsed: unknown = JSON.parse(value);
return customJsxRequestSchema.array().parse(parsed);
let parsed: unknown;
try {
parsed = JSON.parse(value);
} catch {
return [];
}
const result = customJsxRequestSchema.array().safeParse(parsed);
return result.success ? result.data : [];
}
@@ -62,4 +62,16 @@ describe("custom-widget display form contracts", () => {
requests: [{ id: "status", kind: "query", method: "GET" }],
});
});
test("does not throw on invalid request manifest JSON while serializing v2 form state", () => {
const values = requiredFormValues("customJsx");
values.jsxApiVersion = "2";
for (const invalidManifest of ["[invalid", "{not an array}", "", '{"id":1}', "null"]) {
values.requestManifest = invalidManifest;
expect(() => buildDisplayConfigFromFormValues(values)).not.toThrow();
const config = buildDisplayConfigFromFormValues(values) as { requests?: unknown };
expect(config.requests).toEqual([]);
}
});
});
+5
View File
@@ -820,6 +820,10 @@
"editor": {
"saveBlocked": "Resolve the editor errors before saving.",
"saveReady": "The configuration is ready to save.",
"errorBoundary": {
"title": "Something went wrong",
"retry": "Try again"
},
"language": {
"jsx": "JSX",
"json": "JSON"
@@ -4200,6 +4204,7 @@
},
"noDefinition": "No definition selected",
"definitionNotFound": "Widget definition not found. It may have been deleted.",
"editModePending": "Save the board to load this widget.",
"noDisplayOutput": "No display output",
"openJson": "Open in browser JSON viewer",
"execute": "Execute",
+13 -2
View File
@@ -129,7 +129,7 @@ function CustomApiWidgetInner({
const { data, isLoading, error } = clientApi.widget.customApi.getData.useQuery(
{ itemId: itemId ?? "" },
{
enabled: Boolean(itemId),
enabled: Boolean(itemId) && !isEditMode,
refetchInterval: (query) => {
const result = query.state.data as Record<string, unknown> | undefined;
if (
@@ -170,7 +170,18 @@ function CustomApiWidgetInner({
);
}
if (!data) return null;
if (!data) {
if (isEditMode) {
return (
<Center h="100%">
<Text c="dimmed" size="sm" ta="center">
{t("editModePending")}
</Text>
</Center>
);
}
return null;
}
const widgetData = data as Record<string, unknown>;
const dataType = widgetData.type as string | undefined;