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: add backwards compatibility for children in code text (#3270)

Oleg Isonen8b998662a4b6
diff --git a/packages/sdk-components-react/src/code-text.tsx b/packages/sdk-components-react/src/code-text.tsx
index d396877713..d2693c2e8c 100644
--- a/packages/sdk-components-react/src/code-text.tsx
+++ b/packages/sdk-components-react/src/code-text.tsx
@@ -23,13 +23,19 @@ const Placeholder = ({
export const CodeText = forwardRef<
ElementRef<typeof defaultTag>,
ComponentProps<typeof defaultTag> & { code?: string }
->(({ code, ...props }, ref) => {
- if (code === undefined || String(code).trim().length === 0) {
+>(({ code, children, ...props }, ref) => {
+ // We are supporting children here for historical reasons, because
+ // the first version of this component allowed using any components inside the CodeText
+ // and we didn't want to migrate them to use code, also it's not entirely possible.
+ if (
+ (children === undefined && code === undefined) ||
+ String(code).trim().length === 0
+ ) {
return <Placeholder innerRef={ref} {...props} />;
}
return (
<code {...props} ref={ref}>
- {code}
+ {code ?? children}
</code>
);
});