Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: AI, Enable adding text to empty container nodes (#2485)

Ivan Starkovb9e003435b84
diff --git a/apps/builder/app/builder/features/ai/ai-fetch-result.ts b/apps/builder/app/builder/features/ai/ai-fetch-result.ts
index cb1ed2935f..6fcb5dc382 100644
--- a/apps/builder/app/builder/features/ai/ai-fetch-result.ts
+++ b/apps/builder/app/builder/features/ai/ai-fetch-result.ts
@@ -163,9 +163,9 @@ export const fetchResult = async (
patchTextInstance(operation);
appliedOperations.add(JSON.stringify(operation));
}
- } catch {
+ } catch (error) {
// eslint-disable-next-line no-console
- console.error("completion failed to parse", completion);
+ console.error(error);
}
}
},
diff --git a/apps/builder/app/builder/features/ai/apply-operations.ts b/apps/builder/app/builder/features/ai/apply-operations.ts
index c2d2442fd0..4035c58fca 100644
--- a/apps/builder/app/builder/features/ai/apply-operations.ts
+++ b/apps/builder/app/builder/features/ai/apply-operations.ts
@@ -191,10 +191,21 @@ export const patchTextInstance = (textInstance: copywriter.TextInstance) => {
serverSyncStore.createTransaction([instancesStore], (instances) => {
const currentInstance = instances.get(textInstance.instanceId);
- if (
- currentInstance === undefined ||
- currentInstance.children.length === 0
- ) {
+ if (currentInstance === undefined) {
+ return;
+ }
+
+ const meta = registeredComponentMetasStore
+ .get()
+ .get(currentInstance.component);
+
+ // Only container components are allowed to have child elements.
+ if (meta?.type !== "container") {
+ return;
+ }
+
+ if (currentInstance.children.length === 0) {
+ currentInstance.children = [{ type: "text", value: textInstance.text }];
return;
}