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 issues

Andras Bacsaicefd76d9b729
diff --git a/apps/designer/app/routes/rest/project.$projectId.tsx b/apps/designer/app/routes/rest/project.$projectId.tsx
index 683c474dd1..4dbad02f06 100644
--- a/apps/designer/app/routes/rest/project.$projectId.tsx
+++ b/apps/designer/app/routes/rest/project.$projectId.tsx
@@ -1,4 +1,4 @@
-import { ActionFunction, json } from "@remix-run/node";
+import { LoaderFunction, json } from "@remix-run/node";
import env from "~/env.server";
import { db } from "@webstudio-is/project/server";
import { sentryException } from "~/shared/sentry";
@@ -7,14 +7,14 @@ import type { Props, Tree } from "@webstudio-is/react-sdk";
import type { Page } from "@webstudio-is/project";
type PagesDetails = {
- [key: string]: {
+ [path: string]: {
page: Page;
tree: Tree | null;
props: Props[];
css: string;
};
};
-export const loader: ActionFunction = async ({ request, params }) => {
+export const loader: LoaderFunction = async ({ request, params }) => {
try {
const projectId = params.projectId ?? undefined;
const url = new URL(request.url);
@@ -27,7 +27,7 @@ export const loader: ActionFunction = async ({ request, params }) => {
const prodBuild = await db.build.loadByProjectId(projectId, "prod");
if (prodBuild === undefined) {
throw json(
- "Project not found or not published yet. Please contact us to get help.",
+ `Project ${projectId} not found or not published yet. Please contact us to get help.`,
{ status: 500 }
);
}
@@ -37,9 +37,12 @@ export const loader: ActionFunction = async ({ request, params }) => {
const breakpoints = await db.breakpoints.load(prodBuild.id);
const tree = await db.tree.loadById(homePage.treeId);
if (tree === null) {
- throw json("Tree structure not found. Please contact us to get help.", {
- status: 500,
- });
+ throw json(
+ `Tree ${homePage.treeId} structure not found. Please contact us to get help.`,
+ {
+ status: 500,
+ }
+ );
}
pagesDetails["/"] = {
page: homePage,
@@ -48,16 +51,25 @@ export const loader: ActionFunction = async ({ request, params }) => {
css: await generateCssText({
projectId,
mode: "published",
- pathname: url.pathname,
+ pathname: "/",
pageId: homePage.id,
}),
};
if (pages.length > 0) {
for (const page of pages) {
+ const tree = await db.tree.loadById(page.treeId);
+ if (tree === null) {
+ throw json(
+ `Tree ${page.treeId} structure not found. Please contact us to get help.`,
+ {
+ status: 500,
+ }
+ );
+ }
pagesDetails[page.path] = {
page,
- tree: await db.tree.loadById(page.treeId),
+ tree,
props: await db.props.loadByTreeId(page.treeId),
css: await generateCssText({
projectId,
diff --git a/packages/http-client/src/index.d.ts b/packages/http-client/src/index.d.ts
deleted file mode 100644
index e490f98882..0000000000
--- a/packages/http-client/src/index.d.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type {
- BaseInstance,
- Breakpoint,
- UserProp,
-} from "@webstudio-is/react-sdk";
-
-export type Page = {
- id: string;
- root: [string, string];
-};
-export type Project =
- | {
- pages: {
- [string]: {
- page: Page;
- tree: BaseInstance;
- props: Array<UserProp> | [];
- breakpoints: Array<Breakpoint> | null;
- css: string;
- };
- };
- }
- | Error;
diff --git a/packages/http-client/src/index.test.ts b/packages/http-client/src/index.test.ts
index bdf0120436..3daad19216 100644
--- a/packages/http-client/src/index.test.ts
+++ b/packages/http-client/src/index.test.ts
@@ -1,5 +1,4 @@
import { loadProject } from "./index";
-
const existingProjectId = "675e8af3-48fa-4b18-9ebf-fd2b128865e2";
const notPublishedProjectId = "7ec397c6-b3d0-4967-9073-9d83623fcf8e";
const onlyHomeProjectId = "36d6c16f-04a0-45d4-ab1d-aa0ab61eb5b6";
@@ -16,7 +15,10 @@ describe("getProjectDetails", () => {
if (response instanceof Error) {
throw response;
}
- expect(Object.keys(response.pages).length > 1).toBeTruthy();
+ if (typeof response === "object") {
+ return expect(Object.keys(response.pages).length > 1).toBeTruthy();
+ }
+ throw new Error("Unexpected response");
});
test("does not include pages", async () => {
const response = await loadProject({
@@ -26,7 +28,10 @@ describe("getProjectDetails", () => {
if (response instanceof Error) {
throw response;
}
- expect(Object.keys(response.pages).length === 1).toBeTruthy();
+ if (typeof response === "object") {
+ return expect(Object.keys(response.pages).length === 1).toBeTruthy();
+ }
+ throw new Error("Unexpected response");
});
test("loads existing project", async () => {
const response = await loadProject({
@@ -41,7 +46,7 @@ describe("getProjectDetails", () => {
projectId: notPublishedProjectId,
});
expect(response.toString()).toBe(
- "Error: Project not found or not published yet. Please contact us to get help."
+ `Project ${notPublishedProjectId} not found or not published yet. Please contact us to get help.`
);
});
});
diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts
index 2c497122f3..ed0b1795cd 100644
--- a/packages/http-client/src/index.ts
+++ b/packages/http-client/src/index.ts
@@ -1,5 +1,22 @@
import fetch from "isomorphic-fetch";
-import type { Project } from "./index.d";
+import type { BaseInstance, UserProp } from "@webstudio-is/react-sdk";
+import type { Breakpoint } from "@webstudio-is/css-data";
+
+export type Page = {
+ id: string;
+ root: [string, string];
+};
+export type Project = {
+ pages: {
+ [path: string]: {
+ page: Page;
+ tree: BaseInstance;
+ props: Array<UserProp> | [];
+ breakpoints: Array<Breakpoint> | null;
+ css: string;
+ };
+ };
+};
export const loadProject = async ({
apiUrl,
@@ -7,7 +24,7 @@ export const loadProject = async ({
}: {
apiUrl: string;
projectId: string;
-}): Promise<Project> => {
+}): Promise<Project | string> => {
try {
if (apiUrl === undefined) {
throw new Error("Webstudio API URL is required.");
@@ -20,10 +37,10 @@ export const loadProject = async ({
throw new Error(project);
}
return project;
- } catch (error: unknown) {
+ } catch (error) {
if (error instanceof Error) {
- return error;
+ return error.message;
}
- return new Error("Unknown error");
+ throw error;
}
};