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
chore: Add prefetch dns, add loading indicator to dashboard (#4051)
Ivan Starkov56985b70b378
diff --git a/apps/builder/app/dashboard/projects/project-card.tsx b/apps/builder/app/dashboard/projects/project-card.tsxindex 1c3aa4eea3..73b1d2a754 100644--- a/apps/builder/app/dashboard/projects/project-card.tsx+++ b/apps/builder/app/dashboard/projects/project-card.tsx@@ -15,7 +15,7 @@ import {Link,} from "@webstudio-is/design-system";import { InfoCircleIcon, EllipsesIcon } from "@webstudio-is/icons";-import { type KeyboardEvent, useRef, useState } from "react";+import { type KeyboardEvent, useEffect, useRef, useState } from "react";import type { ImageLoader } from "@webstudio-is/image";import { builderUrl } from "~/shared/router-utils";import {@@ -30,7 +30,6 @@ import {ThumbnailWithAbbr,ThumbnailWithImage,} from "./thumbnail";-import { useNavigation } from "@remix-run/react";import { Spinner } from "../shared/spinner";import type { DashboardProject } from "@webstudio-is/dashboard";import { Card, CardContent, CardFooter } from "../shared/card";@@ -180,11 +179,30 @@ export const ProjectCard = ({const [isHidden, setIsHidden] = useState(false);const { thumbnailRef, handleKeyDown } = useProjectCard();const handleCloneProject = useCloneProject(id);- const { state, location } = useNavigation();+ const [isTransitioning, setIsTransitioning] = useState(false);++ useEffect(() => {+ const linkPath = builderUrl({ origin: window.origin, projectId: id });++ const handleNavigate = (event: NavigateEvent) => {+ if (event.destination.url === linkPath) {+ setIsTransitioning(true);+ }+ };++ if (window.navigation === undefined) {+ return;+ }++ window.navigation.addEventListener("navigate", handleNavigate);++ return () => {+ window.navigation.removeEventListener("navigate", handleNavigate);+ };+ }, [id]);const linkPath = builderUrl({ origin: window.origin, projectId: id });- // Transition to the project has started, we may need to show a spinner- const isTransitioning = state !== "idle" && linkPath === location.pathname;+return (<Card hidden={isHidden} tabIndex={0} onKeyDown={handleKeyDown}><CardContentdiff --git a/apps/builder/app/dashboard/projects/thumbnail.tsx b/apps/builder/app/dashboard/projects/thumbnail.tsxindex 4a5bd83e25..3835a48256 100644--- a/apps/builder/app/dashboard/projects/thumbnail.tsx+++ b/apps/builder/app/dashboard/projects/thumbnail.tsx@@ -1,5 +1,4 @@import { forwardRef } from "react";-import { Link } from "@remix-run/react";import { Image, type ImageLoader } from "@webstudio-is/image";import { css, theme, textVariants } from "@webstudio-is/design-system";@@ -32,9 +31,9 @@ export const ThumbnailLinkWithAbbr = forwardRef<{ title: string; to: string }>(({ title, to }, ref) => {return (- <Link ref={ref} to={to} className={abbrStyle()} tabIndex={-1}>+ <a ref={ref} href={to} className={abbrStyle()} tabIndex={-1}>{getThumbnailAbbreviation(title)}- </Link>+ </a>);});ThumbnailLinkWithAbbr.displayName = "ThumbnailLinkWithAbbr";@@ -76,9 +75,9 @@ export const ThumbnailLinkWithImage = forwardRef<{ name: string; to: string; imageLoader: ImageLoader }>(({ name, to, imageLoader }, ref) => {return (- <Link ref={ref} to={to} className={imageContainerStyle()} tabIndex={-1}>+ <a ref={ref} href={to} className={imageContainerStyle()} tabIndex={-1}><Image src={name} loader={imageLoader} className={imageStyle()} />- </Link>+ </a>);});ThumbnailLinkWithImage.displayName = "ThumbnailLinkWithImage";diff --git a/apps/builder/app/routes/_ui.dashboard.tsx b/apps/builder/app/routes/_ui.dashboard.tsxindex 0f05b423ce..896d236bd3 100644--- a/apps/builder/app/routes/_ui.dashboard.tsx+++ b/apps/builder/app/routes/_ui.dashboard.tsx@@ -3,13 +3,15 @@ import { useLoaderData, type MetaFunction } from "@remix-run/react";import { json, type LoaderFunctionArgs } from "@remix-run/server-runtime";import { dashboardProjectRouter } from "@webstudio-is/dashboard/index.server";import { findAuthenticatedUser } from "~/services/auth.server";-import { isDashboard, loginPath } from "~/shared/router-utils";+import { builderUrl, isDashboard, loginPath } from "~/shared/router-utils";import { createContext } from "~/shared/context.server";import env from "~/env/env.server";import { ClientOnly } from "~/shared/client-only";import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";import { createCallerFactory } from "@webstudio-is/trpc-interface/index.server";import { redirect } from "~/services/no-store-redirect";+import { prefetchDNS } from "react-dom";+import { parseBuilderUrl } from "@webstudio-is/http-client";const dashboardProjectCaller = createCallerFactory(dashboardProjectRouter);@@ -58,6 +60,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {throw new Error("User plan features are not defined");}+ const { sourceOrigin } = parseBuilderUrl(request.url);+return json({user,projects,@@ -65,6 +69,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {userPlanFeatures,publisherHost: env.PUBLISHER_HOST,imageBaseUrl: env.IMAGE_BASE_URL,+ origin: sourceOrigin,});};@@ -90,9 +95,14 @@ const DashboardRoute = () => {const data = useLoaderData<typeof loader>();return (- <ClientOnly>- <Dashboard {...data} />- </ClientOnly>+ <>+ {data.projects.map((project) => {+ prefetchDNS(builderUrl({ projectId: project.id, origin: data.origin }));+ })}+ <ClientOnly>+ <Dashboard {...data} />+ </ClientOnly>+ </>);};diff --git a/apps/builder/package.json b/apps/builder/package.jsonindex 3be29966ac..095b426f47 100644--- a/apps/builder/package.json+++ b/apps/builder/package.json@@ -128,6 +128,7 @@"@testing-library/react-hooks": "^8.0.1","@types/cookie": "^0.6.0","@types/debug": "^4.1.12",+ "@types/dom-navigation": "^1.0.3","@types/prismjs": "^1.26.0","@types/react": "^18.2.70","@types/react-dom": "^18.2.25",diff --git a/apps/builder/tsconfig.json b/apps/builder/tsconfig.jsonindex b89dccd766..0dcd9e22e2 100644--- a/apps/builder/tsconfig.json+++ b/apps/builder/tsconfig.json@@ -3,7 +3,14 @@"include": ["app", "**/*.ts", "**/*.tsx", "../../@types/**/*.d.ts"],"compilerOptions": {- "types": ["@remix-run/node", "vite/client", "react/canary"],+ "types": [+ "@remix-run/node",+ "vite/client",+ "react/canary",+ "react-dom/canary",+ "@types/dom-navigation"+ ],+"paths": {"~/*": ["app/*"]},diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b52d569a4b..4090e86bd9 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -452,6 +452,9 @@ importers:'@types/debug':specifier: ^4.1.12version: 4.1.12+ '@types/dom-navigation':+ specifier: ^1.0.3+ version: 1.0.3'@types/prismjs':specifier: ^1.26.0version: 1.26.0@@ -5242,6 +5245,9 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-eOIHzCUSH7SMfonMG1LsC2f8vxBFtho6NGBznK41R84YzPuvSBzrhEps33IsQiOW9+VL6NQ9DbjQJznk/S4uRA==}+ '@types/[email protected]':+ resolution: {integrity: sha512-nbkhQ2o6UUBn1uLwSrA//rFkqs8XRk5d7cE6jzzTl8MAIUs/nFMtFqVESwiYY1HGZxflzbFlXsZ8NNzTaoFs1Q==}+'@types/[email protected]':resolution: {integrity: sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg==}@@ -13399,6 +13405,8 @@ snapshots:'@types/[email protected]': {}+ '@types/[email protected]': {}+'@types/[email protected]': {}'@types/[email protected]': {}