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 critical css for global styles, reset styles for ssr

Oleg Isonencfcf9c5b62ef
diff --git a/apps/designer/app/critical-css.ts b/apps/designer/app/critical-css.ts
index a79e95cd53..adef6a6865 100644
--- a/apps/designer/app/critical-css.ts
+++ b/apps/designer/app/critical-css.ts
@@ -1,24 +1,40 @@
import {
insertCriticalCss as insert,
getCssText as getCanvasCssText,
+ resetCss as resetCanvasCss,
} from "@webstudio-is/react-sdk";
-import { getCssText as getDesignerCssText } from "@webstudio-is/design-system";
+import {
+ getCssText as getDesignerCssText,
+ reset as resetDesignerCss,
+} from "@webstudio-is/design-system";
import config from "./config";
-const getCssTextFunctions = {
- [config.previewPath]: getCanvasCssText,
- [config.canvasPath]: getCanvasCssText,
- [config.designerPath]: getDesignerCssText,
- [config.dashboardPath]: getDesignerCssText,
- [config.loginPath]: getDesignerCssText,
+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 getCssTextFunction = (url: string) => {
+const getFlushFunction = (url: string) => {
const { pathname } = new URL(url);
- let path: keyof typeof getCssTextFunctions;
- for (path in getCssTextFunctions) {
+ let path: keyof typeof flushFunctions;
+ for (path in flushFunctions) {
if (pathname.indexOf(path) === 0) {
- return getCssTextFunctions[path];
+ return flushFunctions[path];
}
}
return getCanvasCssText;
@@ -30,5 +46,5 @@ const getCssTextFunction = (url: string) => {
* @todo find a better way
*/
export const insertCriticalCss = (markup: string, url: string): string => {
- return insert(markup, getCssTextFunction(url));
+ return insert(markup, getFlushFunction(url));
};
diff --git a/packages/react-sdk/src/stitches/css.ts b/packages/react-sdk/src/stitches/css.ts
index 38f559bda1..6baf04d7c1 100644
--- a/packages/react-sdk/src/stitches/css.ts
+++ b/packages/react-sdk/src/stitches/css.ts
@@ -1,6 +1,6 @@
import {
createStitches,
- globalCss,
+ globalCss as globalCssImport,
type CSS,
css as createCss,
} from "@stitches/core";
@@ -12,6 +12,8 @@ let media = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let stitches: any;
+export { type CSS };
+
export const getCachedConfig = () => {
if (stitches === undefined) {
stitches = createStitches({ media });
@@ -23,13 +25,18 @@ export const css: typeof createCss = (...args) => {
return getCachedConfig().css(...args);
};
-export { globalCss };
-export { type CSS };
+export const globalCss: typeof globalCssImport = (...args) => {
+ return getCachedConfig().globalCss(...args);
+};
export const getCssText = (): string => {
return getCachedConfig().getCssText();
};
+export const resetCss = () => {
+ getCachedConfig().reset();
+};
+
export const setBreakpoints = (breakpoints: Array<Breakpoint>) => {
const nextMedia: Record<string, string> = {};
for (const breakpoint of breakpoints) {