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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
experimental: Always finish up builder loading animation (#3537)
Oleg Isonen4567f0956c83
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsxindex dbba8a496e..dc74ccc6fc 100644--- a/apps/builder/app/builder/builder.tsx+++ b/apps/builder/app/builder/builder.tsx@@ -61,7 +61,6 @@ import { canvasApi } from "~/shared/canvas-api";import { loadBuilderData, setBuilderData } from "~/shared/builder-data";import { WebstudioIcon } from "@webstudio-is/icons";import { computed } from "nanostores";-import { useInterval } from "~/shared/hook-utils/use-interval";import { $dataLoadingState } from "~/shared/nano-states/builder";registerContainers();@@ -281,27 +280,20 @@ const $loadingState = computed();const ProgressIndicator = ({ value }: { value: number }) => {+ const [isDone, setIsDone] = useState(false);const [fakeValue, setFakeValue] = useState(value);- // A maximum fake value we can grow to if the value is still 0, so that we don't get stuck at 0%.- const defaultFakeValueLimit = 50;-- // This is an approximation of a real progress that should come from "value".- useInterval((timerId) => {- if (value >= 100) {- clearInterval(timerId);- return;- }- setFakeValue((fakeValue) => {- fakeValue++;- // - When real value is 0, we don't want to use it, because we don't want to get stuck at 0.- // - When real value is smaller than fake value, we don't want to use it because that would jump the progress back.- const minFakeValue =- value === 0 || value < fakeValue ? defaultFakeValueLimit : value;- return Math.min(fakeValue, minFakeValue);- });- }, 50);-- if (value >= 100) {++ useEffect(() => {+ const id = setTimeout(() => {+ setFakeValue((fakeValue) => {+ // Fetching data is the slowest part and we don't want to get stuck at 0% visually+ return Math.max(value, 50);+ });+ }, 300);+ return () => clearTimeout(id);+ }, [value]);++ if (isDone) {return;}@@ -324,9 +316,19 @@ const ProgressIndicator = ({ value }: { value: number }) => {drop-shadow(3px 3px 6px rgba(0, 0, 0, 0.7))brightness(${fakeValue}%)`,+ transitionProperty: "filter",+ transitionDuration: "500ms",+ }}+ />+ <Progress+ value={fakeValue}+ transitionDuration="500ms"+ onTransitionEnd={() => {+ if (value === 100) {+ setIsDone(true);+ }}}/>- <Progress value={fakeValue} /></Flex>);};diff --git a/packages/design-system/src/components/progress.tsx b/packages/design-system/src/components/progress.tsxindex 813864410b..a6c502107f 100644--- a/packages/design-system/src/components/progress.tsx+++ b/packages/design-system/src/components/progress.tsx@@ -1,5 +1,6 @@import { Root, Indicator } from "@radix-ui/react-progress";import { css, theme } from "../stitches.config";+import type { TransitionEventHandler } from "react";const rootStyle = css({width: 200,@@ -14,16 +15,18 @@ const indicatorStyle = css({width: "100%",height: "100%",background: theme.colors.brandBorderNavbar,- transitionDuration: "1000ms",+ transitionDuration: "200ms",transitionProperty: "transform",});export const Progress = ({value,transitionDuration,+ onTransitionEnd,}: {value: number;transitionDuration?: string;+ onTransitionEnd?: TransitionEventHandler;}) => {return (<Root value={value} className={rootStyle()}>@@ -33,6 +36,7 @@ export const Progress = ({transform: `translateX(-${100 - value}%)`,transitionDuration,}}+ onTransitionEnd={onTransitionEnd}/></Root>);