🐛 Address preview review and CI failures

This commit is contained in:
Baptiste Arnaud 2026-07-10 11:41:32 +02:00
parent 83454187c1
commit 1592ea1fc8
No known key found for this signature in database
12 changed files with 6028 additions and 7314 deletions

View File

@ -25,15 +25,11 @@ export const WebPreview = () => {
savedPreviewKey.current = previewKey;
setIsSavingBeforePreview(true);
let isMounted = true;
save().finally(() => {
if (isMounted) setIsSavingBeforePreview(false);
if (savedPreviewKey.current === previewKey)
setIsSavingBeforePreview(false);
});
return () => {
isMounted = false;
};
}, [previewKey, save, typebot]);
const handleNewLogs = (logs: ContinueChatResponse["logs"]) => {

View File

@ -17,7 +17,10 @@ export const SettingsPage = () => {
<div className="flex flex-1 h-[calc(100%-2rem)] w-full border rounded-xl mr-4 bg-gray-1">
{typebot && (
<Standard
typebot={typebot}
typebot={typebot.id}
previewSettings={typebot.settings}
previewTheme={typebot.theme}
isPreview
apiHost={window.location.origin}
style={{
borderRadius: "0.75rem",

View File

@ -17,7 +17,10 @@ export const ThemePage = () => {
<div className="flex flex-1 h-[calc(100%-2rem)] w-full border rounded-xl mr-4 bg-gray-1">
{typebot && (
<Standard
typebot={typebot}
typebot={typebot.id}
previewSettings={typebot.settings}
previewTheme={typebot.theme}
isPreview
apiHost={window.location.origin}
style={{
borderRadius: "0.75rem",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -607,7 +607,7 @@
},
"packages/embeds/js": {
"name": "@typebot.io/js",
"version": "0.10.5",
"version": "0.10.6",
"devDependencies": {
"@ai-sdk/ui-utils": "^1.2.11",
"@ark-ui/solid": "^5.19.0",
@ -642,7 +642,7 @@
},
"packages/embeds/react": {
"name": "@typebot.io/react",
"version": "0.10.5",
"version": "0.10.6",
"dependencies": {
"@typebot.io/js": "workspace:*",
"react": "^19.2.4",

View File

@ -1,21 +1,21 @@
{
"name": "@typebot.io/js",
"version": "0.10.5",
"version": "0.10.6",
"description": "Javascript library to display typebots on your website",
"license": "FSL-1.1-ALv2",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./dist/packages/embeds/js/src/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"types": "./dist/packages/embeds/js/src/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./web": {
"types": "./dist/web.d.ts",
"types": "./dist/packages/embeds/js/src/web.d.ts",
"import": "./dist/web.js",
"default": "./dist/web.js"
}

View File

@ -49,8 +49,10 @@ import { ProgressBar } from "./ProgressBar";
export type BotProps = {
id?: string;
typebot?: string | StartTypebot;
typebot?: string;
templateSlug?: string;
previewSettings?: StartTypebot["settings"];
previewTheme?: StartTypebot["theme"];
isPreview?: boolean;
resultId?: string;
prefilledVariables?: Record<string, unknown>;
@ -79,6 +81,8 @@ export const Bot = (props: BotProps & { class?: string }) => {
const [customCss, setCustomCss] = createSignal("");
const [isInitialized, setIsInitialized] = createSignal(false);
const [error, setError] = createSignal<Error | undefined>();
const isPreview = () =>
isNotEmpty(props.templateSlug) || (props.isPreview ?? false);
const initializeBot = async () => {
if (props.font) injectFont(props.font);
@ -89,13 +93,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
urlParams.forEach((value, key) => {
prefilledVariables[key] = value;
});
const typebotIdFromProps =
typeof props.typebot === "string" ? props.typebot : undefined;
const isTemplatePreview = isNotEmpty(props.templateSlug);
const isPreview =
isTemplatePreview ||
typeof props.typebot !== "string" ||
(props.isPreview ?? false);
const typebotIdFromProps = props.typebot;
const resultIdInStorage =
getExistingResultIdFromStorage(typebotIdFromProps);
const { data, error } = await startChatQuery({
@ -103,7 +101,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
typebot: props.typebot,
templateSlug: props.templateSlug,
apiHost: props.apiHost,
isPreview,
isPreview: isPreview(),
resultId: isNotEmpty(props.resultId) ? props.resultId : resultIdInStorage,
prefilledVariables: {
...prefilledVariables,
@ -113,7 +111,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
sessionId: props.sessionId,
});
if (error instanceof HTTPError) {
if (isPreview) {
if (isPreview()) {
return setError(
new Error("An error occurred while loading the bot.", {
cause: {
@ -141,7 +139,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
if (!data) {
if (error) {
console.error(error);
if (isPreview) {
if (isPreview()) {
return setError(
new Error("Error! Could not reach server. Check your connection.", {
cause: error,
@ -208,7 +206,9 @@ export const Bot = (props: BotProps & { class?: string }) => {
props.onChatStatePersisted?.(false, { typebotId: data.typebot.id });
}
setCustomCss(data.typebot.theme.customCss ?? "");
setCustomCss(
props.previewTheme?.customCss ?? data.typebot.theme.customCss ?? "",
);
};
createEffect(() => {
@ -221,11 +221,10 @@ export const Bot = (props: BotProps & { class?: string }) => {
});
createEffect(() => {
if (isNotDefined(props.typebot) || typeof props.typebot === "string")
return;
setCustomCss(props.typebot.theme.customCss ?? "");
if (isNotDefined(props.previewTheme)) return;
setCustomCss(props.previewTheme.customCss ?? "");
if (
props.typebot.theme.general?.progressBar?.isEnabled &&
props.previewTheme.general?.progressBar?.isEnabled &&
initialChatReply() &&
!initialChatReply()?.typebot.theme.general?.progressBar?.isEnabled
) {
@ -253,30 +252,20 @@ export const Bot = (props: BotProps & { class?: string }) => {
typebot: {
...initialChatReply.typebot,
settings:
typeof props.typebot === "string" || !props.typebot
? initialChatReply.typebot.settings
: props.typebot?.settings,
theme:
typeof props.typebot === "string" || !props.typebot
? initialChatReply.typebot.theme
: props.typebot?.theme,
props.previewSettings ?? initialChatReply.typebot.settings,
theme: props.previewTheme ?? initialChatReply.typebot.theme,
},
}}
context={{
apiHost: props.apiHost,
wsHost: props.wsHost,
isPreview:
typeof props.typebot !== "string" || (props.isPreview ?? false),
isPreview: isPreview(),
resultId: initialChatReply.resultId,
sessionId: initialChatReply.sessionId,
typebot: initialChatReply.typebot,
storage:
initialChatReply.typebot.settings.general?.rememberUser
?.isEnabled &&
!(
typeof props.typebot !== "string" ||
(props.isPreview ?? false)
)
?.isEnabled && !isPreview()
? (initialChatReply.typebot.settings.general?.rememberUser
?.storage ?? defaultSettings.general.rememberUser.storage)
: undefined,

View File

@ -4,7 +4,6 @@ import type {
StartChatResponse,
StartFrom,
StartPreviewChatInput,
StartTypebot,
} from "@typebot.io/chat-api/schemas";
import { isNotDefined, isNotEmpty } from "@typebot.io/lib/utils";
import ky from "ky";
@ -17,7 +16,7 @@ import { getIframeReferrerOrigin } from "../utils/getIframeReferrerOrigin";
import { guessApiHost } from "../utils/guessApiHost";
type Props = {
typebot?: string | StartTypebot;
typebot?: string;
templateSlug?: string;
stripeRedirectStatus?: string;
apiHost?: string;
@ -70,11 +69,10 @@ export async function startChatQuery({
if (isNotDefined(typebot))
throw new Error("Typebot ID is required to get initial messages");
const typebotId = typeof typebot === "string" ? typebot : typebot.id;
if (isPreview) {
return startPreviewChat({
apiHost,
typebotId,
typebotId: typebot,
startFrom,
prefilledVariables,
sessionId,
@ -84,7 +82,7 @@ export async function startChatQuery({
try {
const iframeReferrerOrigin = getIframeReferrerOrigin();
const response = await ky.post(
`${getApiHost(apiHost)}/api/v1/typebots/${typebotId}/startChat`,
`${getApiHost(apiHost)}/api/v1/typebots/${typebot}/startChat`,
{
headers: {
"x-typebot-iframe-referrer-origin": iframeReferrerOrigin,

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.10.5",
"version": "0.10.6",
"description": "Convenient library to display typebots on your React app",
"license": "FSL-1.1-ALv2",
"type": "module",

View File

@ -1,5 +1,4 @@
import { open, Popup, toggle } from "@typebot.io/react";
import { leadGenerationTypebot } from "./assets/leadGenerationTypebot";
export const Default = () => {
return (
@ -11,13 +10,12 @@ export const Default = () => {
Toggle modal
</button>
<Popup
typebot={leadGenerationTypebot}
templateSlug="lead-gen"
apiHost="http://localhost:3001"
autoShowDelay={3000}
theme={{
width: "800px",
}}
isPreview
/>
</>
);

View File

@ -1,14 +1,9 @@
import { Standard } from "@typebot.io/react";
import { leadGenerationTypebot } from "./assets/leadGenerationTypebot";
export const Default = () => {
return (
<div style={{ height: "500px" }}>
<Standard
typebot={leadGenerationTypebot}
apiHost="http://localhost:3001"
isPreview
/>
<Standard templateSlug="lead-gen" apiHost="http://localhost:3001" />
</div>
);
};
@ -18,9 +13,8 @@ export const StartWhenIntoView = () => {
<>
<div style={{ height: "300vh" }} />
<Standard
typebot={leadGenerationTypebot}
templateSlug="lead-gen"
apiHost="http://localhost:3001"
isPreview
style={{ height: "300px" }}
/>
</>