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.

chore: Fast project opening (on subsequent openings) (#4100)

Ivan Starkov8b05d2c7f1cb
diff --git a/apps/builder/app/auth/brand-button.tsx b/apps/builder/app/auth/brand-button.tsx
index 1088724b68..e801c00710 100644
--- a/apps/builder/app/auth/brand-button.tsx
+++ b/apps/builder/app/auth/brand-button.tsx
@@ -1,8 +1,7 @@
import { css, textVariants, theme } from "@webstudio-is/design-system";
import type { ComponentProps } from "react";
-const buttonStyle = css({
- all: "unset",
+export const buttonStyle = css({
boxSizing: "border-box",
minWidth: 0,
display: "inline-flex",
@@ -15,7 +14,7 @@ const buttonStyle = css({
border: "2px solid transparent",
whiteSpace: "nowrap",
backgroundImage: `
- linear-gradient(${theme.colors.backgroundPanel}, ${theme.colors.backgroundPanel}),
+ linear-gradient(${theme.colors.backgroundPanel}, ${theme.colors.backgroundPanel}),
${theme.colors.brandBorderFullGradient}
`,
backgroundOrigin: "border-box",
@@ -41,7 +40,7 @@ const buttonStyle = css({
});
type BrandButtonProps = ComponentProps<"button"> & {
- icon: JSX.Element;
+ icon?: JSX.Element;
};
export const BrandButton = ({ icon, children, ...props }: BrandButtonProps) => {
diff --git a/apps/builder/app/canvas/canvas.tsx b/apps/builder/app/canvas/canvas.tsx
index 5896097543..85e2c72577 100644
--- a/apps/builder/app/canvas/canvas.tsx
+++ b/apps/builder/app/canvas/canvas.tsx
@@ -75,7 +75,12 @@ const FallbackComponent = ({ error, resetErrorBoundary }: FallbackProps) => {
return (
// body is required to prevent breaking collapsed instances logic
<body>
- <ErrorMessage message={error.message} />
+ <ErrorMessage
+ error={{
+ message: error instanceof Error ? error.message : "Unknown error",
+ status: 500,
+ }}
+ />
</body>
);
};
diff --git a/apps/builder/app/dashboard/projects/project-card.tsx b/apps/builder/app/dashboard/projects/project-card.tsx
index 0a2e725d37..ea4a4b4d7c 100644
--- a/apps/builder/app/dashboard/projects/project-card.tsx
+++ b/apps/builder/app/dashboard/projects/project-card.tsx
@@ -13,6 +13,7 @@ import {
Tooltip,
rawTheme,
Link,
+ Box,
} from "@webstudio-is/design-system";
import { InfoCircleIcon, EllipsesIcon } from "@webstudio-is/icons";
import { type KeyboardEvent, useEffect, useRef, useState } from "react";
@@ -206,8 +207,28 @@ export const ProjectCard = ({
return (
<Card hidden={isHidden} tabIndex={0} onKeyDown={handleKeyDown}>
<CardContent
- css={{ background: theme.colors.brandBackgroundProjectCardBack }}
+ css={{
+ background: theme.colors.brandBackgroundProjectCardBack,
+ position: "relative",
+ [`&:hover`]: {
+ "--ws-project-card-prefetch-image-background": `url(${linkPath}cgi/empty.gif)`,
+ },
+ }}
>
+ {/* This div with backgorundImage on card hover is used to prefetch DNS of the project domain on hover. */}
+ <Box
+ css={{
+ backgroundImage: `var(--ws-project-card-prefetch-image-background, none)`,
+ visibility: "hidden",
+ position: "absolute",
+ width: 1,
+ height: 1,
+ left: 0,
+ top: 0,
+ opacity: 0,
+ }}
+ />
+
{previewImageAsset ? (
<ThumbnailLinkWithImage
to={linkPath}
diff --git a/apps/builder/app/routes/_canvas.canvas.tsx b/apps/builder/app/routes/_canvas.canvas.tsx
index 675b6d180f..3fb0846bd7 100644
--- a/apps/builder/app/routes/_canvas.canvas.tsx
+++ b/apps/builder/app/routes/_canvas.canvas.tsx
@@ -7,12 +7,12 @@ import { createImageLoader } from "@webstudio-is/image";
import env from "~/env/env.server";
import { isCanvas } from "~/shared/router-utils";
import { ClientOnly } from "~/shared/client-only";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
export const loader = async ({ request }: LoaderFunctionArgs) => {
if (isCanvas(request) === false) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/_canvas.tsx b/apps/builder/app/routes/_canvas.tsx
index d6a478f938..dd2f052ff0 100644
--- a/apps/builder/app/routes/_canvas.tsx
+++ b/apps/builder/app/routes/_canvas.tsx
@@ -1,6 +1,5 @@
import { Links, Meta, Outlet } from "@remix-run/react";
-import { ErrorMessage } from "~/shared/error";
-import { isRouteErrorResponse, useRouteError } from "@remix-run/react";
+import { ErrorBoundary as ErrorBoundaryComponent } from "~/shared/error/error-boundary";
const Document = (props: { children: React.ReactNode }) => {
return (
@@ -17,20 +16,9 @@ const Document = (props: { children: React.ReactNode }) => {
};
export const ErrorBoundary = () => {
- const error = useRouteError();
-
- console.error({ error });
- const message = isRouteErrorResponse(error)
- ? (error.data.message ?? error.data)
- : error instanceof Error
- ? error.message
- : String(error);
-
return (
<Document>
- <body>
- <ErrorMessage message={message} />
- </body>
+ <ErrorBoundaryComponent />
</Document>
);
};
diff --git a/apps/builder/app/routes/$.tsx b/apps/builder/app/routes/_ui.$.tsx
similarity index 75%
rename from apps/builder/app/routes/$.tsx
rename to apps/builder/app/routes/_ui.$.tsx
index 49c03a26ef..ac92fd860b 100644
--- a/apps/builder/app/routes/$.tsx
+++ b/apps/builder/app/routes/_ui.$.tsx
@@ -2,10 +2,8 @@ import {
type HeadersFunction,
type LoaderFunctionArgs,
} from "@remix-run/server-runtime";
-
-import { isRouteErrorResponse, useRouteError } from "@remix-run/react";
-import { ErrorMessage } from "~/shared/error/error-message";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
export const loader = async ({ request }: LoaderFunctionArgs) => {
preventCrossOriginCookie(request);
@@ -22,7 +20,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
// In case of 404 on static assets, this route will be executed
if (publicPaths.some((publicPath) => url.pathname.startsWith(publicPath))) {
- return new Response("Not found", {
+ throw new Response("Not found", {
status: 404,
headers: {
"Cache-Control": "public, max-age=0, must-revalidate",
@@ -34,19 +32,29 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
if (contentType?.includes("application/json")) {
// Return an error to not trigger the ErrorBoundary rendering (api request)
- return new Response(null, {
+ throw new Response("Not found", {
status: 404,
- statusText: "Not Found",
});
}
// Throw an error to trigger the ErrorBoundary rendering
- throw new Response(null, {
+ throw new Response("Not found", {
status: 404,
- statusText: "Not Found",
});
};
+export default function NotFound() {
+ // Placeholder component to prevent Remix warning:
+ // "Matched leaf route at location '/{SOME_LOCATION}' does not have an element or Component."
+ // Without this, an <Outlet /> with a null value would render an empty page.
+ return (
+ <div>
+ <h1>Not Found</h1>
+ <p>The page you requested could not be found.</p>
+ </div>
+ );
+}
+
export const headers: HeadersFunction = ({ errorHeaders, loaderHeaders }) => {
// !!!! VERY IMPORTANT !!!
// Vercel sets Cache-Control: public, max-age=31536000, immutable for all /assets/* paths,
@@ -62,15 +70,3 @@ export const headers: HeadersFunction = ({ errorHeaders, loaderHeaders }) => {
}
return loaderHeaders;
};
-
-export const ErrorBoundary = () => {
- const error = useRouteError();
- console.error({ error });
- const message = isRouteErrorResponse(error)
- ? `${error.status} ${error.statusText} ${error.data.message ?? error.data}`
- : error instanceof Error
- ? error.message
- : String(error);
-
- return <ErrorMessage message={`${message}`} />;
-};
diff --git a/apps/builder/app/routes/_ui.(builder).tsx b/apps/builder/app/routes/_ui.(builder).tsx
index 0b83e6a782..d029d409c4 100644
--- a/apps/builder/app/routes/_ui.(builder).tsx
+++ b/apps/builder/app/routes/_ui.(builder).tsx
@@ -36,6 +36,8 @@ import {
allowedDestinations,
isFetchDestination,
} from "~/services/destinations.server";
+import { loader as authWsLoader } from "./auth.ws";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
export const links = () => {
return [
@@ -59,7 +61,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
return metas;
};
-export const loader = async ({ request }: LoaderFunctionArgs) => {
+export const loader = async (loaderArgs: LoaderFunctionArgs) => {
+ const { request } = loaderArgs;
preventCrossOriginCookie(request);
allowedDestinations(request, ["document", "empty"]);
@@ -68,9 +71,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
}
if (false === isBuilder(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
@@ -88,8 +90,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
}
if (context.authorization.type === "anonymous") {
- // @todo just import loader from auth and call it
- throw redirect("/auth/ws");
+ throw await authWsLoader(loaderArgs); // redirect("/auth/ws");
}
if (
@@ -98,17 +99,16 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
) {
// If logout fails, or the session cookie in the dashboard is deleted or expired,
// enforce reauthorization on builder reload or navigation (sec-fetch-mode === 'navigate') after a timeout.
-
const RELOAD_ON_NAVIGATE_TIMEOUT =
env.DEPLOYMENT_ENVIRONMENT === "production"
- ? 1000 * 60 * 3 // 3 minutes
- : 1000 * 30; // 30 seconds
+ ? 1000 * 60 * 60 * 24 * 7 // 1 week
+ : 1000 * 60 * 60 * 1; // 1 hour
if (
Date.now() - context.authorization.sessionCreatedAt >
RELOAD_ON_NAVIGATE_TIMEOUT
) {
- throw redirect("/auth/ws");
+ throw await authWsLoader(loaderArgs); // start immediately instead of redirect("/auth/ws");
}
}
@@ -118,14 +118,18 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const { projectId } = parseBuilderUrl(request.url);
if (projectId === undefined) {
- throw new Error("Project ID is not defined");
+ throw new Response("Project ID is not defined", {
+ status: 404,
+ });
}
const start = Date.now();
const project = await db.project.loadById(projectId, context);
if (project === null) {
- throw new Error(`Project "${projectId}" not found`);
+ throw new Response(`Project "${projectId}" not found`, {
+ status: 404,
+ });
}
const authPermit =
@@ -167,7 +171,9 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const { userPlanFeatures } = context;
if (userPlanFeatures === undefined) {
- throw new Error("User plan features are not defined");
+ throw new Response("User plan features are not defined", {
+ status: 404,
+ });
}
if (project.userId === null) {
diff --git a/apps/builder/app/routes/_ui.dashboard.tsx b/apps/builder/app/routes/_ui.dashboard.tsx
index f5742081e6..07b45474f5 100644
--- a/apps/builder/app/routes/_ui.dashboard.tsx
+++ b/apps/builder/app/routes/_ui.dashboard.tsx
@@ -18,6 +18,7 @@ import { parseBuilderUrl } from "@webstudio-is/http-client";
import { allowedDestinations } from "~/services/destinations.server";
import { db as authDb } from "@webstudio-is/authorization-token/index.server";
import { db } from "@webstudio-is/project/index.server";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
const dashboardProjectCaller = createCallerFactory(dashboardProjectRouter);
@@ -31,9 +32,8 @@ export const meta: MetaFunction<typeof loader> = () => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
@@ -105,7 +105,9 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const { userPlanFeatures } = context;
if (userPlanFeatures === undefined) {
- throw new Error("User plan features are not defined");
+ throw new Response("User plan features are not defined", {
+ status: 404,
+ });
}
const { sourceOrigin } = parseBuilderUrl(request.url);
diff --git a/apps/builder/app/routes/_ui.error.tsx b/apps/builder/app/routes/_ui.error.tsx
index cb6ce5ebd5..8a48b8f916 100644
--- a/apps/builder/app/routes/_ui.error.tsx
+++ b/apps/builder/app/routes/_ui.error.tsx
@@ -1,16 +1,13 @@
-import { type LoaderFunctionArgs, json } from "@remix-run/server-runtime";
-import { useLoaderData, type MetaFunction } from "@remix-run/react";
-import { getAuthorizationServerOrigin } from "~/shared/router-utils/origins";
+import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
+import { type MetaFunction } from "@remix-run/react";
import { builderSessionStorage } from "~/services/builder-session.server";
import { sessionStorage } from "~/services/session.server";
import { authenticator } from "~/services/auth.server";
import { builderAuthenticator } from "~/services/builder-auth.server";
import { z } from "zod";
-import { fromError } from "zod-validation-error";
-import { lazy } from "react";
-import { ClientOnly } from "~/shared/client-only";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
import { isBuilder } from "~/shared/router-utils";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
const SessionError = z.object({
message: z.string(),
@@ -25,9 +22,57 @@ export const meta: MetaFunction<typeof loader> = () => {
return metas;
};
+const developmentErrors = [
+ {
+ message: "Unknown error",
+ description: undefined,
+ },
+
+ {
+ message:
+ "Unknown error Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ description: undefined,
+ },
+
+ {
+ message: "Unknown error",
+ description:
+ "Unknown error Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ },
+ {
+ message:
+ "Unknown error Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ description:
+ "Unknown error Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ },
+ {
+ message:
+ "UnknownerrorLoremIpsumissimplydummytextoftheprintingandtypesettingindustry.LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbook.Ithassurvivednotonlyfivecenturies,butalsotheleapintoelectronictypesetting,remainingessentiallyunchanged.Itwaspopularisedinthe1960swiththereleaseofLetrasetsheetscontainingLoremIpsumpassages,andmorerecentlywithdesktoppublishingsoftwarelikeAldusPageMakerincludingversionsofLoremIpsum.",
+ description:
+ "UnknownerrorLoremIpsumissimplydummytextoftheprintingandtypesettingindustry.LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbook.Ithassurvivednotonlyfivecenturies,butalsotheleapintoelectronictypesetting,remainingessentiallyunchanged.Itwaspopularisedinthe1960swiththereleaseofLetrasetsheetscontainingLoremIpsumpassages,andmorerecentlywithdesktoppublishingsoftwarelikeAldusPageMakerincludingversionsofLoremIpsum.",
+ },
+];
+
export const loader = async ({ request }: LoaderFunctionArgs) => {
preventCrossOriginCookie(request);
+ // We leave it here because production errors in remix has a different behavior
+ // https://wstd.dev:5173/error?development-error=0
+ // https://wstd.dev:5173/error?development-error=1
+ // ...
+ const url = new URL(request.url);
+ if (url.searchParams.has("development-error")) {
+ const index = Number(url.searchParams.get("development-error"));
+ if (index >= 0 && index < developmentErrors.length) {
+ throw new Response(JSON.stringify(developmentErrors[index]), {
+ status: 400,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ }
+ }
+
const storage = isBuilder(request) ? builderSessionStorage : sessionStorage;
const sessionErrorKey = isBuilder(request)
? builderAuthenticator.sessionErrorKey
@@ -46,37 +91,24 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
description: "",
};
- if (false === parsedError.success) {
- console.error(fromError(parsedError.error));
- }
-
- return json(
- { error, origin: getAuthorizationServerOrigin(request.url) },
- // remove flash message from session
- {
- headers: {
- "Set-Cookie": await storage.commitSession(session),
- },
- }
- );
+ throw new Response(JSON.stringify(error), {
+ status: 400,
+ headers: {
+ "Content-Type": "application/json",
+ // Clear the error from the session
+ "Set-Cookie": await storage.commitSession(session),
+ },
+ });
};
-const ErrorPage = lazy(async () => {
- const { ErrorPage } = await import("~/shared/error/error-page.client");
- return { default: ErrorPage };
-});
-
-/**
- * @todo Implement the error page
- */
-const Error = () => {
- const data = useLoaderData<typeof loader>();
-
+export default function Error() {
+ // Placeholder component to prevent Remix warning:
+ // "Matched leaf route at location '/{SOME_LOCATION}' does not have an element or Component."
+ // Without this, an <Outlet /> with a null value would render an empty page.
return (
- <ClientOnly>
- <ErrorPage error={data.error} onCloseNavigateTo={data.origin} />
- </ClientOnly>
+ <div>
+ <h1>Error</h1>
+ <p>Unknown error.</p>
+ </div>
);
-};
-
-export default Error;
+}
diff --git a/apps/builder/app/routes/_ui.login._index.tsx b/apps/builder/app/routes/_ui.login._index.tsx
index de95b23b59..246df700f7 100644
--- a/apps/builder/app/routes/_ui.login._index.tsx
+++ b/apps/builder/app/routes/_ui.login._index.tsx
@@ -20,6 +20,7 @@ import { lazy } from "react";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
import { redirect } from "~/services/no-store-redirect";
import { allowedDestinations } from "~/services/destinations.server";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
export const links: LinksFunction = () => {
return [
@@ -52,9 +53,8 @@ export const loader = async ({
request,
}: LoaderFunctionArgs): Promise<TypedResponse<LoginProps>> => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/_ui.logout.tsx b/apps/builder/app/routes/_ui.logout.tsx
index 686cd7ae24..74fd57e145 100644
--- a/apps/builder/app/routes/_ui.logout.tsx
+++ b/apps/builder/app/routes/_ui.logout.tsx
@@ -1,16 +1,16 @@
import { json, type LoaderFunctionArgs } from "@remix-run/server-runtime";
import { createDebug } from "~/shared/debug";
-import { authenticator } from "~/services/auth.server";
import { builderUrl, isDashboard, loginPath } from "~/shared/router-utils";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
import { createCallerFactory } from "@webstudio-is/trpc-interface/index.server";
import { logoutRouter } from "~/services/logout-router.server";
import { createContext } from "~/shared/context.server";
-import { redirect, type ActionFunctionArgs } from "react-router-dom";
+import { redirect } from "react-router-dom";
import { ClientOnly } from "~/shared/client-only";
import { useLoaderData, type MetaFunction } from "@remix-run/react";
-import { lazy, useRef } from "react";
+import { lazy } from "react";
import { allowedDestinations } from "~/services/destinations.server";
+export { ErrorBoundary } from "~/shared/error/error-boundary";
const logoutCaller = createCallerFactory(logoutRouter);
@@ -26,7 +26,9 @@ export const meta: MetaFunction<typeof loader> = () => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Error("Only Dashboard can logout at this endpoint");
+ throw new Response("Not found", {
+ status: 404,
+ });
}
preventCrossOriginCookie(request);
@@ -70,19 +72,6 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
}
};
-export const action = async ({ request }: ActionFunctionArgs) => {
- if (false === isDashboard(request)) {
- throw new Error("Only Dashboard can logout at this endpoint");
- }
-
- preventCrossOriginCookie(request);
-
- const redirectTo = loginPath({});
- await authenticator.logout(request, {
- redirectTo,
- });
-};
-
const LogoutPage = lazy(async () => {
const { LogoutPage } = await import("~/shared/logout.client");
return { default: LogoutPage };
@@ -90,18 +79,10 @@ const LogoutPage = lazy(async () => {
export default function Logout() {
const data = useLoaderData<typeof loader>();
- const formRef = useRef<HTMLFormElement>(null);
return (
<ClientOnly>
- <form action={"/logout"} method="post" ref={formRef}>
- <LogoutPage
- logoutUrls={data.logoutUrls}
- onFinish={() => {
- formRef.current?.submit();
- }}
- />
- </form>
+ <LogoutPage logoutUrls={data.logoutUrls} />
</ClientOnly>
);
}
diff --git a/apps/builder/app/routes/_ui.tsx b/apps/builder/app/routes/_ui.tsx
index e592a048be..26dbc59878 100644
--- a/apps/builder/app/routes/_ui.tsx
+++ b/apps/builder/app/routes/_ui.tsx
@@ -1,11 +1,9 @@
import {
- isRouteErrorResponse,
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
- useRouteError,
type ClientLoaderFunctionArgs,
} from "@remix-run/react";
import interFont from "@fontsource-variable/inter/index.css?url";
@@ -17,7 +15,7 @@ import {
type LinksFunction,
type LoaderFunctionArgs,
} from "@remix-run/server-runtime";
-import { ErrorMessage } from "~/shared/error/error-message";
+import { ErrorBoundary as ErrorBoundaryComponent } from "~/shared/error/error-boundary";
import { getCsrfTokenAndCookie } from "~/services/csrf-session.server";
import invariant from "tiny-invariant";
import {
@@ -79,6 +77,7 @@ export const clientLoader = async ({
serverLoader,
}: ClientLoaderFunctionArgs) => {
const serverData = await serverLoader<typeof loader>();
+
if (clientCsrfToken === undefined) {
const { csrfToken } = serverData;
invariant(csrfToken !== "", "CSRF token is empty");
@@ -93,20 +92,9 @@ export const clientLoader = async ({
clientLoader.hydrate = true;
export const ErrorBoundary = () => {
- const error = useRouteError();
-
- const message =
- error == null
- ? "Uknown error"
- : isRouteErrorResponse(error)
- ? `${error.status} ${error.statusText} ${error.data.message ?? error.data}`
- : typeof error === "object" && "message" in error
- ? error.message
- : JSON.stringify(error);
-
return (
<Document>
- <ErrorMessage message={`${message}`} />
+ <ErrorBoundaryComponent />
</Document>
);
};
diff --git a/apps/builder/app/routes/auth.dev.tsx b/apps/builder/app/routes/auth.dev.tsx
index 365c8b1482..1e621ef3d5 100644
--- a/apps/builder/app/routes/auth.dev.tsx
+++ b/apps/builder/app/routes/auth.dev.tsx
@@ -14,9 +14,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
preventCrossOriginCookie(request);
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/auth.github.tsx b/apps/builder/app/routes/auth.github.tsx
index 852dd1a6e7..6f9efcd560 100644
--- a/apps/builder/app/routes/auth.github.tsx
+++ b/apps/builder/app/routes/auth.github.tsx
@@ -12,9 +12,8 @@ export default function GH() {
export const action = async ({ request }: ActionFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/auth.github_.callback.tsx b/apps/builder/app/routes/auth.github_.callback.tsx
index ee326ecc1c..bf0325e0f6 100644
--- a/apps/builder/app/routes/auth.github_.callback.tsx
+++ b/apps/builder/app/routes/auth.github_.callback.tsx
@@ -9,9 +9,8 @@ import { allowedDestinations } from "~/services/destinations.server";
export const loader = async ({ request }: LoaderFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
preventCrossOriginCookie(request);
diff --git a/apps/builder/app/routes/auth.google.tsx b/apps/builder/app/routes/auth.google.tsx
index 08a066743d..8fb4abf269 100644
--- a/apps/builder/app/routes/auth.google.tsx
+++ b/apps/builder/app/routes/auth.google.tsx
@@ -17,9 +17,8 @@ export const loader = (_args: LoaderFunctionArgs) => redirect("/login");
export const action = async ({ request }: ActionFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/auth.google_.callback.tsx b/apps/builder/app/routes/auth.google_.callback.tsx
index 20b5129b91..cd65085409 100644
--- a/apps/builder/app/routes/auth.google_.callback.tsx
+++ b/apps/builder/app/routes/auth.google_.callback.tsx
@@ -9,9 +9,8 @@ import { allowedDestinations } from "~/services/destinations.server";
export const loader = async ({ request }: LoaderFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/auth.ws.ts b/apps/builder/app/routes/auth.ws.ts
index e683e8e248..2f99e8d44a 100644
--- a/apps/builder/app/routes/auth.ws.ts
+++ b/apps/builder/app/routes/auth.ws.ts
@@ -14,9 +14,8 @@ export const loader: LoaderFunction = async ({ request }) => {
if (false === isBuilder(request)) {
debug(`Request url is not the builder URL ${request.url}`);
- return new Response(null, {
+ return new Response("Only builder URL is allowed", {
status: 404,
- statusText: "Only builder URL is allowed",
});
}
@@ -41,9 +40,17 @@ export const loader: LoaderFunction = async ({ request }) => {
const url = new URL(request.url);
let returnTo = url.searchParams.get("returnTo");
- if (returnTo !== null && comparePathnames(returnTo, request.url)) {
- // avoid loops
- returnTo = "/";
+
+ if (returnTo !== null) {
+ if (comparePathnames(returnTo, request.url)) {
+ // avoid loops
+ returnTo = "/";
+ }
+
+ // Do not allow absolute URLs
+ if (URL.canParse(returnTo)) {
+ returnTo = "/";
+ }
}
const options = returnTo === null ? { maxAge: -1 } : {};
diff --git a/apps/builder/app/routes/auth.ws_.callback.ts b/apps/builder/app/routes/auth.ws_.callback.ts
index ff79b2e179..a13ce2fcd9 100644
--- a/apps/builder/app/routes/auth.ws_.callback.ts
+++ b/apps/builder/app/routes/auth.ws_.callback.ts
@@ -16,9 +16,8 @@ export const loader: LoaderFunction = async ({ request }) => {
if (false === isBuilder(request)) {
debug(`Request url is not the builder URL ${request.url}`);
- return new Response(null, {
+ return new Response("Only builder URL is allowed", {
status: 404,
- statusText: "Only builder URL is allowed",
});
}
diff --git a/apps/builder/app/routes/builder-logout.ts b/apps/builder/app/routes/builder-logout.ts
index a74ec7ad41..2037af6468 100644
--- a/apps/builder/app/routes/builder-logout.ts
+++ b/apps/builder/app/routes/builder-logout.ts
@@ -13,7 +13,9 @@ export const action = async ({ request }: ActionFunctionArgs) => {
// At the SaaS proxy side, only the allowed "access-control-allow-origin" header is set for OPTIONS requests.
if (false === isBuilder(request)) {
- throw new Error("Only Builder can logout at this endpoint");
+ throw new Response("Not found", {
+ status: 404,
+ });
}
if (request.method !== "POST") {
@@ -21,21 +23,29 @@ export const action = async ({ request }: ActionFunctionArgs) => {
{ message: "Method not allowed" },
{
status: 405,
- statusText: "Method Not Allowed",
}
);
}
if (request.headers.get("sec-fetch-site") === "same-origin") {
// To prevent logout initiated from the builder iframe
- throw new Error("Only cross-origin requests are allowed");
+
+ throw new Response("Only cross-origin requests are allowed", {
+ status: 403,
+ });
}
if (
false === request.headers.get("Content-Type")?.includes("application/json")
) {
// Enforce preflight request, preflight is checked on allowed origin
- throw new Error("Invalid content type, only application/json is allowed");
+
+ throw new Response(
+ "Invalid content type, only application/json is allowed",
+ {
+ status: 415,
+ }
+ );
}
const redirectTo = `${getAuthorizationServerOrigin(request.url)}${loginPath({})}`;
@@ -62,5 +72,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
throw error;
}
- throw new Error("Should not reach this point");
+ throw new Response("Should not reach this point", {
+ status: 500,
+ });
};
diff --git a/apps/builder/app/routes/builder.$projectId.tsx b/apps/builder/app/routes/builder.$projectId.tsx
index 7ae2ce460a..e6ac3b5ccd 100644
--- a/apps/builder/app/routes/builder.$projectId.tsx
+++ b/apps/builder/app/routes/builder.$projectId.tsx
@@ -6,7 +6,9 @@ import { builderUrl } from "~/shared/router-utils";
// @todo: Remove after 2024-12-31
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
if (params.projectId === undefined) {
- throw new Error("projectId is required");
+ throw new Response("projectId is required", {
+ status: 404,
+ });
}
const url = new URL(request.url);
diff --git a/apps/builder/app/routes/cgi.empty[.]gif.ts b/apps/builder/app/routes/cgi.empty[.]gif.ts
new file mode 100644
index 0000000000..e42430a127
--- /dev/null
+++ b/apps/builder/app/routes/cgi.empty[.]gif.ts
@@ -0,0 +1,15 @@
+// For development purposes only
+// Exists on saas worker
+export const loader = async () => {
+ const emptyGif = "R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
+
+ return new Response(
+ Uint8Array.from(atob(emptyGif), (c) => c.charCodeAt(0)).buffer,
+ {
+ headers: {
+ "Content-Type": "image/gif",
+ "Cache-Control": "public, max-age=10",
+ },
+ }
+ );
+};
diff --git a/apps/builder/app/routes/dashboard-logout.ts b/apps/builder/app/routes/dashboard-logout.ts
new file mode 100644
index 0000000000..7d949d854c
--- /dev/null
+++ b/apps/builder/app/routes/dashboard-logout.ts
@@ -0,0 +1,47 @@
+import { json } from "@remix-run/server-runtime";
+import { authenticator } from "~/services/auth.server";
+import { isDashboard, loginPath } from "~/shared/router-utils";
+import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
+import { type ActionFunctionArgs } from "react-router-dom";
+import { checkCsrf } from "~/services/csrf-session.server";
+import { isRedirectResponse } from "@remix-run/server-runtime/dist/responses";
+
+export const action = async ({ request }: ActionFunctionArgs) => {
+ try {
+ if (false === isDashboard(request)) {
+ throw new Response("Not found", {
+ status: 404,
+ });
+ }
+
+ preventCrossOriginCookie(request);
+ await checkCsrf(request);
+
+ const redirectTo = loginPath({});
+
+ await authenticator.logout(request, {
+ redirectTo,
+ });
+ } catch (error) {
+ if (error instanceof Response && isRedirectResponse(error)) {
+ const headers = new Headers();
+
+ if (error.headers.get("Set-Cookie")) {
+ headers.set("Set-Cookie", error.headers.get("Set-Cookie")!);
+ }
+
+ headers.set("Content-Type", "application/json");
+
+ return json(
+ {
+ redirectTo: error.headers.get("Location"),
+ },
+ {
+ headers,
+ }
+ );
+ }
+
+ return error;
+ }
+};
diff --git a/apps/builder/app/routes/n8n.$.tsx b/apps/builder/app/routes/n8n.$.tsx
index 3ba77342a9..f6d81c803a 100644
--- a/apps/builder/app/routes/n8n.$.tsx
+++ b/apps/builder/app/routes/n8n.$.tsx
@@ -27,9 +27,8 @@ const zWebhookEnv = z.object({
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
if (isDashboard(request) === false) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/oauth.ws.authorize.tsx b/apps/builder/app/routes/oauth.ws.authorize.tsx
index f77252ac97..2d42564816 100644
--- a/apps/builder/app/routes/oauth.ws.authorize.tsx
+++ b/apps/builder/app/routes/oauth.ws.authorize.tsx
@@ -81,9 +81,8 @@ const OAuthRedirectUri = z.object({
*/
export const loader: LoaderFunction = async ({ request }) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/oauth.ws.token.ts b/apps/builder/app/routes/oauth.ws.token.ts
index 8351f39e3d..866e77ea05 100644
--- a/apps/builder/app/routes/oauth.ws.token.ts
+++ b/apps/builder/app/routes/oauth.ws.token.ts
@@ -40,9 +40,8 @@ const debug = createDebug(import.meta.url);
*/
export const action = async ({ request }: ActionFunctionArgs) => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/rest.build.$buildId.tsx b/apps/builder/app/routes/rest.build.$buildId.tsx
index bfded9cd6c..e6c8b643d1 100644
--- a/apps/builder/app/routes/rest.build.$buildId.tsx
+++ b/apps/builder/app/routes/rest.build.$buildId.tsx
@@ -18,9 +18,8 @@ export const loader = async ({
}
> => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/routes/rest.buildId.$projectId.tsx b/apps/builder/app/routes/rest.buildId.$projectId.tsx
index ab2ab182ab..f0eb1a4351 100644
--- a/apps/builder/app/routes/rest.buildId.$projectId.tsx
+++ b/apps/builder/app/routes/rest.buildId.$projectId.tsx
@@ -12,9 +12,8 @@ export const loader = async ({
request,
}: LoaderFunctionArgs): Promise<{ buildId: string | null }> => {
if (false === isDashboard(request)) {
- throw new Response(null, {
+ throw new Response("Not Found", {
status: 404,
- statusText: "Not Found",
});
}
diff --git a/apps/builder/app/shared/error/error-boundary.tsx b/apps/builder/app/shared/error/error-boundary.tsx
new file mode 100644
index 0000000000..3757afd2a7
--- /dev/null
+++ b/apps/builder/app/shared/error/error-boundary.tsx
@@ -0,0 +1,79 @@
+import { isRouteErrorResponse, useRouteError } from "@remix-run/react";
+import { ClientOnly } from "../client-only";
+import { lazy } from "react";
+import { z } from "zod";
+
+const ErrorMessage = lazy(async () => {
+ const { ErrorMessage } = await import("./error-message.client");
+ return { default: ErrorMessage };
+});
+
+const PageError = z.union([
+ z.string().transform((message) => ({ message, description: undefined })),
+ z.object({
+ message: z.string(),
+ description: z.string().optional(),
+ }),
+]);
+
+const parseErrorObject = (
+ error: unknown
+): {
+ status: number;
+ statusText?: string;
+ message: string;
+ description?: string;
+} => {
+ if (error instanceof Error) {
+ return {
+ message: error.message,
+ status: 500,
+ };
+ }
+
+ if (isRouteErrorResponse(error)) {
+ const parsed = PageError.safeParse(error.data);
+
+ if (parsed.success) {
+ return {
+ message: parsed.data.message,
+ description: parsed.data.description,
+ status: error.status,
+ statusText: error.statusText,
+ };
+ }
+
+ return {
+ message: error.data ? JSON.stringify(error.data) : "unknown error",
+ status: error.status,
+ statusText: error.statusText,
+ };
+ }
+
+ const parsed = PageError.safeParse(error);
+ if (parsed.success) {
+ return {
+ message: parsed.data.message,
+ description: parsed.data.description,
+ status: 1001,
+ };
+ }
+
+ return {
+ message: JSON.stringify(error ?? "unknown error"),
+ status: 1001,
+ statusText: undefined,
+ };
+};
+
+export const ErrorBoundary = () => {
+ const rawError = useRouteError();
+
+ const error = parseErrorObject(rawError);
+
+ return (
+ <ClientOnly>
+ <ErrorMessage error={error} />
+ </ClientOnly>
+ );
+};
diff --git a/apps/builder/app/shared/error/error-message.client.tsx b/apps/builder/app/shared/error/error-message.client.tsx
new file mode 100644
index 0000000000..6a5fad8138
--- /dev/null
+++ b/apps/builder/app/shared/error/error-message.client.tsx
@@ -0,0 +1,87 @@
+import {
+ AccessibleIcon,
+ css,
+ Grid,
+ Text,
+ theme,
+} from "@webstudio-is/design-system";
+import { WebstudioIcon } from "@webstudio-is/icons";
+import { buttonStyle } from "~/auth/brand-button";
+
+const pageStyle = css({
+ position: "fixed",
+ justifyItems: "center",
+ alignContent: "start",
+ inset: 0,
+ background: `
+ radial-gradient(65.88% 47.48% at 50% 50%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%),
+ linear-gradient(0deg, rgba(255, 255, 255, 0) 49.46%, rgba(255, 255, 255, 0.33) 100%),
+ linear-gradient(180deg, rgba(255, 174, 60, 0) 0%, rgba(230, 60, 254, 0.33) 100%),
+ radial-gradient(211.58% 161.63% at 3.13% 100%, rgba(255, 174, 60, 0.3) 0%, rgba(227, 53, 255, 0) 100%),
+ radial-gradient(107.1% 32.15% at 92.96% 5.04%, rgba(53, 255, 182, 0.2) 0%, rgba(74, 78, 250, 0.2) 100%), #EBFFFC;
+ `,
+});
+
+export const ErrorMessage = ({
+ error,
+}: {
+ error: {
+ status: number;
+ statusText?: string;
+ message: string;
+ description?: string;
+ };
+}) => {
+ return (
+ <Grid className={pageStyle()} justify={"center"} gap={9}>
+ <div />
+ <AccessibleIcon label="Logo">
+ <WebstudioIcon size="60" />
+ </AccessibleIcon>
+ <Text
+ css={{
+ fontSize: theme.spacing[21],
+ }}
+ variant={"bigTitle"}
+ >
+ {error.status}
+ </Text>
+
+ <Grid
+ css={{
+ justifyItems: "center",
+ mx: theme.spacing[10],
+ maxWidth: 800,
+ }}
+ gap={5}
+ >
+ <Text
+ css={{
+ display: "-webkit-box",
+ "-webkit-line-clamp": 4,
+ "-webkit-box-orient": "vertical",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ wordBreak: "break-word",
+ }}
+ variant={"bigTitle"}
+ >
+ {error.message ?? error.statusText}
+ </Text>
+
+ {error.description && (
+ <Text
+ css={{ wordBreak: "break-word", whiteSpace: "pre-line" }}
+ variant={"regular"}
+ >
+ {error.description}
+ </Text>
+ )}
+
+ <a href="/" className={buttonStyle()}>
+ Go Home
+ </a>
+ </Grid>
+ </Grid>
+ );
+};
diff --git a/apps/builder/app/shared/error/error-message.tsx b/apps/builder/app/shared/error/error-message.tsx
deleted file mode 100644
index 7c6b6ddd07..0000000000
--- a/apps/builder/app/shared/error/error-message.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-export const ErrorMessage = ({ message }: { message: string }) => {
- return (
- <div>
- <h1>Error</h1>
- <pre>{message}</pre>
- </div>
- );
-};
diff --git a/apps/builder/app/shared/error/error-page.client.tsx b/apps/builder/app/shared/error/error-page.client.tsx
deleted file mode 100644
index 2e17a2fff0..0000000000
--- a/apps/builder/app/shared/error/error-page.client.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import {
- Toast,
- Text,
- TooltipProvider,
- Flex,
-} from "@webstudio-is/design-system";
-
-export type ErrorPageProps = {
- error: {
- message: string;
- description?: string;
- };
- onCloseNavigateTo: string;
-};
-
-export const ErrorPage = (props: ErrorPageProps) => {
- return (
- <TooltipProvider>
- <Flex
- css={{
- position: "fixed",
- inset: 0,
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <Flex>
- <Toast
- variant={"error"}
- onCopy={() => {
- navigator.clipboard.writeText(
- `${props.error.message}\n${props.error.description}`
- );
- }}
- onClose={() => {
- window.location.href = props.onCloseNavigateTo;
- }}
- >
- <Text variant={"titles"}>{props.error.message}</Text>
- <Text>{props.error.description}</Text>
- </Toast>
- </Flex>
- </Flex>
- </TooltipProvider>
- );
-};
diff --git a/apps/builder/app/shared/error/index.ts b/apps/builder/app/shared/error/index.ts
index b321e84cf6..09fb00bcd2 100644
--- a/apps/builder/app/shared/error/index.ts
+++ b/apps/builder/app/shared/error/index.ts
@@ -1 +1 @@
-export * from "./error-message";
+export * from "./error-message.client";
diff --git a/apps/builder/app/shared/logout.client.tsx b/apps/builder/app/shared/logout.client.tsx
index e3475ce530..1f9a58de8b 100644
--- a/apps/builder/app/shared/logout.client.tsx
+++ b/apps/builder/app/shared/logout.client.tsx
@@ -1,20 +1,39 @@
import { Text, Grid } from "@webstudio-is/design-system";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
+import { useEffectEvent } from "./hook-utils/effect-event";
+import { fetch } from "~/shared/fetch.client";
+import { z } from "zod";
+import { restLogoutPath } from "./router-utils";
-export type LogoutPageProps = {
+export type LogoutProps = {
logoutUrls: string[];
- onFinish: () => void;
+ onFinish: (failedProjects?: string[]) => void;
};
-export const LogoutPage = (props: LogoutPageProps) => {
+const MAX_RETRIES = 3;
+
+const Logout = (props: LogoutProps) => {
const [logoutState, setLogoutState] = useState({
- retries: 3,
+ retries: MAX_RETRIES,
logoutUrls: props.logoutUrls,
});
useEffect(() => {
+ if (logoutState.retries === 0) {
+ if (logoutState.retries === 0) {
+ // Show error message
+ props.onFinish(logoutState.logoutUrls);
+ }
+
+ return;
+ }
+
Promise.allSettled(
logoutState.logoutUrls.map(async (url) => {
+ await new Promise((resolve) =>
+ setTimeout(resolve, (MAX_RETRIES - logoutState.retries) * 1000)
+ );
+
const response = await fetch(url, {
method: "POST",
credentials: "include",
@@ -42,15 +61,6 @@ export const LogoutPage = (props: LogoutPageProps) => {
return;
}
- if (logoutState.retries === 0) {
- console.error(
- "Logout failed for the following URLs:",
- failedUrls.join(", ")
- );
- props.onFinish();
- return;
- }
-
setLogoutState({
retries: logoutState.retries - 1,
logoutUrls: failedUrls,
@@ -72,3 +82,78 @@ export const LogoutPage = (props: LogoutPageProps) => {
</Grid>
);
};
+
+export type LogoutPageProps = {
+ logoutUrls: string[];
+};
+
+const LogoutResponse = z.object({
+ redirectTo: z.string(),
+});
+
+export const LogoutPage = (props: LogoutPageProps) => {
+ const refForm = useRef<HTMLFormElement>(null);
+
+ const handleLogout = useEffectEvent(async (formData: FormData) => {
+ const response = await fetch(restLogoutPath(), {
+ method: "POST",
+ body: JSON.stringify(Object.fromEntries(formData.entries())),
+ headers: { "content-type": "application/json" },
+ redirect: "manual",
+ });
+
+ if (false === response.ok) {
+ throw {
+ message: "Logout failed. Please try again later.",
+ description: `Logout request failed with status ${response.status}: ${await response.text()}`,
+ };
+ }
+
+ const data = await response.json();
+ const parsedData = LogoutResponse.safeParse(data);
+
+ if (false === parsedData.success) {
+ throw {
+ message: "Logout failed. Please try again later",
+ description: "Logout request failed: Unsupported endpoint response",
+ };
+ }
+
+ if (formData.get("error") !== null) {
+ const value = formData.get("error")!.toString();
+
+ const failedProjects = (JSON.parse(value) as string[])
+ .map((project) => `- ${new URL(project).origin}`)
+ .join("\n");
+
+ throw {
+ message: "Logout failed. Please try again later",
+ description: `Something went wrong during the projects logout. Please try again later.\nProjects failed to logout:\n${failedProjects}`,
+ };
+ }
+
+ window.location.href = parsedData.data.redirectTo;
+ return;
+ });
+
+ const handleFinish = useEffectEvent((failedProjects?: string[]) => {
+ if (failedProjects !== undefined) {
+ const elt = document.createElement("button");
+ elt.type = "submit";
+ elt.name = "error";
+ elt.value = JSON.stringify(failedProjects);
+ elt.style.display = "none";
+ refForm.current?.appendChild(elt);
+ refForm.current?.requestSubmit(elt);
+ return;
+ }
+
+ refForm.current?.requestSubmit();
+ });
+
+ return (
+ <form ref={refForm} action={handleLogout}>
+ <Logout logoutUrls={props.logoutUrls} onFinish={handleFinish} />
+ </form>
+ );
+};
diff --git a/apps/builder/app/shared/router-utils/path-utils.ts b/apps/builder/app/shared/router-utils/path-utils.ts
index 2ade55a964..6b3adf974b 100644
--- a/apps/builder/app/shared/router-utils/path-utils.ts
+++ b/apps/builder/app/shared/router-utils/path-utils.ts
@@ -92,6 +92,7 @@ export const loginPath = (params: {
}) => `/login${searchParams(params)}`;
export const logoutPath = () => "/logout";
+export const restLogoutPath = () => "/dashboard-logout";
export const userPlanSubscriptionPath = () => {
const urlSearchParams = new URLSearchParams();
diff --git a/apps/builder/package.json b/apps/builder/package.json
index 095b426f47..0cf2fa73ee 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -96,6 +96,7 @@
"nanoevents": "^8.0.0",
"nanoid": "^5.0.1",
"nanostores": "^0.9.3",
+ "picocolors": "^1.0.1",
"pretty-bytes": "^6.1.1",
"prismjs": "^1.29.0",
"react": "18.3.0-canary-14898b6a9-20240318",
diff --git a/apps/builder/vite.config.ts b/apps/builder/vite.config.ts
index c0d47edc8d..846dca4679 100644
--- a/apps/builder/vite.config.ts
+++ b/apps/builder/vite.config.ts
@@ -3,6 +3,8 @@ import { defineConfig, type CorsOptions } from "vite";
import { vitePlugin as remix } from "@remix-run/dev";
import { vercelPreset } from "@vercel/remix/vite";
import type { IncomingMessage } from "node:http";
+import pc from "picocolors";
+
import {
getAuthorizationServerOrigin,
isBuilderUrl,
@@ -21,6 +23,29 @@ export default defineConfig(({ mode }) => {
remix({
presets: [vercelPreset()],
}),
+ {
+ name: "request-timing-logger",
+ configureServer(server) {
+ server.middlewares.use((req, res, next) => {
+ const start = Date.now();
+ res.on("finish", () => {
+ const duration = Date.now() - start;
+ if (
+ !(
+ req.url?.startsWith("/@") ||
+ req.url?.startsWith("/app") ||
+ req.url?.includes("/node_modules")
+ )
+ ) {
+ console.info(
+ `[${req.method}] ${req.url} - ${duration}ms : ${pc.dim(req.headers.host)}`
+ );
+ }
+ });
+ next();
+ });
+ },
+ },
],
resolve: {
conditions: ["webstudio", "import", "module", "browser", "default"],
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 87941c095f..dcf7a19811 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -361,6 +361,9 @@ importers:
nanostores:
specifier: ^0.9.3
version: 0.9.3
+ picocolors:
+ specifier: ^1.0.1
+ version: 1.0.1
pretty-bytes:
specifier: ^6.1.1
version: 6.1.1