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.

better PR diff

Roman Pominov8968764b6e64
diff --git a/apps/designer/app/routes/canvas/$projectId.$pageId.tsx b/apps/designer/app/routes/canvas/$projectId.$pageId.tsx
index 98b5b421b5..673acba501 100644
--- a/apps/designer/app/routes/canvas/$projectId.$pageId.tsx
+++ b/apps/designer/app/routes/canvas/$projectId.$pageId.tsx
@@ -1,46 +1,2 @@
-import { useLoaderData } from "@remix-run/react";
-import type { LoaderFunction, MetaFunction } from "@remix-run/node";
-import { Canvas } from "~/canvas";
-import { loadCanvasData, type CanvasData } from "~/shared/db";
-import { ErrorMessage } from "~/shared/error";
-import { sentryException } from "~/shared/sentry";
-import { Root } from "@webstudio-is/react-sdk";
-
-type Data = CanvasData | { errors: string };
-
-export const meta: MetaFunction = ({ data }: { data: Data }) => {
- if ("errors" in data) {
- return { title: "Error" };
- }
- const { page } = data;
- return { title: page.title, ...page.meta };
-};
-
-export const loader: LoaderFunction = async ({ params }): Promise<Data> => {
- try {
- if (params.projectId === undefined) {
- throw new Error("Missing projectId");
- }
-
- return loadCanvasData(params.projectId, params.pageId);
- } catch (error) {
- const message = error instanceof Error ? error.message : String(error);
- sentryException({ message });
- return { errors: message };
- }
-};
-
-const Outlet = () => {
- const data = useLoaderData<CanvasData>();
- return <Canvas data={data} />;
-};
-
-const CanvasRoute = () => {
- const data = useLoaderData<Data>();
- if ("errors" in data) {
- return <ErrorMessage message={data.errors} />;
- }
- return <Root Outlet={Outlet} />;
-};
-
-export default CanvasRoute;
+export * from "./$projectId";
+export { default } from "./$projectId";
diff --git a/apps/designer/app/routes/canvas/$projectId.tsx b/apps/designer/app/routes/canvas/$projectId.tsx
index a08197110f..98b5b421b5 100644
--- a/apps/designer/app/routes/canvas/$projectId.tsx
+++ b/apps/designer/app/routes/canvas/$projectId.tsx
@@ -1,2 +1,46 @@
-export * from "./$projectId.$pageId";
-export { default } from "./$projectId.$pageId";
+import { useLoaderData } from "@remix-run/react";
+import type { LoaderFunction, MetaFunction } from "@remix-run/node";
+import { Canvas } from "~/canvas";
+import { loadCanvasData, type CanvasData } from "~/shared/db";
+import { ErrorMessage } from "~/shared/error";
+import { sentryException } from "~/shared/sentry";
+import { Root } from "@webstudio-is/react-sdk";
+
+type Data = CanvasData | { errors: string };
+
+export const meta: MetaFunction = ({ data }: { data: Data }) => {
+ if ("errors" in data) {
+ return { title: "Error" };
+ }
+ const { page } = data;
+ return { title: page.title, ...page.meta };
+};
+
+export const loader: LoaderFunction = async ({ params }): Promise<Data> => {
+ try {
+ if (params.projectId === undefined) {
+ throw new Error("Missing projectId");
+ }
+
+ return loadCanvasData(params.projectId, params.pageId);
+ } catch (error) {
+ const message = error instanceof Error ? error.message : String(error);
+ sentryException({ message });
+ return { errors: message };
+ }
+};
+
+const Outlet = () => {
+ const data = useLoaderData<CanvasData>();
+ return <Canvas data={data} />;
+};
+
+const CanvasRoute = () => {
+ const data = useLoaderData<Data>();
+ if ("errors" in data) {
+ return <ErrorMessage message={data.errors} />;
+ }
+ return <Root Outlet={Outlet} />;
+};
+
+export default CanvasRoute;
diff --git a/apps/designer/app/routes/designer/$projectId.$pageId.tsx b/apps/designer/app/routes/designer/$projectId.$pageId.tsx
index 38fbf3c1f5..673acba501 100644
--- a/apps/designer/app/routes/designer/$projectId.$pageId.tsx
+++ b/apps/designer/app/routes/designer/$projectId.$pageId.tsx
@@ -1,66 +1,2 @@
-import { useLoaderData } from "@remix-run/react";
-import { LoaderFunction } from "@remix-run/node";
-import { Designer, links } from "~/designer";
-import { db } from "@webstudio-is/project/index.server";
-import { type Project, type Page, utils } from "@webstudio-is/project";
-import config from "~/config";
-import { ErrorMessage } from "~/shared/error";
-import { action, useAction } from "./_assets";
-import { sentryException } from "~/shared/sentry";
-
-export { action, links };
-
-export const loader: LoaderFunction = async ({
- params,
-}): Promise<Data | Error> => {
- try {
- if (params.projectId === undefined) {
- throw new Error("Project id undefined");
- }
-
- const project = await db.project.loadById(params.projectId);
-
- if (project === null) {
- throw new Error(`Project "${params.projectId}" not found`);
- }
-
- const devBuild = await db.build.loadByProjectId(project.id, "dev");
-
- const page =
- params.pageId === undefined
- ? devBuild.pages.homePage
- : utils.pages.findById(devBuild.pages, params.pageId);
-
- if (page === undefined) {
- throw new Error(`Page "${params.pageId}" not found`);
- }
-
- return { config, project, page };
- } catch (error) {
- const message = error instanceof Error ? error.message : String(error);
- sentryException({ message });
- return { errors: message };
- }
-};
-
-type Data = {
- config: typeof config;
- project: Project;
- page: Page;
-};
-
-type Error = {
- errors: string;
-};
-
-export const DesignerRoute = () => {
- const data = useLoaderData<Data | Error>();
- useAction();
- if ("errors" in data) {
- return <ErrorMessage message={data.errors} />;
- }
-
- return <Designer {...data} />;
-};
-
-export default DesignerRoute;
+export * from "./$projectId";
+export { default } from "./$projectId";
diff --git a/apps/designer/app/routes/designer/$projectId.tsx b/apps/designer/app/routes/designer/$projectId.tsx
index a08197110f..38fbf3c1f5 100644
--- a/apps/designer/app/routes/designer/$projectId.tsx
+++ b/apps/designer/app/routes/designer/$projectId.tsx
@@ -1,2 +1,66 @@
-export * from "./$projectId.$pageId";
-export { default } from "./$projectId.$pageId";
+import { useLoaderData } from "@remix-run/react";
+import { LoaderFunction } from "@remix-run/node";
+import { Designer, links } from "~/designer";
+import { db } from "@webstudio-is/project/index.server";
+import { type Project, type Page, utils } from "@webstudio-is/project";
+import config from "~/config";
+import { ErrorMessage } from "~/shared/error";
+import { action, useAction } from "./_assets";
+import { sentryException } from "~/shared/sentry";
+
+export { action, links };
+
+export const loader: LoaderFunction = async ({
+ params,
+}): Promise<Data | Error> => {
+ try {
+ if (params.projectId === undefined) {
+ throw new Error("Project id undefined");
+ }
+
+ const project = await db.project.loadById(params.projectId);
+
+ if (project === null) {
+ throw new Error(`Project "${params.projectId}" not found`);
+ }
+
+ const devBuild = await db.build.loadByProjectId(project.id, "dev");
+
+ const page =
+ params.pageId === undefined
+ ? devBuild.pages.homePage
+ : utils.pages.findById(devBuild.pages, params.pageId);
+
+ if (page === undefined) {
+ throw new Error(`Page "${params.pageId}" not found`);
+ }
+
+ return { config, project, page };
+ } catch (error) {
+ const message = error instanceof Error ? error.message : String(error);
+ sentryException({ message });
+ return { errors: message };
+ }
+};
+
+type Data = {
+ config: typeof config;
+ project: Project;
+ page: Page;
+};
+
+type Error = {
+ errors: string;
+};
+
+export const DesignerRoute = () => {
+ const data = useLoaderData<Data | Error>();
+ useAction();
+ if ("errors" in data) {
+ return <ErrorMessage message={data.errors} />;
+ }
+
+ return <Designer {...data} />;
+};
+
+export default DesignerRoute;
diff --git a/apps/designer/app/routes/preview/$projectId.$pageId.tsx b/apps/designer/app/routes/preview/$projectId.$pageId.tsx
index 158207222f..673acba501 100644
--- a/apps/designer/app/routes/preview/$projectId.$pageId.tsx
+++ b/apps/designer/app/routes/preview/$projectId.$pageId.tsx
@@ -1,44 +1,2 @@
-import { useLoaderData } from "@remix-run/react";
-import type { LoaderFunction, MetaFunction } from "@remix-run/node";
-import { loadCanvasData, type CanvasData } from "~/shared/db";
-import { InstanceRoot, Root } from "@webstudio-is/react-sdk";
-import { sentryException } from "~/shared/sentry";
-
-type Data = CanvasData | { errors: string };
-
-export const meta: MetaFunction = ({ data }: { data: Data }) => {
- if ("errors" in data) {
- return { title: "Error" };
- }
- const { page } = data;
- return { title: page.title, ...page.meta };
-};
-
-export const loader: LoaderFunction = async ({ params }): Promise<Data> => {
- try {
- if (params.projectId === undefined) {
- throw new Error("Missing projectId");
- }
-
- return loadCanvasData(params.projectId, params.pageId);
- } catch (error) {
- const message = error instanceof Error ? error.message : String(error);
- sentryException({ message });
- return { errors: message };
- }
-};
-
-const Outlet = () => {
- const data = useLoaderData<CanvasData>();
- return <InstanceRoot data={data} />;
-};
-
-const PreviewRoute = () => {
- const data = useLoaderData<Data>();
- if ("errors" in data) {
- return <p>{data.errors}</p>;
- }
- return <Root Outlet={Outlet} />;
-};
-
-export default PreviewRoute;
+export * from "./$projectId";
+export { default } from "./$projectId";
diff --git a/apps/designer/app/routes/preview/$projectId.tsx b/apps/designer/app/routes/preview/$projectId.tsx
index a08197110f..158207222f 100644
--- a/apps/designer/app/routes/preview/$projectId.tsx
+++ b/apps/designer/app/routes/preview/$projectId.tsx
@@ -1,2 +1,44 @@
-export * from "./$projectId.$pageId";
-export { default } from "./$projectId.$pageId";
+import { useLoaderData } from "@remix-run/react";
+import type { LoaderFunction, MetaFunction } from "@remix-run/node";
+import { loadCanvasData, type CanvasData } from "~/shared/db";
+import { InstanceRoot, Root } from "@webstudio-is/react-sdk";
+import { sentryException } from "~/shared/sentry";
+
+type Data = CanvasData | { errors: string };
+
+export const meta: MetaFunction = ({ data }: { data: Data }) => {
+ if ("errors" in data) {
+ return { title: "Error" };
+ }
+ const { page } = data;
+ return { title: page.title, ...page.meta };
+};
+
+export const loader: LoaderFunction = async ({ params }): Promise<Data> => {
+ try {
+ if (params.projectId === undefined) {
+ throw new Error("Missing projectId");
+ }
+
+ return loadCanvasData(params.projectId, params.pageId);
+ } catch (error) {
+ const message = error instanceof Error ? error.message : String(error);
+ sentryException({ message });
+ return { errors: message };
+ }
+};
+
+const Outlet = () => {
+ const data = useLoaderData<CanvasData>();
+ return <InstanceRoot data={data} />;
+};
+
+const PreviewRoute = () => {
+ const data = useLoaderData<Data>();
+ if ("errors" in data) {
+ return <p>{data.errors}</p>;
+ }
+ return <Root Outlet={Outlet} />;
+};
+
+export default PreviewRoute;
diff --git a/apps/designer/app/routes/rest/props.$projectId.$pageId.ts b/apps/designer/app/routes/rest/props.$projectId.$pageId.ts
index 49278be79f..1116abf360 100644
--- a/apps/designer/app/routes/rest/props.$projectId.$pageId.ts
+++ b/apps/designer/app/routes/rest/props.$projectId.$pageId.ts
@@ -1,44 +1 @@
-import { type LoaderFunction } from "@remix-run/node";
-import { type InstanceProps } from "@webstudio-is/react-sdk";
-import { db } from "@webstudio-is/project/index.server";
-import { utils } from "@webstudio-is/project";
-
-type ErrorData = {
- errors: string;
-};
-
-export const loader: LoaderFunction = async ({
- params,
-}): Promise<Array<InstanceProps> | ErrorData> => {
- try {
- if (params.projectId === undefined) {
- throw new Error(`Project ID required`);
- }
-
- const prodBuild = await db.build.loadByProjectId(params.projectId, "prod");
-
- if (prodBuild === undefined) {
- throw new Error(
- `Project ${params.projectId} needs to be published first`
- );
- }
-
- const page =
- params.pageId === undefined
- ? prodBuild.pages.homePage
- : utils.pages.findById(prodBuild.pages, params.pageId);
-
- if (page === undefined) {
- throw new Error(`Page ${params.pageId} not found`);
- }
-
- return await db.props.loadByTreeId(page.treeId);
- } catch (error) {
- if (error instanceof Error) {
- return {
- errors: error.message,
- };
- }
- }
- return { errors: "Unexpected error" };
-};
+export * from "./props.$projectId";
diff --git a/apps/designer/app/routes/rest/props.$projectId.ts b/apps/designer/app/routes/rest/props.$projectId.ts
index f4f63c7ec2..49278be79f 100644
--- a/apps/designer/app/routes/rest/props.$projectId.ts
+++ b/apps/designer/app/routes/rest/props.$projectId.ts
@@ -1 +1,44 @@
-export * from "./props.$projectId.$pageId";
+import { type LoaderFunction } from "@remix-run/node";
+import { type InstanceProps } from "@webstudio-is/react-sdk";
+import { db } from "@webstudio-is/project/index.server";
+import { utils } from "@webstudio-is/project";
+
+type ErrorData = {
+ errors: string;
+};
+
+export const loader: LoaderFunction = async ({
+ params,
+}): Promise<Array<InstanceProps> | ErrorData> => {
+ try {
+ if (params.projectId === undefined) {
+ throw new Error(`Project ID required`);
+ }
+
+ const prodBuild = await db.build.loadByProjectId(params.projectId, "prod");
+
+ if (prodBuild === undefined) {
+ throw new Error(
+ `Project ${params.projectId} needs to be published first`
+ );
+ }
+
+ const page =
+ params.pageId === undefined
+ ? prodBuild.pages.homePage
+ : utils.pages.findById(prodBuild.pages, params.pageId);
+
+ if (page === undefined) {
+ throw new Error(`Page ${params.pageId} not found`);
+ }
+
+ return await db.props.loadByTreeId(page.treeId);
+ } catch (error) {
+ if (error instanceof Error) {
+ return {
+ errors: error.message,
+ };
+ }
+ }
+ return { errors: "Unexpected error" };
+};
diff --git a/apps/designer/app/routes/rest/tree.$projectId.$pageId.ts b/apps/designer/app/routes/rest/tree.$projectId.$pageId.ts
index af3158b75f..0983fbedbd 100644
--- a/apps/designer/app/routes/rest/tree.$projectId.$pageId.ts
+++ b/apps/designer/app/routes/rest/tree.$projectId.$pageId.ts
@@ -1,44 +1 @@
-import { type LoaderFunction } from "@remix-run/node";
-import type { Tree } from "@webstudio-is/react-sdk";
-import { db } from "@webstudio-is/project/index.server";
-import { utils } from "@webstudio-is/project";
-
-export type ErrorData = {
- errors: string;
-};
-
-export const loader: LoaderFunction = async ({
- params,
-}): Promise<Tree | null | ErrorData> => {
- try {
- if (params.projectId === undefined) {
- throw new Error(`Project ID required`);
- }
-
- const prodBuild = await db.build.loadByProjectId(params.projectId, "prod");
-
- if (prodBuild === undefined) {
- throw new Error(
- `Project ${params.projectId} needs to be published first`
- );
- }
-
- const page =
- params.pageId === undefined
- ? prodBuild.pages.homePage
- : utils.pages.findById(prodBuild.pages, params.pageId);
-
- if (page === undefined) {
- throw new Error(`Page ${params.pageId} not found`);
- }
-
- return await db.tree.loadById(page.treeId);
- } catch (error) {
- if (error instanceof Error) {
- return {
- errors: error.message,
- };
- }
- }
- return { errors: "Unexpected error" };
-};
+export * from "./tree.$projectId";
diff --git a/apps/designer/app/routes/rest/tree.$projectId.ts b/apps/designer/app/routes/rest/tree.$projectId.ts
index c3315b80b5..af3158b75f 100644
--- a/apps/designer/app/routes/rest/tree.$projectId.ts
+++ b/apps/designer/app/routes/rest/tree.$projectId.ts
@@ -1 +1,44 @@
-export * from "./tree.$projectId.$pageId";
+import { type LoaderFunction } from "@remix-run/node";
+import type { Tree } from "@webstudio-is/react-sdk";
+import { db } from "@webstudio-is/project/index.server";
+import { utils } from "@webstudio-is/project";
+
+export type ErrorData = {
+ errors: string;
+};
+
+export const loader: LoaderFunction = async ({
+ params,
+}): Promise<Tree | null | ErrorData> => {
+ try {
+ if (params.projectId === undefined) {
+ throw new Error(`Project ID required`);
+ }
+
+ const prodBuild = await db.build.loadByProjectId(params.projectId, "prod");
+
+ if (prodBuild === undefined) {
+ throw new Error(
+ `Project ${params.projectId} needs to be published first`
+ );
+ }
+
+ const page =
+ params.pageId === undefined
+ ? prodBuild.pages.homePage
+ : utils.pages.findById(prodBuild.pages, params.pageId);
+
+ if (page === undefined) {
+ throw new Error(`Page ${params.pageId} not found`);
+ }
+
+ return await db.tree.loadById(page.treeId);
+ } catch (error) {
+ if (error instanceof Error) {
+ return {
+ errors: error.message,
+ };
+ }
+ }
+ return { errors: "Unexpected error" };
+};