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
feat: Preload page font and background-image assets (#2932)
Ivan Starkov979d0fa5d90d
diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.jsonindex f9296feb82..db611b8fd1 100644--- a/fixtures/webstudio-custom-template/.webstudio/data.json+++ b/fixtures/webstudio-custom-template/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "5eb1ac93-67ea-45e9-86a7-152a34d5dab6",+ "id": "0c1fd955-ccd4-45cc-b62d-c12777f2c28b","projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",- "version": 113,- "createdAt": "2024-02-07T18:05:33.222Z",- "updatedAt": "2024-02-07T18:05:33.222Z",+ "version": 125,+ "createdAt": "2024-02-22T06:28:11.305Z",+ "updatedAt": "2024-02-22T06:28:11.305Z","pages": {"meta": {"siteName": "Fixture Site",@@ -203,6 +203,224 @@"value": 15}}+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:fontFamily:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "fontFamily",+ "value": {+ "type": "fontFamily",+ "value": ["Cormorant Garamond"]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundAttachment:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundAttachment",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "scroll"+ },+ {+ "type": "keyword",+ "value": "scroll"+ },+ {+ "type": "keyword",+ "value": "scroll"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundClip:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundClip",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "border-box"+ },+ {+ "type": "keyword",+ "value": "border-box"+ },+ {+ "type": "keyword",+ "value": "border-box"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundBlendMode:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundBlendMode",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "normal"+ },+ {+ "type": "keyword",+ "value": "normal"+ },+ {+ "type": "keyword",+ "value": "normal"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundImage:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundImage",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "unparsed",+ "value": "linear-gradient(rgba(255,0,0,0.2),rgba(0,255,255,0.2))"+ },+ {+ "type": "image",+ "value": {+ "type": "asset",+ "value": "cd1e9fad-8df1-45c6-800f-05fda2d2469f"+ }+ },+ {+ "type": "unparsed",+ "value": "linear-gradient(to right,rgba(255,0,255,0.2),rgba(0,255,0,0.2))"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundOrigin:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundOrigin",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "padding-box"+ },+ {+ "type": "keyword",+ "value": "padding-box"+ },+ {+ "type": "keyword",+ "value": "padding-box"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundPosition:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundPosition",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "unit",+ "value": 0,+ "unit": "%"+ },+ {+ "type": "unit",+ "value": 0,+ "unit": "%"+ },+ {+ "type": "unit",+ "value": 0,+ "unit": "%"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundRepeat:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundRepeat",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "repeat"+ },+ {+ "type": "keyword",+ "value": "repeat"+ },+ {+ "type": "keyword",+ "value": "repeat"+ }+ ]+ }+ }+ ],+ [+ "NfeivFkbA_acBLVg7dn9P:mIDIDBHsdlix3RVZAVmv7:backgroundSize:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "NfeivFkbA_acBLVg7dn9P",+ "property": "backgroundSize",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "auto"+ },+ {+ "type": "keyword",+ "value": "auto"+ },+ {+ "type": "keyword",+ "value": "auto"+ }+ ]+ }+ }]],"styleSources": [@@ -415,6 +633,21 @@}],"assets": [+ {+ "id": "a8fb692a-5970-4014-ad4d-45c6f1edea36",+ "name": "CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2",+ "description": null,+ "projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",+ "size": 156212,+ "type": "font",+ "createdAt": "2024-02-22T05:36:52.004Z",+ "format": "woff2",+ "meta": {+ "family": "Cormorant Garamond",+ "style": "normal",+ "weight": 500+ }+ },{"id": "cd1e9fad-8df1-45c6-800f-05fda2d2469f","name": "home_wsKvRSqvkajPPBeycZ-C8.svg",diff --git a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsxindex ae2f7420e6..8752bbaea0 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import {@@ -12,7 +17,6 @@ import {import { Heading as Heading } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",@@ -26,6 +30,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 16, height: 16 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "Fixture Site",diff --git a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].tsindex 5f65ed8058..2a308ddd2d 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts+++ b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts@@ -2,11 +2,11 @@ export const sitemap = {pages: [{path: "",- lastModified: "2024-02-07T18:05:33.222Z",+ lastModified: "2024-02-22T06:28:11.305Z",},{path: "/script-test",- lastModified: "2024-02-07T18:05:33.222Z",+ lastModified: "2024-02-22T06:28:11.305Z",},],};diff --git a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx b/fixtures/webstudio-custom-template/app/__generated__/_index.tsxindex bf8de4d47e..965e2bd7f7 100644--- a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/_index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import {@@ -12,7 +17,6 @@ import {import { Heading as Heading } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",@@ -26,6 +30,36 @@ export const imageAssets: ImageAsset[] = [meta: { width: 16, height: 16 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [+ {+ id: "a8fb692a-5970-4014-ad4d-45c6f1edea36",+ name: "CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2",+ description: null,+ projectId: "0d856812-61d8-4014-a20a-82e01c0eb8ee",+ size: 156212,+ type: "font",+ createdAt: "2024-02-22T05:36:52.004Z",+ format: "woff2",+ meta: { family: "Cormorant Garamond", style: "normal", weight: 500 },+ },+];++export const pageBackgroundImageAssets: ImageAsset[] = [+ {+ id: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",+ name: "home_wsKvRSqvkajPPBeycZ-C8.svg",+ description: null,+ projectId: "0d856812-61d8-4014-a20a-82e01c0eb8ee",+ size: 3350,+ type: "image",+ format: "svg",+ createdAt: "2023-10-30T20:35:47.113Z",+ meta: { width: 16, height: 16 },+ },+];+export const pageData: PageData = {project: {siteName: "Fixture Site",@@ -67,7 +101,7 @@ const Page = ({}: { params: any }) => {<Headingdata-ws-id="7pwqBSgrfuuOfk1JblWcL"data-ws-component="Heading"- className="c11x2bo2"+ className="c11x2bo2 cykwawo c1qmshyz c12wnxll c1hzshzo c136ve95 cyttr60 c1cywb85 c187ui6a c1azrtl7">{"DO NOT TOUCH THIS PROJECT, IT'S USED FOR FIXTURES"}</Heading>diff --git a/fixtures/webstudio-custom-template/app/__generated__/index.css b/fixtures/webstudio-custom-template/app/__generated__/index.cssindex c2311061c0..30c11f4a3c 100644--- a/fixtures/webstudio-custom-template/app/__generated__/index.css+++ b/fixtures/webstudio-custom-template/app/__generated__/index.css@@ -1,3 +1,11 @@+@font-face {+ font-family: "Cormorant Garamond";+ font-style: normal;+ font-weight: 500;+ font-display: swap;+ src: url("/custom-folder/CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2")+ format("woff2");+}html {margin: 0;display: grid;@@ -83,6 +91,38 @@ html {.c11x2bo2 {font-size: 4em;}+ .cykwawo {+ font-family: "Cormorant Garamond", sans-serif;+ }+ .c1qmshyz {+ background-attachment: scroll, scroll, scroll;+ }+ .c12wnxll {+ -webkit-background-clip: border-box, border-box, border-box;+ }+ .c1hzshzo {+ background-blend-mode: normal, normal, normal;+ }+ .c136ve95 {+ background-image: linear-gradient(+ rgba(255, 0, 0, 0.2),+ rgba(0, 255, 255, 0.2)+ ),+ url("/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg"),+ linear-gradient(to right, rgba(255, 0, 255, 0.2), rgba(0, 255, 0, 0.2));+ }+ .cyttr60 {+ background-origin: padding-box, padding-box, padding-box;+ }+ .c1cywb85 {+ background-position: 0%, 0%, 0%;+ }+ .c187ui6a {+ background-repeat: repeat, repeat, repeat;+ }+ .c1azrtl7 {+ background-size: auto, auto, auto;+ }.c1vynykc {margin-top: 15px;}diff --git a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsxindex cc1b032ad0..588ab41812 100644--- a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx@@ -6,13 +6,13 @@ import {type ActionArgs,type LoaderArgs,json,+ redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";-import type { Page as PageType, ProjectMeta } from "@webstudio-is/sdk";+import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -21,6 +21,9 @@ import {Page,imageAssets,getRemixParams,+ getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[script-test]._index";import { loadResources } from "../__generated__/[script-test]._index.server";import css from "../__generated__/index.css";@@ -33,6 +36,15 @@ export type PageData = {export const loader = async (arg: LoaderArgs) => {const params = getRemixParams(arg.params);const resources = await loadResources({ params });+ const pageMeta = getPageMeta({ params, resources });++ if (pageMeta.redirect) {+ const status =+ pageMeta.status === 301 || pageMeta.status === 302+ ? pageMeta.status+ : 302;+ return redirect(pageMeta.redirect, status);+ }const host =arg.request.headers.get("x-forwarded-host") ||@@ -53,10 +65,14 @@ export const loader = async (arg: LoaderArgs) => {excludeFromSearch: arg.context.EXCLUDE_FROM_SEARCH,params,resources,+ pageMeta,},// No way for current information to change, so add cache for 10 minutes// In case of CRM Data, this should be set to 0- { headers: { "Cache-Control": "public, max-age=600" } }+ {+ status: pageMeta.status,+ headers: { "Cache-Control": "public, max-age=600" },+ });};@@ -66,6 +82,94 @@ export const headers = () => {};};+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];+ if (data === undefined) {+ return metas;+ }+ const { pageMeta } = data;+ const { project } = pageData;++ if (data.url) {+ metas.push({+ property: "og:url",+ content: data.url,+ });+ }++ if (pageMeta.title) {+ metas.push({ title: pageMeta.title });++ metas.push({+ property: "og:title",+ content: pageMeta.title,+ });+ }++ metas.push({ property: "og:type", content: "website" });++ const origin = `https://${data.host}`;++ if (project?.siteName) {+ metas.push({+ property: "og:site_name",+ content: project.siteName,+ });+ metas.push({+ "script:ld+json": {+ "@context": "https://schema.org",+ "@type": "WebSite",+ name: project.siteName,+ url: origin,+ },+ });+ }++ if (pageMeta.excludePageFromSearch || data.excludeFromSearch) {+ metas.push({+ name: "robots",+ content: "noindex, nofollow",+ });+ }++ if (pageMeta.description) {+ metas.push({+ name: "description",+ content: pageMeta.description,+ });+ metas.push({+ property: "og:description",+ content: pageMeta.description,+ });+ }++ if (pageMeta.socialImageAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === pageMeta.socialImageAssetId+ );++ if (imageAsset) {+ metas.push({+ property: "og:image",+ content: `https://${data.host}${imageLoader({+ src: imageAsset.name,+ // Do not transform social image (not enough information do we need to do this)+ format: "raw",+ })}`,+ });+ }+ } else if (pageMeta.socialImageUrl) {+ metas.push({+ property: "og:image",+ content: pageMeta.socialImageUrl,+ });+ }++ metas.push(...pageMeta.custom);++ return metas;+};+export const links: LinksFunction = () => {const result: LinkDescriptor[] = [];@@ -73,6 +177,59 @@ export const links: LinksFunction = () => {rel: "stylesheet",href: css,});++ const { project } = pageData;++ if (project?.faviconAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === project.faviconAssetId+ );++ if (imageAsset) {+ result.push({+ rel: "icon",+ href: imageLoader({+ src: imageAsset.name,+ width: 128,+ quality: 100,+ format: "auto",+ }),+ type: undefined,+ });+ }+ } else {+ result.push({+ rel: "icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });++ result.push({+ rel: "shortcut icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });+ }++ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });+ }+return result;};diff --git a/fixtures/webstudio-custom-template/app/routes/_index.tsx b/fixtures/webstudio-custom-template/app/routes/_index.tsxindex 38468dec53..705dbbe5ff 100644--- a/fixtures/webstudio-custom-template/app/routes/_index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/_index.tsx@@ -6,13 +6,13 @@ import {type ActionArgs,type LoaderArgs,json,+ redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";-import type { Page as PageType, ProjectMeta } from "@webstudio-is/sdk";+import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -21,6 +21,9 @@ import {Page,imageAssets,getRemixParams,+ getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/_index";import { loadResources } from "../__generated__/_index.server";import css from "../__generated__/index.css";@@ -33,6 +36,15 @@ export type PageData = {export const loader = async (arg: LoaderArgs) => {const params = getRemixParams(arg.params);const resources = await loadResources({ params });+ const pageMeta = getPageMeta({ params, resources });++ if (pageMeta.redirect) {+ const status =+ pageMeta.status === 301 || pageMeta.status === 302+ ? pageMeta.status+ : 302;+ return redirect(pageMeta.redirect, status);+ }const host =arg.request.headers.get("x-forwarded-host") ||@@ -53,10 +65,14 @@ export const loader = async (arg: LoaderArgs) => {excludeFromSearch: arg.context.EXCLUDE_FROM_SEARCH,params,resources,+ pageMeta,},// No way for current information to change, so add cache for 10 minutes// In case of CRM Data, this should be set to 0- { headers: { "Cache-Control": "public, max-age=600" } }+ {+ status: pageMeta.status,+ headers: { "Cache-Control": "public, max-age=600" },+ });};@@ -66,6 +82,94 @@ export const headers = () => {};};+export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {+ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];+ if (data === undefined) {+ return metas;+ }+ const { pageMeta } = data;+ const { project } = pageData;++ if (data.url) {+ metas.push({+ property: "og:url",+ content: data.url,+ });+ }++ if (pageMeta.title) {+ metas.push({ title: pageMeta.title });++ metas.push({+ property: "og:title",+ content: pageMeta.title,+ });+ }++ metas.push({ property: "og:type", content: "website" });++ const origin = `https://${data.host}`;++ if (project?.siteName) {+ metas.push({+ property: "og:site_name",+ content: project.siteName,+ });+ metas.push({+ "script:ld+json": {+ "@context": "https://schema.org",+ "@type": "WebSite",+ name: project.siteName,+ url: origin,+ },+ });+ }++ if (pageMeta.excludePageFromSearch || data.excludeFromSearch) {+ metas.push({+ name: "robots",+ content: "noindex, nofollow",+ });+ }++ if (pageMeta.description) {+ metas.push({+ name: "description",+ content: pageMeta.description,+ });+ metas.push({+ property: "og:description",+ content: pageMeta.description,+ });+ }++ if (pageMeta.socialImageAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === pageMeta.socialImageAssetId+ );++ if (imageAsset) {+ metas.push({+ property: "og:image",+ content: `https://${data.host}${imageLoader({+ src: imageAsset.name,+ // Do not transform social image (not enough information do we need to do this)+ format: "raw",+ })}`,+ });+ }+ } else if (pageMeta.socialImageUrl) {+ metas.push({+ property: "og:image",+ content: pageMeta.socialImageUrl,+ });+ }++ metas.push(...pageMeta.custom);++ return metas;+};+export const links: LinksFunction = () => {const result: LinkDescriptor[] = [];@@ -73,6 +177,59 @@ export const links: LinksFunction = () => {rel: "stylesheet",href: css,});++ const { project } = pageData;++ if (project?.faviconAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === project.faviconAssetId+ );++ if (imageAsset) {+ result.push({+ rel: "icon",+ href: imageLoader({+ src: imageAsset.name,+ width: 128,+ quality: 100,+ format: "auto",+ }),+ type: undefined,+ });+ }+ } else {+ result.push({+ rel: "icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });++ result.push({+ rel: "shortcut icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });+ }++ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });+ }+return result;};diff --git a/fixtures/webstudio-custom-template/custom-template/__templates__/route-template.tsx b/fixtures/webstudio-custom-template/custom-template/__templates__/route-template.tsxdeleted file mode 100644index 18fd594694..0000000000--- a/fixtures/webstudio-custom-template/custom-template/__templates__/route-template.tsx+++ /dev/null@@ -1,176 +0,0 @@-/* eslint-disable camelcase */-import {- type V2_ServerRuntimeMetaFunction,- type LinksFunction,- type LinkDescriptor,- type ActionArgs,- type LoaderArgs,- json,-} from "@remix-run/server-runtime";-import { useLoaderData } from "@remix-run/react";-import type { Page as PageType, ProjectMeta } from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";-import {- fontAssets,- pageData,- user,- projectId,- pagesPaths,- formsProperties,- Page,- imageAssets,- getRemixParams,-} from "../../app/__generated__/_index";-import { loadResources } from "../../app/__generated__/_index.server";-import css from "../__generated__/index.css";-import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";--export type PageData = {- project?: ProjectMeta;-};--export const loader = async (arg: LoaderArgs) => {- const params = getRemixParams(arg.params);- const resources = await loadResources({ params });-- const host =- arg.request.headers.get("x-forwarded-host") ||- arg.request.headers.get("host") ||- "";-- const url = new URL(arg.request.url);- url.host = host;- url.protocol = "https";-- // typecheck- arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;-- return json(- {- host,- url: url.href,- excludeFromSearch: arg.context.EXCLUDE_FROM_SEARCH,- params,- resources,- },- // No way for current information to change, so add cache for 10 minutes- // In case of CRM Data, this should be set to 0- { headers: { "Cache-Control": "public, max-age=600" } }- );-};--export const headers = () => {- return {- "Cache-Control": "public, max-age=0, must-revalidate",- };-};--export const links: LinksFunction = () => {- const result: LinkDescriptor[] = [];-- result.push({- rel: "stylesheet",- href: css,- });- return result;-};--const getRequestHost = (request: Request): string =>- request.headers.get("x-forwarded-host") || request.headers.get("host") || "";--const getMethod = (value: string | undefined) => {- if (value === undefined) {- return "post";- }-- switch (value.toLowerCase()) {- case "get":- return "get";- default:- return "post";- }-};--export const action = async ({ request, context }: ActionArgs) => {- const formData = await request.formData();-- const formId = getFormId(formData);- if (formId === undefined) {- // We're throwing rather than returning { success: false }- // because this isn't supposed to happen normally: bug or malicious user- throw json("Form not found", { status: 404 });- }-- const formProperties = formsProperties.get(formId);-- // form properties are not defined when defaults are used- const { action, method } = formProperties ?? {};-- const email = user?.email;-- if (email == null) {- return { success: false };- }-- // wrapped in try/catch just in cases new URL() throws- // (should not happen)- let pageUrl: URL;- try {- pageUrl = new URL(request.url);- pageUrl.host = getRequestHost(request);- } catch {- return { success: false };- }-- if (action !== undefined) {- try {- // Test that action is full URL- new URL(action);- } catch {- return json(- {- success: false,- error: "Invalid action URL, must be valid http/https protocol",- },- { status: 200 }- );- }- }-- const formInfo = {- formData,- projectId,- action: action ?? null,- method: getMethod(method),- pageUrl: pageUrl.toString(),- toEmail: email,- fromEmail: pageUrl.hostname + "@webstudio.email",- } as const;-- const result = await n8nHandler({- formInfo,- hookUrl: context.N8N_FORM_EMAIL_HOOK,- });-- return result;-};--const Outlet = () => {- const { params, resources } = useLoaderData<typeof loader>();- return (- <ReactSdkContext.Provider- value={{- imageLoader,- assetBaseUrl,- imageBaseUrl,- pagesPaths,- resources,- }}- >- <Page params={params} />- </ReactSdkContext.Provider>- );-};--export default Outlet;diff --git a/fixtures/webstudio-custom-template/public/custom-folder/CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2 b/fixtures/webstudio-custom-template/public/custom-folder/CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2new file mode 100644index 0000000000..e7f98ba27fBinary files /dev/null and b/fixtures/webstudio-custom-template/public/custom-folder/CormorantGaramond-Medium_-nWJ-OtHncaW9xDHQ9hSA_CBl88Oo59QKH_z9pCWva2.woff2 differdiff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsxindex 429dda32b3..6ad1f974e6 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";@@ -12,8 +17,13 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: { siteName: "", faviconAssetId: "", code: "" },};diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsxindex 9c7c675a4a..705dbbe5ff 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/_index";import { loadResources } from "../__generated__/_index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsxindex 429dda32b3..6ad1f974e6 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";@@ -12,8 +17,13 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: { siteName: "", faviconAssetId: "", code: "" },};diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsxindex 9c7c675a4a..705dbbe5ff 100644--- a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/_index";import { loadResources } from "../__generated__/_index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsxindex 97dab0e457..3cba96c094 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx@@ -2,14 +2,18 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";import { Image as Image } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -45,6 +49,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsxindex af8029282c..76e792a785 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import {@@ -18,7 +23,6 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -54,6 +58,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsxindex 5354900b4a..faf22e14cc 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.tsx@@ -2,14 +2,18 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";import { Heading as Heading } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -45,6 +49,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.tsxindex efd15b511e..65674c847e 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.tsx@@ -2,14 +2,18 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";import { Heading as Heading } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -45,6 +49,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsxindex b8103dc4d0..06bbf238bb 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";@@ -20,7 +25,6 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -56,6 +60,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.tsxindex 0edd481245..29583a3d02 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import { Body as Body } from "@webstudio-is/sdk-components-react-remix";@@ -12,7 +17,6 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -48,6 +52,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsxindex f775349027..dab58ff5fb 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx@@ -2,7 +2,12 @@/* This is a auto generated file for building the project */import { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type {+ Asset,+ FontAsset,+ ImageAsset,+ ProjectMeta,+} from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";import {@@ -18,7 +23,6 @@ import {} from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [{id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",@@ -54,6 +58,12 @@ export const imageAssets: ImageAsset[] = [meta: { width: 1024, height: 1024 },},];++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = [];++export const pageBackgroundImageAssets: ImageAsset[] = [];+export const pageData: PageData = {project: {siteName: "KittyGuardedZone",diff --git a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsxindex c0d90ad167..8f6ef7af2e 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[_route_with_symbols_]._index";import { loadResources } from "../__generated__/[_route_with_symbols_]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsxindex 1301281d9c..627a1e2b5d 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[form]._index";import { loadResources } from "../__generated__/[form]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsxindex b8fa6e7080..6db7a9440d 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[heading-with-id]._index";import { loadResources } from "../__generated__/[heading-with-id]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsxindex a8c7aad728..6d560615f1 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[nested].[nested-page]._index";import { loadResources } from "../__generated__/[nested].[nested-page]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsxindex 5321c74663..a1b082a120 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[radix]._index";import { loadResources } from "../__generated__/[radix]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsxindex b6893d0c8c..dea3a0ccc0 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/[resources]._index";import { loadResources } from "../__generated__/[resources]._index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx b/fixtures/webstudio-remix-vercel/app/routes/_index.tsxindex 9c7c675a4a..705dbbe5ff 100644--- a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../__generated__/_index";import { loadResources } from "../__generated__/_index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;diff --git a/packages/cli/__generated__/_index.tsx b/packages/cli/__generated__/_index.tsxindex 283b5cabf6..dbb9fa0565 100644--- a/packages/cli/__generated__/_index.tsx+++ b/packages/cli/__generated__/_index.tsx@@ -1,11 +1,10 @@/*** The only intent of this file is to support typings inside ../templates/route-template for easier development.**/-import type { Asset, ImageAsset } from "@webstudio-is/sdk";+import type { ImageAsset, FontAsset } from "@webstudio-is/sdk";import type { PageData } from "../templates/defaults/__templates__/route-template";import type { PageMeta } from "@webstudio-is/react-sdk";-export const fontAssets: Asset[] = [];export const imageAssets: ImageAsset[] = [];export const pageData: PageData = {@@ -48,3 +47,6 @@ export const formsProperties = new Map<string,{ method?: string; action?: string }>([]);++export const pageFontAssets: FontAsset[] = [];+export const pageBackgroundImageAssets: ImageAsset[] = [];diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.tsindex 450eff7ae9..735afae25f 100644--- a/packages/cli/src/prebuild.ts+++ b/packages/cli/src/prebuild.ts@@ -295,6 +295,8 @@ export const prebuild = async (options: {const projectMetas = new Map<Instance["component"], WsComponentMeta>();const componentsByPage: ComponentsByPage = {};const siteDataByPage: SiteDataByPage = {};+ const fontAssetsByPage: Record<Page["id"], FontAsset[]> = {};+ const backgroundImageAssetsByPage: Record<Page["id"], ImageAsset[]> = {};for (const page of Object.values(siteData.pages)) {const instanceMap = new Map(siteData.build.instances);@@ -364,10 +366,65 @@ export const prebuild = async (options: {projectMetas.set(instance.component, meta);}}++ // Extract background SVGs and Font assets+ const styleSourceSelections = siteData.build?.styleSourceSelections ?? [];+ const pageStyleSourceIds = new Set(+ styleSourceSelections+ .filter(([, { instanceId }]) => pageInstanceSet.has(instanceId))+ .map(([, { values }]) => values)+ .flat()+ );++ const pageStyles = siteData.build?.styles?.filter(([, { styleSourceId }]) =>+ pageStyleSourceIds.has(styleSourceId)+ );++ // Extract fonts+ const pageFontFamilySet = new Set(+ pageStyles+ .filter(([, { property }]) => property === "fontFamily")+ .map(([, { value }]) =>+ value.type === "fontFamily" ? value.value : undefined+ )+ .flat()+ .filter(<T>(value: T): value is NonNullable<T> => value !== undefined)+ );++ const pageFontAssets = siteData.assets+ .filter((asset): asset is FontAsset => asset.type === "font")+ .filter((fontAsset) => pageFontFamilySet.has(fontAsset.meta.family));++ fontAssetsByPage[page.id] = pageFontAssets;++ // Extract background images+ // backgroundImage => "value.type=="layers" => value.type == "image" => .value (assetId)+ const backgroundImageAssetIdSet = new Set(+ pageStyles+ .filter(([, { property }]) => property === "backgroundImage")+ .map(([, { value }]) =>+ value.type === "layers"+ ? value.value.map((layer) =>+ layer.type === "image"+ ? layer.value.type === "asset"+ ? layer.value.value+ : undefined+ : undefined+ )+ : undefined+ )+ .flat()+ .filter(<T>(value: T): value is NonNullable<T> => value !== undefined)+ );++ const backgroundImageAssets = siteData.assets+ .filter((asset): asset is ImageAsset => asset.type === "image")+ .filter((imageAsset) => backgroundImageAssetIdSet.has(imageAsset.id));++ backgroundImageAssetsByPage[page.id] = backgroundImageAssets;}const assetsToDownload: Promise<void>[] = [];- const fontAssets: FontAsset[] = [];const imageAssets: ImageAsset[] = [];for (const asset of siteData.assets) {@@ -406,7 +463,6 @@ export const prebuild = async (options: {)));- fontAssets.push(asset);}}}@@ -500,6 +556,8 @@ export const prebuild = async (options: {}const pageData = siteDataByPage[pageId];+ const pageFontAssets = fontAssetsByPage[pageId];+ const pageBackgroundImageAssets = backgroundImageAssetsByPage[pageId];// serialize data only used in runtimeconst renderedPageData: PageData = {project: siteData.build.pages.meta,@@ -552,13 +610,20 @@ export const prebuild = async (options: {const pageExports = `/* eslint-disable *//* This is a auto generated file for building the project */ \nimport { Fragment, useState } from "react";-import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import type { Asset, FontAsset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";import type { PageMeta } from "@webstudio-is/react-sdk";${componentImports}import type { PageData } from "~/routes/_index";-export const fontAssets: Asset[] = ${JSON.stringify(fontAssets)}export const imageAssets: ImageAsset[] = ${JSON.stringify(imageAssets)}++// Font assets on current page (can be preloaded)+export const pageFontAssets: FontAsset[] = ${JSON.stringify(pageFontAssets)}++export const pageBackgroundImageAssets: ImageAsset[] = ${JSON.stringify(+ pageBackgroundImageAssets+ )}+export const pageData: PageData = ${JSON.stringify(renderedPageData)};export const user: { email: string | null } | undefined = ${JSON.stringify(siteData.userdiff --git a/packages/cli/templates/defaults/__templates__/route-template.tsx b/packages/cli/templates/defaults/__templates__/route-template.tsxindex b091d41667..304f35b33e 100644--- a/packages/cli/templates/defaults/__templates__/route-template.tsx+++ b/packages/cli/templates/defaults/__templates__/route-template.tsx@@ -13,7 +13,6 @@ import type { ProjectMeta } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";import {- fontAssets,pageData,user,projectId,@@ -23,6 +22,8 @@ import {imageAssets,getRemixParams,getPageMeta,+ pageFontAssets,+ pageBackgroundImageAssets,} from "../../../__generated__/_index";import { loadResources } from "../../../__generated__/_index.server";import css from "../__generated__/index.css";@@ -210,17 +211,23 @@ export const links: LinksFunction = () => {});}- for (const asset of fontAssets) {- if (asset.type === "font") {- result.push({- rel: "preload",- href: assetBaseUrl + asset.name,- as: "font",- crossOrigin: "anonymous",- // @todo add mimeType- // type: asset.mimeType,- });- }+ for (const asset of pageFontAssets) {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ });+ }++ for (const backgroundImageAsset of pageBackgroundImageAssets) {+ result.push({+ rel: "preload",+ href: imageLoader({+ src: backgroundImageAsset.name,+ format: "raw",+ }),+ as: "image",+ });}return result;