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 <ErrorMessage> and use it for errors on canvas

Roman Pominov0c010767965e
diff --git a/apps/designer/app/designer/features/breakpoints/use-update-canvas-width.ts b/apps/designer/app/designer/features/breakpoints/use-update-canvas-width.ts
index 24d9f98b0f..9f71a23802 100644
--- a/apps/designer/app/designer/features/breakpoints/use-update-canvas-width.ts
+++ b/apps/designer/app/designer/features/breakpoints/use-update-canvas-width.ts
@@ -1,4 +1,3 @@
-import { useSubscribe } from "~/shared/pubsub";
import { useCallback, useEffect } from "react";
import {
useSelectedBreakpoint,
@@ -32,7 +31,16 @@ export const useUpdateCanvasWidth = () => {
setCanvasWidth(Math.max(selectedBreakpoint.minWidth, minWidth));
}, [selectedBreakpoint, setCanvasWidth]);
- useSubscribe("canvasWidth", setCanvasWidth);
+ // Handle the case when canvas loads with a error
+ // And doesn't send any messages that it's supposed to send
+ useEffect(() => {
+ if (canvasWidth === 0) {
+ const timeout = setTimeout(() => {
+ setCanvasWidth(600);
+ }, 1000);
+ return () => clearTimeout(timeout);
+ }
+ }, [canvasWidth, setCanvasWidth]);
// Set the initial canvas width based on the selected breakpoint upper bound, which starts where the next breakpoint begins.
return useCallback(
diff --git a/apps/designer/app/routes/$.tsx b/apps/designer/app/routes/$.tsx
index fdbcf90d8c..522d4ee880 100644
--- a/apps/designer/app/routes/$.tsx
+++ b/apps/designer/app/routes/$.tsx
@@ -7,6 +7,7 @@ import { db } from "@webstudio-is/project/index.server";
import env, { Env } from "~/env.server";
import { sentryException } from "~/shared/sentry";
import { Canvas } from "~/canvas";
+import { ErrorMessage } from "~/shared/error";
type Mode = "edit" | "preview" | "published";
@@ -112,7 +113,7 @@ const Content = () => {
const data = useLoaderData<Data>();
if ("errors" in data) {
- return <p>{data.errors}</p>;
+ return <ErrorMessage message={data.errors} />;
}
const Outlet =
diff --git a/apps/designer/app/shared/error/error-message.tsx b/apps/designer/app/shared/error/error-message.tsx
index daebed6b5f..7c6b6ddd07 100644
--- a/apps/designer/app/shared/error/error-message.tsx
+++ b/apps/designer/app/shared/error/error-message.tsx
@@ -1,16 +1,4 @@
-import { useEffect } from "react";
-import { publish } from "~/shared/pubsub";
-
-declare module "~/shared/pubsub" {
- export interface PubsubMap {
- canvasWidth: number;
- }
-}
-
export const ErrorMessage = ({ message }: { message: string }) => {
- useEffect(() => {
- publish({ type: "canvasWidth", payload: 600 });
- }, []);
return (
<div>
<h1>Error</h1>