diff --git a/apps/designer/app/critical-css.ts b/apps/designer/app/critical-css.ts
deleted file mode 100644
index adef6a6865..0000000000
--- a/apps/designer/app/critical-css.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import {
- insertCriticalCss as insert,
- getCssText as getCanvasCssText,
- resetCss as resetCanvasCss,
-} from "@webstudio-is/react-sdk";
-import {
- getCssText as getDesignerCssText,
- reset as resetDesignerCss,
-} from "@webstudio-is/design-system";
-import config from "./config";
-
-const flushCanvas = () => {
- const css = getCanvasCssText();
- resetCanvasCss();
- return css;
-};
-
-const flushDesigner = () => {
- const css = getDesignerCssText();
- resetDesignerCss();
- return css;
-};
-
-const flushFunctions = {
- [config.previewPath]: flushCanvas,
- [config.canvasPath]: flushCanvas,
- [config.designerPath]: flushDesigner,
- [config.dashboardPath]: flushDesigner,
- [config.loginPath]: flushDesigner,
-};
-
-const getFlushFunction = (url: string) => {
- const { pathname } = new URL(url);
- let path: keyof typeof flushFunctions;
- for (path in flushFunctions) {
- if (pathname.indexOf(path) === 0) {
- return flushFunctions[path];
- }
- }
- return getCanvasCssText;
-};
-
-/**
- * This works around the problem with getCssTextfunction being a different one
- * depending on createStitches() used in each outlet.
- * @todo find a better way
- */
-export const insertCriticalCss = (markup: string, url: string): string => {
- return insert(markup, getFlushFunction(url));
-};
diff --git a/apps/designer/app/entry.server.tsx b/apps/designer/app/entry.server.tsx
index 0d2bdf0cc2..2d217876da 100644
--- a/apps/designer/app/entry.server.tsx
+++ b/apps/designer/app/entry.server.tsx
@@ -1,10 +1,10 @@
-import { renderToString } from "react-dom/server";
-import { RemixServer } from "@remix-run/react";
-import { insertCriticalCss } from "./critical-css";
import type { EntryContext } from "@remix-run/node";
import * as Sentry from "@sentry/remix";
import { initSentry } from "./shared/sentry";
import { prisma } from "@webstudio-is/prisma-client";
+import { handleRequest as handleRequestDesigner } from "./shared/remix";
+import { handleRequest as handleRequestCanvas } from "@webstudio-is/react-sdk";
+import config from "./config";
initSentry({
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
@@ -16,17 +16,15 @@ export default function handleRequest(
responseHeaders: Headers,
remixContext: EntryContext
) {
- let markup = renderToString(
-
- );
+ const { pathname } = new URL(request.url);
+ let handle = handleRequestDesigner;
- markup = insertCriticalCss(markup, request.url);
+ if (
+ pathname.indexOf(config.previewPath) === 0 ||
+ pathname.indexOf(config.canvasPath) === 0
+ ) {
+ handle = handleRequestCanvas;
+ }
- responseHeaders.set("Content-Type", "text/html");
- responseHeaders.set("Accept-CH", "Sec-CH-Prefers-Color-Scheme");
-
- return new Response("" + markup, {
- status: responseStatusCode,
- headers: responseHeaders,
- });
+ return handle(request, responseStatusCode, responseHeaders, remixContext);
}
diff --git a/apps/designer/app/routes/dashboard.tsx b/apps/designer/app/routes/dashboard.tsx
index 20bd4e9ce0..4a0cb028ab 100644
--- a/apps/designer/app/routes/dashboard.tsx
+++ b/apps/designer/app/routes/dashboard.tsx
@@ -1,5 +1,5 @@
import type { LoaderFunction, MetaFunction } from "@remix-run/node";
-import { Designer } from "~/shared/documents/designer";
+import { Root } from "~/shared/remix";
import env from "~/env.server";
import { getThemeData } from "~/shared/theme";
@@ -14,4 +14,4 @@ export const meta: MetaFunction = () => {
return { title: "Webstudio Dashboard" };
};
-export default Designer;
+export default Root;
diff --git a/apps/designer/app/routes/designer.tsx b/apps/designer/app/routes/designer.tsx
index 7097e1b5cf..44e8680655 100644
--- a/apps/designer/app/routes/designer.tsx
+++ b/apps/designer/app/routes/designer.tsx
@@ -1,5 +1,5 @@
import type { LoaderFunction, MetaFunction } from "@remix-run/node";
-import { Designer } from "~/shared/documents/designer";
+import { Root } from "~/shared/remix";
import env from "~/env.server";
import { getThemeData } from "~/shared/theme";
@@ -14,4 +14,4 @@ export const meta: MetaFunction = () => {
return { title: "Webstudio" };
};
-export default Designer;
+export default Root;
diff --git a/apps/designer/app/routes/login.tsx b/apps/designer/app/routes/login.tsx
index 99d9febb01..a76cc559f8 100644
--- a/apps/designer/app/routes/login.tsx
+++ b/apps/designer/app/routes/login.tsx
@@ -1,5 +1,5 @@
import { LoaderFunction, MetaFunction } from "@remix-run/node";
-import { Designer } from "~/shared/documents/designer";
+import { Root } from "~/shared/remix";
import env from "~/env.server";
import { getThemeData } from "~/shared/theme";
@@ -14,4 +14,4 @@ export const meta: MetaFunction = () => {
return { title: "Webstudio Login" };
};
-export default Designer;
+export default Root;
diff --git a/apps/designer/app/shared/remix/constants.ts b/apps/designer/app/shared/remix/constants.ts
new file mode 100644
index 0000000000..b5ddbd71f5
--- /dev/null
+++ b/apps/designer/app/shared/remix/constants.ts
@@ -0,0 +1 @@
+export const CRITICAL_CSS_MARKER = "__CRITICAL_CSS__";
diff --git a/apps/designer/app/shared/remix/handle-request.server.tsx b/apps/designer/app/shared/remix/handle-request.server.tsx
new file mode 100644
index 0000000000..9b72cb7cc7
--- /dev/null
+++ b/apps/designer/app/shared/remix/handle-request.server.tsx
@@ -0,0 +1,23 @@
+import { renderToString } from "react-dom/server";
+import { RemixServer } from "@remix-run/react";
+import type { EntryContext } from "@remix-run/node";
+import { insertCriticalCss } from "./insert-critical-css";
+
+export const handleRequest = (
+ request: Request,
+ responseStatusCode: number,
+ responseHeaders: Headers,
+ remixContext: EntryContext
+) => {
+ const markup = renderToString(
+
+ );
+
+ responseHeaders.set("Content-Type", "text/html");
+ responseHeaders.set("Accept-CH", "Sec-CH-Prefers-Color-Scheme");
+
+ return new Response("" + insertCriticalCss(markup), {
+ status: responseStatusCode,
+ headers: responseHeaders,
+ });
+};
diff --git a/apps/designer/app/shared/remix/index.ts b/apps/designer/app/shared/remix/index.ts
new file mode 100644
index 0000000000..444dfb6c40
--- /dev/null
+++ b/apps/designer/app/shared/remix/index.ts
@@ -0,0 +1,2 @@
+export * from "./handle-request.server";
+export * from "./root";
diff --git a/apps/designer/app/shared/remix/insert-critical-css.ts b/apps/designer/app/shared/remix/insert-critical-css.ts
new file mode 100644
index 0000000000..fda5504048
--- /dev/null
+++ b/apps/designer/app/shared/remix/insert-critical-css.ts
@@ -0,0 +1,6 @@
+import { flushCss } from "@webstudio-is/design-system";
+import { CRITICAL_CSS_MARKER } from "./constants";
+
+export const insertCriticalCss = (markup: string): string => {
+ return markup.replace(CRITICAL_CSS_MARKER, ``);
+};
diff --git a/apps/designer/app/shared/documents/designer.tsx b/apps/designer/app/shared/remix/root.tsx
similarity index 79%
rename from apps/designer/app/shared/documents/designer.tsx
rename to apps/designer/app/shared/remix/root.tsx
index 4638c4919a..38a1e662c6 100644
--- a/apps/designer/app/shared/documents/designer.tsx
+++ b/apps/designer/app/shared/remix/root.tsx
@@ -1,9 +1,9 @@
import { Links, LiveReload, Meta, Outlet, Scripts } from "@remix-run/react";
-import { CriticalCss } from "@webstudio-is/react-sdk";
import { Env } from "~/shared/env";
import { useThemeProps } from "~/shared/theme";
+import { CRITICAL_CSS_MARKER } from "./constants";
-export const Designer = () => {
+export const Root = () => {
const themeProps = useThemeProps();
return (
@@ -12,7 +12,7 @@ export const Designer = () => {
-
+ {typeof document === "undefined" ? CRITICAL_CSS_MARKER : null}
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index ec369e4873..54bb4137dc 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -1,16 +1,4 @@
-export {
- config,
- createTheme,
- css,
- darkTheme,
- getCssText,
- globalCss,
- keyframes,
- reset,
- styled,
- theme,
- type CSS,
-} from "./stitches.config";
+export * from "./stitches.config";
export * from "./components/toast";
export * as Collapsible from "@radix-ui/react-collapsible";
diff --git a/packages/design-system/src/stitches.config.ts b/packages/design-system/src/stitches.config.ts
index e159c2e7d7..b1906c6d94 100644
--- a/packages/design-system/src/stitches.config.ts
+++ b/packages/design-system/src/stitches.config.ts
@@ -118,7 +118,7 @@ import {
import type * as Stitches from "@stitches/react";
export type { VariantProps } from "@stitches/react";
-export const {
+const {
styled,
css,
theme,
@@ -414,6 +414,14 @@ export const {
export type CSS = Stitches.CSS;
+export { styled, css, theme, globalCss, keyframes, config };
+
+export const flushCss = () => {
+ const css = getCssText();
+ reset();
+ return css;
+};
+
export const darkTheme = createTheme({
colors: {
...grayDark,
diff --git a/packages/react-sdk/src/canvas/index.ts b/packages/react-sdk/src/canvas/index.ts
deleted file mode 100644
index df456a3704..0000000000
--- a/packages/react-sdk/src/canvas/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./canvas";
diff --git a/packages/react-sdk/src/index.ts b/packages/react-sdk/src/index.ts
index 58ede255ac..7458f83c4d 100644
--- a/packages/react-sdk/src/index.ts
+++ b/packages/react-sdk/src/index.ts
@@ -6,4 +6,4 @@ export * as componentsMeta from "./components/meta";
export * from "./user-props";
export * from "./pubsub";
export * from "./db";
-export * from "./canvas";
+export * from "./remix";
diff --git a/packages/react-sdk/src/remix/constants.ts b/packages/react-sdk/src/remix/constants.ts
new file mode 100644
index 0000000000..b5ddbd71f5
--- /dev/null
+++ b/packages/react-sdk/src/remix/constants.ts
@@ -0,0 +1 @@
+export const CRITICAL_CSS_MARKER = "__CRITICAL_CSS__";
diff --git a/packages/react-sdk/src/remix/handle-request.server.tsx b/packages/react-sdk/src/remix/handle-request.server.tsx
new file mode 100644
index 0000000000..8efe2c9943
--- /dev/null
+++ b/packages/react-sdk/src/remix/handle-request.server.tsx
@@ -0,0 +1,22 @@
+import { renderToString } from "react-dom/server";
+import { RemixServer } from "@remix-run/react";
+import type { EntryContext } from "@remix-run/node";
+import { insertCriticalCss } from "./insert-critical-css";
+
+export const handleRequest = (
+ request: Request,
+ responseStatusCode: number,
+ responseHeaders: Headers,
+ remixContext: EntryContext
+) => {
+ const markup = renderToString(
+
+ );
+
+ responseHeaders.set("Content-Type", "text/html");
+
+ return new Response("" + insertCriticalCss(markup), {
+ status: responseStatusCode,
+ headers: responseHeaders,
+ });
+};
diff --git a/packages/react-sdk/src/remix/index.ts b/packages/react-sdk/src/remix/index.ts
new file mode 100644
index 0000000000..1287530143
--- /dev/null
+++ b/packages/react-sdk/src/remix/index.ts
@@ -0,0 +1,2 @@
+export * from "./root";
+export * from "./handle-request.server";
diff --git a/packages/react-sdk/src/remix/insert-critical-css.ts b/packages/react-sdk/src/remix/insert-critical-css.ts
new file mode 100644
index 0000000000..9f0bdd20ca
--- /dev/null
+++ b/packages/react-sdk/src/remix/insert-critical-css.ts
@@ -0,0 +1,6 @@
+import { flushCss } from "../stitches";
+import { CRITICAL_CSS_MARKER } from "./constants";
+
+export const insertCriticalCss = (markup: string): string => {
+ return markup.replace(CRITICAL_CSS_MARKER, ``);
+};
diff --git a/packages/react-sdk/src/canvas/canvas.tsx b/packages/react-sdk/src/remix/root.tsx
similarity index 84%
rename from packages/react-sdk/src/canvas/canvas.tsx
rename to packages/react-sdk/src/remix/root.tsx
index b20e8fb98e..eced0b5951 100644
--- a/packages/react-sdk/src/canvas/canvas.tsx
+++ b/packages/react-sdk/src/remix/root.tsx
@@ -1,5 +1,5 @@
import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
-import { CriticalCss } from "..";
+import { CRITICAL_CSS_MARKER } from "./constants";
/**
* We are using Outlet prop from index layout when user renders site from a subdomain.
@@ -18,7 +18,7 @@ export const Root = ({
-
+ {typeof document === "undefined" ? CRITICAL_CSS_MARKER : null}