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 assets vercel uploading (#1626)

Ivan Starkov2374b5f22b10
diff --git a/apps/builder/app/routes/$.tsx b/apps/builder/app/routes/$.tsx
index 6b3c517104..003a9a99ab 100644
--- a/apps/builder/app/routes/$.tsx
+++ b/apps/builder/app/routes/$.tsx
@@ -1,6 +1,10 @@
import { redirect } from "@remix-run/node";
import type { LoaderArgs } from "@remix-run/node";
-import { useLoaderData, useRouteError } from "@remix-run/react";
+import {
+ isRouteErrorResponse,
+ useLoaderData,
+ useRouteError,
+} from "@remix-run/react";
import { type Params, Root, getComponent } from "@webstudio-is/react-sdk";
import env from "~/env/env.public.server";
import { sentryException } from "~/shared/sentry";
@@ -9,6 +13,17 @@ import { ErrorMessage } from "~/shared/error";
import { getBuildParams, dashboardPath } from "~/shared/router-utils";
export const loader = async ({ request }: LoaderArgs) => {
+ const url = new URL(request.url);
+ // See remix.config.ts for the publicPath value
+ const publicPath = "/build/";
+
+ // In case of 404 on static assets, this route will be executed
+ if (url.pathname.startsWith(publicPath)) {
+ throw new Response("Not found", {
+ status: 404,
+ });
+ }
+
const buildParams = getBuildParams(request);
if (buildParams === undefined) {
throw redirect(dashboardPath());
@@ -27,8 +42,14 @@ export const loader = async ({ request }: LoaderArgs) => {
export const ErrorBoundary = () => {
const error = useRouteError();
+
sentryException({ error });
- const message = error instanceof Error ? error.message : String(error);
+ const message = isRouteErrorResponse(error)
+ ? error.data.message ?? error.data
+ : error instanceof Error
+ ? error.message
+ : String(error);
+
return <ErrorMessage message={message} />;
};
diff --git a/apps/builder/app/routes/vercel-deploy-workaround.tsx b/apps/builder/app/routes/vercel-deploy-workaround.tsx
new file mode 100644
index 0000000000..89c6779ef9
--- /dev/null
+++ b/apps/builder/app/routes/vercel-deploy-workaround.tsx
@@ -0,0 +1,29 @@
+import type { LinksFunction } from "@remix-run/node";
+
+import { Root } from "~/shared/remix";
+// eslint-disable-next-line import/no-internal-modules
+import interFont from "@fontsource/inter/variable.css";
+// eslint-disable-next-line import/no-internal-modules
+import manropeVariableFont from "@fontsource/manrope/variable.css";
+// eslint-disable-next-line import/no-internal-modules
+import robotoMonoFont from "@fontsource/roboto-mono/index.css";
+// eslint-disable-next-line import/no-internal-modules
+import appCss from "../shared/app.css";
+
+/**
+ * For unknown reason vercel don't upload css assets if they are not exported from route path
+ * This is workaround to make sure that all css assets we use in request handler are uploaded
+ */
+
+export const links: LinksFunction = () => {
+ // `links` returns an array of objects whose
+ // properties map to the `<link />` component props
+ return [
+ { rel: "stylesheet", href: interFont },
+ { rel: "stylesheet", href: manropeVariableFont },
+ { rel: "stylesheet", href: robotoMonoFont },
+ { rel: "stylesheet", href: appCss },
+ ];
+};
+
+export default Root;
diff --git a/apps/builder/app/shared/remix/handle-request.server.tsx b/apps/builder/app/shared/remix/handle-request.server.tsx
index d33c6d2f2a..d203bce57f 100644
--- a/apps/builder/app/shared/remix/handle-request.server.tsx
+++ b/apps/builder/app/shared/remix/handle-request.server.tsx
@@ -4,13 +4,7 @@ import type { EntryContext } from "@remix-run/node";
import { flushCss } from "@webstudio-is/design-system";
import { renderHeadToString } from "remix-island";
import { Head } from "./root";
-// eslint-disable-next-line import/no-internal-modules
-import interFont from "@fontsource/inter/variable.css";
-// eslint-disable-next-line import/no-internal-modules
-import manropeVariableFont from "@fontsource/manrope/variable.css";
-// eslint-disable-next-line import/no-internal-modules
-import robotoMonoFont from "@fontsource/roboto-mono/index.css";
-import appCss from "../app.css";
+import { links } from "~/routes/vercel-deploy-workaround";
export const handleRequest = (
request: Request,
@@ -35,10 +29,13 @@ export const handleRequest = (
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
- <link rel="stylesheet" href="${interFont}" />
- <link rel="stylesheet" href="${manropeVariableFont}" />
- <link rel="stylesheet" href="${robotoMonoFont}" />
- <link rel="stylesheet" href="${appCss}" />
+ ${links()
+ .map((link) =>
+ "href" in link
+ ? `<link rel="${link.rel}" href="${link.href}" />`
+ : ""
+ )
+ .join("\n")}
${head}
<style id="stitches">${flushCss()}</style>
</head>