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.

use dynamicLinks from remix-utils to handle link tags and ssr generated css

Oleg Isonen66fa251fda70
diff --git a/apps/designer/app/routes/$.tsx b/apps/designer/app/routes/$.tsx
index 8755c9e88b..86530cf256 100644
--- a/apps/designer/app/routes/$.tsx
+++ b/apps/designer/app/routes/$.tsx
@@ -17,11 +17,21 @@ import {
dashboardPath,
} from "~/shared/router-utils";
import { db } from "@webstudio-is/project/server";
+import { DynamicLinksFunction } from "remix-utils";
type Data =
| (CanvasData & { env: Env; mode: BuildMode })
| { errors: string; env: Env };
+export const dynamicLinks: DynamicLinksFunction<CanvasData> = ({
+ data,
+ location,
+}) => {
+ const searchParams = new URLSearchParams(location.search);
+ searchParams.set("pageId", data.page.id);
+ return [{ rel: "stylesheet", href: `/s/css/?${searchParams}` }];
+};
+
export const meta: MetaFunction = ({ data }: { data: Data }) => {
if ("errors" in data) {
return { title: "Error" };
@@ -33,6 +43,7 @@ export const meta: MetaFunction = ({ data }: { data: Data }) => {
export const loader: LoaderFunction = async ({
request,
}): Promise<Data | Response> => {
+ console.log(111);
try {
const buildParams = getBuildParams(request);
diff --git a/apps/designer/app/routes/index.tsx b/apps/designer/app/routes/index.tsx
index 476a48fc1f..3ebf1fc3b3 100644
--- a/apps/designer/app/routes/index.tsx
+++ b/apps/designer/app/routes/index.tsx
@@ -7,6 +7,7 @@ import { LoaderFunction, MetaFunction } from "@remix-run/node";
import CatchAllContnet, {
loader as catchAllloader,
meta as catchAllmeta,
+ dynamicLinks as catchAllDynamicLinks,
} from "./$";
// We're wrapping functions in order for them to be distinct from the ones in $.tsx.
@@ -14,5 +15,7 @@ import CatchAllContnet, {
export const meta: MetaFunction = (args) => catchAllmeta(args);
export const loader: LoaderFunction = (args) => catchAllloader(args);
+export const dynamicLinks = (args: any) => catchAllDynamicLinks(args);
+export const handle = { dynamicLinks };
const Content = () => <CatchAllContnet />;
export default Content;
diff --git a/apps/designer/package.json b/apps/designer/package.json
index 5528740b1c..eac62ffe8b 100644
--- a/apps/designer/package.json
+++ b/apps/designer/package.json
@@ -25,8 +25,8 @@
"@sentry/remix": "^7.5.0",
"@vercel/node": "^2.4.1",
"@webstudio-is/asset-uploader": "*",
- "@webstudio-is/css-vars": "*",
"@webstudio-is/css-engine": "*",
+ "@webstudio-is/css-vars": "*",
"@webstudio-is/design-system": "*",
"@webstudio-is/icons": "*",
"@webstudio-is/prisma-client": "*",
@@ -63,6 +63,7 @@
"remix-auth-form": "^1.1.2",
"remix-auth-github": "^1.1.1",
"remix-auth-google": "^1.1.0",
+ "remix-utils": "^4.1.0",
"slugify": "^1.6.5",
"zod-form-data": "^1.2.1"
},
diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json
index 21243f8607..5c51b2848d 100644
--- a/packages/react-sdk/package.json
+++ b/packages/react-sdk/package.json
@@ -23,6 +23,7 @@
"@esbuild-kit/esm-loader": "^2.4.2",
"@remix-run/react": "^1.2.3",
"@remix-run/server-runtime": "^1.2.3",
+ "remix-utils": "^4.1.0",
"@storybook/addon-actions": "^6.5.6",
"@storybook/addon-essentials": "^6.5.6",
"@storybook/addon-interactions": "^6.5.6",
@@ -52,6 +53,7 @@
"peerDependencies": {
"@remix-run/react": "^1.2.3",
"@remix-run/server-runtime": "^1.2.3",
+ "remix-utils": "^4.1.0",
"@storybook/react": "^6.5.6",
"react": "^17.0.2",
"react-dom": "^17.0.2"
diff --git a/packages/react-sdk/src/remix/root.tsx b/packages/react-sdk/src/remix/root.tsx
index eced0b5951..c584e65ebf 100644
--- a/packages/react-sdk/src/remix/root.tsx
+++ b/packages/react-sdk/src/remix/root.tsx
@@ -1,4 +1,5 @@
import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
+import { DynamicLinks } from "remix-utils";
import { CRITICAL_CSS_MARKER } from "./constants";
/**
@@ -17,9 +18,11 @@ export const Root = ({
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<Meta />
+ <DynamicLinks />
<Links />
{typeof document === "undefined" ? CRITICAL_CSS_MARKER : null}
</head>
+
<Outlet />
</html>
);
diff --git a/yarn.lock b/yarn.lock
index ee9628f388..97eb7b56f2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -11030,6 +11030,11 @@ interpret@^2.2.0:
resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==
+intl-parse-accept-language@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/intl-parse-accept-language/-/intl-parse-accept-language-1.0.0.tgz#204d1bc0b13c5baea7775f5eeb95bef2b795675c"
+ integrity sha512-YFMSV91JNBOSjw1cOfw2tup6hDP7mkz+2AUV7W1L1AM6ntgI75qC1ZeFpjPGMrWp+upmBRTX2fJWQ8c7jsUWpA==
+
invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@@ -11037,6 +11042,11 @@ invariant@^2.2.4:
dependencies:
loose-envify "^1.0.0"
+ip-regex@^4.0.0:
+ version "4.3.0"
+ resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.3.0.tgz#687275ab0f57fa76978ff8f4dddc8a23d5990db5"
+ integrity sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==
+
ip@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"
@@ -11342,6 +11352,13 @@ is-interactive@^1.0.0:
resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e"
integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==
+is-ip@^3.1.0:
+ version "3.1.0"
+ resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8"
+ integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==
+ dependencies:
+ ip-regex "^4.0.0"
+
is-map@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.2.tgz#00922db8c9bf73e81b7a335827bc2a43f2b91127"
@@ -15710,6 +15727,17 @@ remix-auth@^3.0.0, remix-auth@^3.1.0, remix-auth@^3.2.2:
dependencies:
uuid "^8.3.2"
+remix-utils@^4.1.0:
+ version "4.1.0"
+ resolved "https://registry.yarnpkg.com/remix-utils/-/remix-utils-4.1.0.tgz#d46cce6661befecdb3ed40269c3215377e719b58"
+ integrity sha512-Ii/+6bd56t2D3ADeXD4RGc3Ym7Yn/rA/n7GZ9naTjF+fire7vqsDhBPwhZV0gIJBLIbw8ZRUlIAg+Ia95+CLBA==
+ dependencies:
+ intl-parse-accept-language "^1.0.0"
+ is-ip "^3.1.0"
+ schema-dts "^1.1.0"
+ type-fest "^2.5.2"
+ uuid "^8.3.2"
+
version "0.4.2"
resolved "https://registry.yarnpkg.com/remove-accents/-/remove-accents-0.4.2.tgz#0a43d3aaae1e80db919e07ae254b285d9e1c7bb5"
@@ -16049,6 +16077,11 @@ scheduler@^0.23.0:
dependencies:
loose-envify "^1.1.0"
+schema-dts@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/schema-dts/-/schema-dts-1.1.0.tgz#33227971076ef1daa33e56a3127a8aae030e81c9"
+ integrity sha512-vdmbs/5ycj4zyKpZIDqTcy+IZi4s7c38RVAYuDmRi7zgxUT8wRWPMLzg0jr7FjdVunYu9yZ00F3+XcZTTFcTOQ==
+
version "2.7.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7"
@@ -17603,7 +17636,7 @@ type-fest@^1.0.2:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"
integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==
-type-fest@^2.18.0:
+type-fest@^2.18.0, type-fest@^2.5.2:
version "2.19.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==