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: Fix text binding rendering for non-text values (#5808)

Oleg Isonenc585918459e5
diff --git a/fixtures/react-router-cloudflare/app/__generated__/[another-page]._index.tsx b/fixtures/react-router-cloudflare/app/__generated__/[another-page]._index.tsx
index 879db5f27a..ed6f071611 100644
--- a/fixtures/react-router-cloudflare/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/react-router-cloudflare/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/react-router-cloudflare/app/__generated__/_index.tsx b/fixtures/react-router-cloudflare/app/__generated__/_index.tsx
index 7e9af1e569..566526621e 100644
--- a/fixtures/react-router-cloudflare/app/__generated__/_index.tsx
+++ b/fixtures/react-router-cloudflare/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/react-router-docker/app/__generated__/[another-page]._index.tsx b/fixtures/react-router-docker/app/__generated__/[another-page]._index.tsx
index 879db5f27a..ed6f071611 100644
--- a/fixtures/react-router-docker/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/react-router-docker/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/react-router-docker/app/__generated__/_index.tsx b/fixtures/react-router-docker/app/__generated__/_index.tsx
index 7e9af1e569..566526621e 100644
--- a/fixtures/react-router-docker/app/__generated__/_index.tsx
+++ b/fixtures/react-router-docker/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/react-router-netlify/app/__generated__/[another-page]._index.tsx b/fixtures/react-router-netlify/app/__generated__/[another-page]._index.tsx
index 879db5f27a..ed6f071611 100644
--- a/fixtures/react-router-netlify/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/react-router-netlify/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/react-router-netlify/app/__generated__/_index.tsx b/fixtures/react-router-netlify/app/__generated__/_index.tsx
index 7e9af1e569..566526621e 100644
--- a/fixtures/react-router-netlify/app/__generated__/_index.tsx
+++ b/fixtures/react-router-netlify/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/react-router-vercel/app/__generated__/[another-page]._index.tsx b/fixtures/react-router-vercel/app/__generated__/[another-page]._index.tsx
index 879db5f27a..ed6f071611 100644
--- a/fixtures/react-router-vercel/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/react-router-vercel/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/react-router-vercel/app/__generated__/_index.tsx b/fixtures/react-router-vercel/app/__generated__/_index.tsx
index 7e9af1e569..566526621e 100644
--- a/fixtures/react-router-vercel/app/__generated__/_index.tsx
+++ b/fixtures/react-router-vercel/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/ssg-cloudflare-pages/app/__generated__/[another-page]._index.tsx b/fixtures/ssg-cloudflare-pages/app/__generated__/[another-page]._index.tsx
index d0639b2eb5..4ebcece298 100644
--- a/fixtures/ssg-cloudflare-pages/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/ssg-cloudflare-pages/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Heading as Heading,
diff --git a/fixtures/ssg-cloudflare-pages/app/__generated__/_index.tsx b/fixtures/ssg-cloudflare-pages/app/__generated__/_index.tsx
index 59fb5e41cc..f25a124612 100644
--- a/fixtures/ssg-cloudflare-pages/app/__generated__/_index.tsx
+++ b/fixtures/ssg-cloudflare-pages/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Heading as Heading,
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx
index 16dd018a72..8e97d940d0 100644
--- a/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
export const projectId = "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e";
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx
index fb78075778..4907c249a3 100644
--- a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Heading as Heading,
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx
index 99ca4f29a0..380084eada 100644
--- a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
index d9ef7b52e4..b0fa1ab831 100644
--- a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
index 570ee8537a..886ce11c7b 100644
--- a/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Image as Image } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx b/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
index 2b8a4d0fe6..1c051b000f 100644
--- a/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
Box as Box,
diff --git a/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx b/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx
index 78ee3101c1..5fa87bb0c1 100644
--- a/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
diff --git a/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx b/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
index 56bbffbc7e..6da2f5ebb3 100644
--- a/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Box as Box } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
index 498f2e2513..91ecdf15cf 100644
--- a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
Box as Box,
diff --git a/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx b/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
index ebba89d6bc..c6387894cc 100644
--- a/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { AnimateChildren as AnimateChildren } from "@webstudio-is/sdk-components-animation";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx b/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
index 682f0afc25..652608d643 100644
--- a/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
Heading as Heading,
@@ -40,7 +44,7 @@ const Page = (_props: { system: any }) => {
return (
<Body className={`w-body`}>
<Heading className={`w-heading`}>
- {`${jsonResourceVariable?.data?.args}`}
+ {renderText(`${jsonResourceVariable?.data?.args}`)}
</Heading>
<HtmlEmbed
code={`<script>
@@ -52,7 +56,7 @@ console.log(a, b);
</script>`}
className={`w-html-embed`}
/>
- <Box className={`w-box`}>{globalVariable}</Box>
+ <Box className={`w-box`}>{renderText(globalVariable)}</Box>
</Body>
);
};
diff --git a/fixtures/webstudio-features/app/__generated__/[form]._index.tsx b/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
index d17341725d..d85f966db0 100644
--- a/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Form as Form,
diff --git a/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx b/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
index 2d798da808..bbee83f8e5 100644
--- a/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx b/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
index 024d1986eb..6e0f457261 100644
--- a/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx b/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
index 1605aaecf9..af5656d5fe 100644
--- a/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import { Heading as Heading } from "@webstudio-is/sdk-components-react";
diff --git a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
index efa400f9a5..2dfffa6808 100644
--- a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
Accordion as Accordion,
diff --git a/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx b/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
index 430acda063..5a39c0ac5c 100644
--- a/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
Box as Box,
diff --git a/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx b/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
index 0ce95c387a..d78c0e4a8c 100644
--- a/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
XmlNode as XmlNode,
XmlTime as XmlTime,
@@ -67,9 +71,9 @@ const Page = (_props: { system: any }) => {
<Fragment key={index}>
<XmlNode tag={"url"}>
<XmlNode tag={"loc"}>
- {`${system?.origin ?? "${ORIGIN}"}${url?.path}`}
+ {renderText(`${system?.origin ?? "${ORIGIN}"}${url?.path}`)}
</XmlNode>
- <XmlNode tag={"lastmod"}>{url?.lastModified}</XmlNode>
+ <XmlNode tag={"lastmod"}>{renderText(url?.lastModified)}</XmlNode>
<XmlNode
tag={"xhtml:link"}
rel={"alternate"}
diff --git a/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx b/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
index b19b9cfe78..15301f321e 100644
--- a/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import { Body as Body } from "@webstudio-is/sdk-components-react-router";
import {
AnimateChildren as AnimateChildren,
diff --git a/fixtures/webstudio-features/app/__generated__/_index.tsx b/fixtures/webstudio-features/app/__generated__/_index.tsx
index 7a963c48d5..3cd3788b11 100644
--- a/fixtures/webstudio-features/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/_index.tsx
@@ -2,7 +2,11 @@
/* This is a auto generated file for building the project */
import { Fragment, useState } from "react";
-import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import {
+ renderText,
+ useResource,
+ useVariableState,
+} from "@webstudio-is/react-sdk/runtime";
import {
Body as Body,
Link as Link,
diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts
index d44497aec6..0b4052e939 100644
--- a/packages/cli/src/prebuild.ts
+++ b/packages/cli/src/prebuild.ts
@@ -635,7 +635,7 @@ export const prebuild = async (options: {
/* This is a auto generated file for building the project */ \n
import { Fragment, useState } from "react";
- import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+ import { renderText, useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
${importsString}
export const projectId = "${siteData.build.projectId}";
diff --git a/packages/react-sdk/src/component-generator.test.tsx b/packages/react-sdk/src/component-generator.test.tsx
index 15ba4f023f..2c1e1327b3 100644
--- a/packages/react-sdk/src/component-generator.test.tsx
+++ b/packages/react-sdk/src/component-generator.test.tsx
@@ -381,7 +381,7 @@ test("generate jsx children with expression", () => {
).toEqual(
validateJSX(
clear(`
- {'Hello ' + myvar}
+ {renderText('Hello ' + myvar)}
`)
)
);
@@ -515,7 +515,7 @@ test("generate collection component with itemKey", () => {
return (
<Fragment key={key}>
<Label>
- {key}
+ {renderText(key)}
</Label>
<Button
aria-label={element} />
@@ -1148,13 +1148,13 @@ test("generate unset variables as undefined", () => {
).toEqual(
validateJSX(
clear(`
- const Page = () => {
- return <Body>
- <Box>
- {undefined + undefined}
- </Box>
- </Body>
- }
+ const Page = () => {
+ return <Body>
+ <Box>
+ {renderText(undefined + undefined)}
+ </Box>
+ </Body>
+ }
`)
)
);
@@ -1187,7 +1187,7 @@ test("generate global variables", () => {
let [rootVariable, set$rootVariable] = useVariableState<any>("root")
return <Body>
<Box>
- {rootVariable}
+ {renderText(rootVariable)}
</Box>
</Body>
}
diff --git a/packages/react-sdk/src/component-generator.ts b/packages/react-sdk/src/component-generator.ts
index 7bb30798b0..052260e51c 100644
--- a/packages/react-sdk/src/component-generator.ts
+++ b/packages/react-sdk/src/component-generator.ts
@@ -400,7 +400,7 @@ export const generateJsxChildren = ({
usedDataSources,
scope,
});
- generatedChildren = `{${expression}}\n`;
+ generatedChildren = `{renderText(${expression})}\n`;
continue;
}
if (child.type === "id") {
diff --git a/packages/react-sdk/src/context.test.tsx b/packages/react-sdk/src/context.test.tsx
new file mode 100644
index 0000000000..88dd18a3fe
--- /dev/null
+++ b/packages/react-sdk/src/context.test.tsx
@@ -0,0 +1,55 @@
+import { renderToStaticMarkup } from "react-dom/server";
+import { expect, test } from "vitest";
+
+import { renderText } from "./context";
+
+const renderTextBinding = (value: unknown) =>
+ renderToStaticMarkup(<div>{renderText(value)}</div>);
+
+test("failed resource status binding renders the status code", () => {
+ const resource = {
+ ok: false,
+ status: 500,
+ statusText: "Internal Server Error",
+ data: { message: "Internal Server Error" },
+ };
+ const html = renderTextBinding(resource.status);
+
+ expect(html).toBe("<div>500</div>");
+});
+
+test("application error field binding renders the error message", () => {
+ const resource = {
+ ok: true,
+ status: 200,
+ statusText: "OK",
+ data: { error: "permission denied" },
+ };
+ const html = renderTextBinding(resource.data.error);
+
+ expect(html).toBe("<div>permission denied</div>");
+});
+
+test("failed resource object binding renders empty text instead of crashing", () => {
+ const resource = {
+ ok: false,
+ status: 500,
+ statusText: "Internal Server Error",
+ data: { message: "Internal Server Error" },
+ };
+ const html = renderTextBinding(resource);
+
+ expect(html).toBe("<div></div>");
+});
+
+test("object-valued data binding renders empty text instead of crashing", () => {
+ const resource = {
+ data: { title: "Changed shape" },
+ ok: true,
+ status: 200,
+ statusText: "OK",
+ };
+ const html = renderTextBinding(resource.data);
+
+ expect(html).toBe("<div></div>");
+});
diff --git a/packages/react-sdk/src/context.tsx b/packages/react-sdk/src/context.tsx
index 4c7289e189..be06dfc88c 100644
--- a/packages/react-sdk/src/context.tsx
+++ b/packages/react-sdk/src/context.tsx
@@ -65,3 +65,7 @@ export const useResource = (name: string) => {
return resourceMemozied;
};
+
+export const renderText = (value: unknown) => {
+ return typeof value === "string" || typeof value === "number" ? value : "";
+};