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
refactor: decouple resource loader from generated requests (#3798)
Bogdan Chadkin34ae0411db59
diff --git a/fixtures/ssg/.webstudio/data.json b/fixtures/ssg/.webstudio/data.jsonindex 41f94ebc32..ccea62eda4 100644--- a/fixtures/ssg/.webstudio/data.json+++ b/fixtures/ssg/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",+ "id": "2b8a9d28-3a0e-48c9-9aa2-b26db7926a22","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",- "version": 29,- "createdAt": "2024-07-21T11:48:14.097",- "updatedAt": "2024-07-21T11:48:14.097",+ "version": 33,+ "createdAt": "2024-07-26T13:42:42.816",+ "updatedAt": "2024-07-26T13:42:42.816","pages": {"meta": {"siteName": "",@@ -151,6 +151,19 @@"value": 1}}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg:rKj-wYctg3-GnqL3WHN9I:width:",+ {+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",+ "styleSourceId": "mf2C07UBmGT7y_G4Du3yg",+ "property": "width",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 400+ }+ }]],"styleSources": [@@ -167,6 +180,13 @@"type": "local","id": "0KA68BwP9gdTzE1ESO2Zp"}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg",+ {+ "type": "local",+ "id": "mf2C07UBmGT7y_G4Du3yg"+ }]],"styleSourceSelections": [@@ -183,6 +203,13 @@"instanceId": "BMJfjOzunWs8XkQgvvx1e","values": ["0KA68BwP9gdTzE1ESO2Zp"]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "values": ["mf2C07UBmGT7y_G4Du3yg"]+ }]],"props": [@@ -195,6 +222,36 @@"type": "page","value": "WPPAbLFyJD_02vhjRd8P4"}+ ],+ [+ "su3ag3OxH9WTBjJg5eIyg",+ {+ "id": "su3ag3OxH9WTBjJg5eIyg",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "src",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "vGCYpBBB1QUPIPPIdyexn",+ {+ "id": "vGCYpBBB1QUPIPPIdyexn",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "width",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "JKAGY7DWpciEl0UdnWuKL",+ {+ "id": "JKAGY7DWpciEl0UdnWuKL",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "height",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }]],"dataSources": [@@ -237,6 +294,10 @@{"type": "id","value": "pjkZo5EiBqaeUXBcyHf_O"+ },+ {+ "type": "id",+ "value": "uHB3Fjb7-NELG-bnH7bXB"}]}@@ -310,6 +371,15 @@}]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "type": "instance",+ "id": "uHB3Fjb7-NELG-bnH7bXB",+ "component": "Image",+ "children": []+ }]],"deployment": {@@ -364,7 +434,22 @@"path": "/another-page"}],- "assets": [],+ "assets": [+ {+ "id": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee",+ "name": "iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg",+ "description": null,+ "projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",+ "size": 999,+ "type": "image",+ "format": "svg",+ "createdAt": "2024-07-26T13:39:48.678Z",+ "meta": {+ "width": 14,+ "height": 16+ }+ }+ ],"user": {"email": "[email protected]"},diff --git a/fixtures/ssg/app/__generated__/$resources.sitemap.xml.ts b/fixtures/ssg/app/__generated__/$resources.sitemap.xml.tsindex af4f4e6a39..f8e2489bc3 100644--- a/fixtures/ssg/app/__generated__/$resources.sitemap.xml.ts+++ b/fixtures/ssg/app/__generated__/$resources.sitemap.xml.ts@@ -1,6 +1,6 @@export const sitemap = [{path: "/",- lastModified: "2024-07-21",+ lastModified: "2024-07-26",},];diff --git a/fixtures/ssg/app/__generated__/[another-page]._index.server.tsx b/fixtures/ssg/app/__generated__/[another-page]._index.server.tsxindex 134adccf84..7848d01d46 100644--- a/fixtures/ssg/app/__generated__/[another-page]._index.server.tsx+++ b/fixtures/ssg/app/__generated__/[another-page]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/ssg/app/__generated__/_index.server.tsx b/fixtures/ssg/app/__generated__/_index.server.tsxindex 38333a7aa9..ec7f6f9e62 100644--- a/fixtures/ssg/app/__generated__/_index.server.tsx+++ b/fixtures/ssg/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/ssg/app/__generated__/_index.tsx b/fixtures/ssg/app/__generated__/_index.tsxindex 1f0a3395d2..fccb8f013f 100644--- a/fixtures/ssg/app/__generated__/_index.tsx+++ b/fixtures/ssg/app/__generated__/_index.tsx@@ -9,6 +9,7 @@ import {Heading as Heading,Text as Text,Link as Link,+ Image as Image,} from "@webstudio-is/sdk-components-react";export const siteName = "";@@ -53,6 +54,14 @@ const Page = ({}: { system: any }) => {>{"Test another page link"}</Link>+ <Image+ data-ws-id="uHB3Fjb7-NELG-bnH7bXB"+ data-ws-component="Image"+ src={"/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg"}+ width={14}+ height={16}+ className="w-image c161qeci"+ /></Body>);};diff --git a/fixtures/ssg/app/__generated__/index.css b/fixtures/ssg/app/__generated__/index.cssindex bc9e936306..20fa46db3e 100644--- a/fixtures/ssg/app/__generated__/index.css+++ b/fixtures/ssg/app/__generated__/index.css@@ -84,6 +84,17 @@ html {min-height: 1em;display: inline-block;}+ :where(img.w-image) {+ box-sizing: border-box;+ border-top-width: 1px;+ border-right-width: 1px;+ border-bottom-width: 1px;+ border-left-width: 1px;+ outline-width: 1px;+ max-width: 100%;+ display: block;+ height: auto;+ }}@media all {.c1jaw2zx {@@ -101,4 +112,7 @@ html {.cn3rfux {margin-bottom: 1em;}+ .c161qeci {+ width: 400px;+ }}diff --git a/fixtures/ssg/pages/another-page/+data.ts b/fixtures/ssg/pages/another-page/+data.tsindex 06db8c4308..c2dbbe3f59 100644--- a/fixtures/ssg/pages/another-page/+data.ts+++ b/fixtures/ssg/pages/another-page/+data.ts@@ -1,8 +1,9 @@import type { PageContextServer } from "vike/types";import { redirect } from "vike/abort";+import { loadResources } from "@webstudio-is/sdk";import {getPageMeta,- loadResources,+ getResources,} from "../../app/__generated__/[another-page]._index.server";export const data = async (pageContext: PageContextServer) => {@@ -19,7 +20,7 @@ export const data = async (pageContext: PageContextServer) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(fetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/ssg/pages/index/+data.ts b/fixtures/ssg/pages/index/+data.tsindex fd6fce9dad..ea262488b3 100644--- a/fixtures/ssg/pages/index/+data.ts+++ b/fixtures/ssg/pages/index/+data.ts@@ -1,8 +1,9 @@import type { PageContextServer } from "vike/types";import { redirect } from "vike/abort";+import { loadResources } from "@webstudio-is/sdk";import {getPageMeta,- loadResources,+ getResources,} from "../../app/__generated__/_index.server";export const data = async (pageContext: PageContextServer) => {@@ -19,7 +20,7 @@ export const data = async (pageContext: PageContextServer) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(fetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/ssg/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg b/fixtures/ssg/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svgnew file mode 100644index 0000000000..bc70d3a453--- /dev/null+++ b/fixtures/ssg/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg@@ -0,0 +1 @@+<svg width="14" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m2.139 9.442-.007.088-.038-.105a5.451 5.451 0 0 0-.054-.142c-.01-.025.003-.045.039-.061.049-.022.054-.018.06.054a1.15 1.15 0 0 1 0 .166" fill-rule="evenodd"/></svg>\ No newline at end of filediff --git a/fixtures/webstudio-cloudflare-template/.webstudio/data.json b/fixtures/webstudio-cloudflare-template/.webstudio/data.jsonindex 41f94ebc32..ccea62eda4 100644--- a/fixtures/webstudio-cloudflare-template/.webstudio/data.json+++ b/fixtures/webstudio-cloudflare-template/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",+ "id": "2b8a9d28-3a0e-48c9-9aa2-b26db7926a22","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",- "version": 29,- "createdAt": "2024-07-21T11:48:14.097",- "updatedAt": "2024-07-21T11:48:14.097",+ "version": 33,+ "createdAt": "2024-07-26T13:42:42.816",+ "updatedAt": "2024-07-26T13:42:42.816","pages": {"meta": {"siteName": "",@@ -151,6 +151,19 @@"value": 1}}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg:rKj-wYctg3-GnqL3WHN9I:width:",+ {+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",+ "styleSourceId": "mf2C07UBmGT7y_G4Du3yg",+ "property": "width",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 400+ }+ }]],"styleSources": [@@ -167,6 +180,13 @@"type": "local","id": "0KA68BwP9gdTzE1ESO2Zp"}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg",+ {+ "type": "local",+ "id": "mf2C07UBmGT7y_G4Du3yg"+ }]],"styleSourceSelections": [@@ -183,6 +203,13 @@"instanceId": "BMJfjOzunWs8XkQgvvx1e","values": ["0KA68BwP9gdTzE1ESO2Zp"]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "values": ["mf2C07UBmGT7y_G4Du3yg"]+ }]],"props": [@@ -195,6 +222,36 @@"type": "page","value": "WPPAbLFyJD_02vhjRd8P4"}+ ],+ [+ "su3ag3OxH9WTBjJg5eIyg",+ {+ "id": "su3ag3OxH9WTBjJg5eIyg",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "src",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "vGCYpBBB1QUPIPPIdyexn",+ {+ "id": "vGCYpBBB1QUPIPPIdyexn",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "width",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "JKAGY7DWpciEl0UdnWuKL",+ {+ "id": "JKAGY7DWpciEl0UdnWuKL",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "height",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }]],"dataSources": [@@ -237,6 +294,10 @@{"type": "id","value": "pjkZo5EiBqaeUXBcyHf_O"+ },+ {+ "type": "id",+ "value": "uHB3Fjb7-NELG-bnH7bXB"}]}@@ -310,6 +371,15 @@}]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "type": "instance",+ "id": "uHB3Fjb7-NELG-bnH7bXB",+ "component": "Image",+ "children": []+ }]],"deployment": {@@ -364,7 +434,22 @@"path": "/another-page"}],- "assets": [],+ "assets": [+ {+ "id": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee",+ "name": "iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg",+ "description": null,+ "projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",+ "size": 999,+ "type": "image",+ "format": "svg",+ "createdAt": "2024-07-26T13:39:48.678Z",+ "meta": {+ "width": 14,+ "height": 16+ }+ }+ ],"user": {"email": "[email protected]"},diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.tsindex af4f4e6a39..f8e2489bc3 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts@@ -1,6 +1,6 @@export const sitemap = [{path: "/",- lastModified: "2024-07-21",+ lastModified: "2024-07-26",},];diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsxindex 134adccf84..7848d01d46 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.server.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.server.tsxindex 38333a7aa9..ec7f6f9e62 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.server.tsx+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsxindex b3f8b2e3ea..38fa1a51e4 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx@@ -11,6 +11,7 @@ import {import {Heading as Heading,Text as Text,+ Image as Image,} from "@webstudio-is/sdk-components-react";export const siteName = "";@@ -55,6 +56,14 @@ const Page = ({}: { system: any }) => {>{"Test another page link"}</Link>+ <Image+ data-ws-id="uHB3Fjb7-NELG-bnH7bXB"+ data-ws-component="Image"+ src={"/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg"}+ width={14}+ height={16}+ className="w-image c161qeci"+ /></Body>);};diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css b/fixtures/webstudio-cloudflare-template/app/__generated__/index.cssindex bc9e936306..20fa46db3e 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/index.css@@ -84,6 +84,17 @@ html {min-height: 1em;display: inline-block;}+ :where(img.w-image) {+ box-sizing: border-box;+ border-top-width: 1px;+ border-right-width: 1px;+ border-bottom-width: 1px;+ border-left-width: 1px;+ outline-width: 1px;+ max-width: 100%;+ display: block;+ height: auto;+ }}@media all {.c1jaw2zx {@@ -101,4 +112,7 @@ html {.cn3rfux {margin-bottom: 1em;}+ .c161qeci {+ width: 400px;+ }}diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsxindex b303d23e7b..6607c5547c 100644--- a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[another-page]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[another-page]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsxindex f6cc1d7435..aa8db5a3c4 100644--- a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/_index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/_index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-cloudflare-template/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg b/fixtures/webstudio-cloudflare-template/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svgnew file mode 100644index 0000000000..bc70d3a453--- /dev/null+++ b/fixtures/webstudio-cloudflare-template/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg@@ -0,0 +1 @@+<svg width="14" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m2.139 9.442-.007.088-.038-.105a5.451 5.451 0 0 0-.054-.142c-.01-.025.003-.045.039-.061.049-.022.054-.018.06.054a1.15 1.15 0 0 1 0 .166" fill-rule="evenodd"/></svg>\ No newline at end of filediff --git a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsx b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsxindex a87bc29fd2..4a9f69fd8a 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml]._index.server.tsx b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml]._index.server.tsxindex e718bfb1de..01e71fb611 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml]._index.server.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml]._index.server.tsx@@ -2,35 +2,16 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-import { sitemap } from "./$resources.sitemap.xml";-export const loadResources = async (_props: { system: System }) => {- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);- }-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set("content-type", "application/json; charset=utf-8");- return Promise.resolve(response);- }-- return fetch(input, init);+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ const sitemapxml_1: ResourceRequest = {+ id: "Y_ZBU-mHnSXigZ1IXI02s",+ name: "sitemap.xml",+ url: "/$resources/sitemap.xml",+ method: "get",+ headers: [],};- const [sitemapxml_1] = await Promise.all([- loadResource(customFetch, {- id: "Y_ZBU-mHnSXigZ1IXI02s",- name: "sitemap.xml",- url: "/$resources/sitemap.xml",- method: "get",- headers: [],- }),- ]);- return {- sitemapxml_1,- } as Record<string, unknown>;+ return new Map<string, ResourceRequest>([["sitemapxml_1", sitemapxml_1]]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-custom-template/app/__generated__/[world]._index.server.tsx b/fixtures/webstudio-custom-template/app/__generated__/[world]._index.server.tsxindex a193777283..ca27831095 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[world]._index.server.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[world]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-custom-template/app/__generated__/_index.server.tsx b/fixtures/webstudio-custom-template/app/__generated__/_index.server.tsxindex 013ccb1c9b..24ab7bf214 100644--- a/fixtures/webstudio-custom-template/app/__generated__/_index.server.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsxindex 324cfc402f..759b546853 100644--- a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[script-test]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[script-test]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsxindex 9bb5e05977..505eb68346 100644--- a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx@@ -1,14 +1,31 @@/* eslint-disable camelcase */import { renderToString } from "react-dom/server";import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { Page } from "../__generated__/[sitemap.xml]._index";import {- loadResources,getPageMeta,getRemixParams,+ getResources,} from "../__generated__/[sitemap.xml]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -27,7 +44,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsxindex 0fb7b111b4..6bf8247607 100644--- a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[world]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[world]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-custom-template/app/routes/_index.tsx b/fixtures/webstudio-custom-template/app/routes/_index.tsxindex f6cc1d7435..aa8db5a3c4 100644--- a/fixtures/webstudio-custom-template/app/routes/_index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/_index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/_index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/_index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.jsonindex 41f94ebc32..ccea62eda4 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json+++ b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",+ "id": "2b8a9d28-3a0e-48c9-9aa2-b26db7926a22","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",- "version": 29,- "createdAt": "2024-07-21T11:48:14.097",- "updatedAt": "2024-07-21T11:48:14.097",+ "version": 33,+ "createdAt": "2024-07-26T13:42:42.816",+ "updatedAt": "2024-07-26T13:42:42.816","pages": {"meta": {"siteName": "",@@ -151,6 +151,19 @@"value": 1}}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg:rKj-wYctg3-GnqL3WHN9I:width:",+ {+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",+ "styleSourceId": "mf2C07UBmGT7y_G4Du3yg",+ "property": "width",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 400+ }+ }]],"styleSources": [@@ -167,6 +180,13 @@"type": "local","id": "0KA68BwP9gdTzE1ESO2Zp"}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg",+ {+ "type": "local",+ "id": "mf2C07UBmGT7y_G4Du3yg"+ }]],"styleSourceSelections": [@@ -183,6 +203,13 @@"instanceId": "BMJfjOzunWs8XkQgvvx1e","values": ["0KA68BwP9gdTzE1ESO2Zp"]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "values": ["mf2C07UBmGT7y_G4Du3yg"]+ }]],"props": [@@ -195,6 +222,36 @@"type": "page","value": "WPPAbLFyJD_02vhjRd8P4"}+ ],+ [+ "su3ag3OxH9WTBjJg5eIyg",+ {+ "id": "su3ag3OxH9WTBjJg5eIyg",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "src",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "vGCYpBBB1QUPIPPIdyexn",+ {+ "id": "vGCYpBBB1QUPIPPIdyexn",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "width",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "JKAGY7DWpciEl0UdnWuKL",+ {+ "id": "JKAGY7DWpciEl0UdnWuKL",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "height",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }]],"dataSources": [@@ -237,6 +294,10 @@{"type": "id","value": "pjkZo5EiBqaeUXBcyHf_O"+ },+ {+ "type": "id",+ "value": "uHB3Fjb7-NELG-bnH7bXB"}]}@@ -310,6 +371,15 @@}]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "type": "instance",+ "id": "uHB3Fjb7-NELG-bnH7bXB",+ "component": "Image",+ "children": []+ }]],"deployment": {@@ -364,7 +434,22 @@"path": "/another-page"}],- "assets": [],+ "assets": [+ {+ "id": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee",+ "name": "iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg",+ "description": null,+ "projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",+ "size": 999,+ "type": "image",+ "format": "svg",+ "createdAt": "2024-07-26T13:39:48.678Z",+ "meta": {+ "width": 14,+ "height": 16+ }+ }+ ],"user": {"email": "[email protected]"},diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.tsindex af4f4e6a39..f8e2489bc3 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts@@ -1,6 +1,6 @@export const sitemap = [{path: "/",- lastModified: "2024-07-21",+ lastModified: "2024-07-26",},];diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsxindex 134adccf84..7848d01d46 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.server.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.server.tsxindex 38333a7aa9..ec7f6f9e62 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.server.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsxindex b3f8b2e3ea..38fa1a51e4 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx@@ -11,6 +11,7 @@ import {import {Heading as Heading,Text as Text,+ Image as Image,} from "@webstudio-is/sdk-components-react";export const siteName = "";@@ -55,6 +56,14 @@ const Page = ({}: { system: any }) => {>{"Test another page link"}</Link>+ <Image+ data-ws-id="uHB3Fjb7-NELG-bnH7bXB"+ data-ws-component="Image"+ src={"/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg"}+ width={14}+ height={16}+ className="w-image c161qeci"+ /></Body>);};diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.cssindex bc9e936306..20fa46db3e 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css@@ -84,6 +84,17 @@ html {min-height: 1em;display: inline-block;}+ :where(img.w-image) {+ box-sizing: border-box;+ border-top-width: 1px;+ border-right-width: 1px;+ border-bottom-width: 1px;+ border-left-width: 1px;+ outline-width: 1px;+ max-width: 100%;+ display: block;+ height: auto;+ }}@media all {.c1jaw2zx {@@ -101,4 +112,7 @@ html {.cn3rfux {margin-bottom: 1em;}+ .c161qeci {+ width: 400px;+ }}diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsxindex b303d23e7b..6607c5547c 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[another-page]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[another-page]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsxindex f6cc1d7435..aa8db5a3c4 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/_index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/_index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-netlify-edge-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg b/fixtures/webstudio-remix-netlify-edge-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svgnew file mode 100644index 0000000000..bc70d3a453--- /dev/null+++ b/fixtures/webstudio-remix-netlify-edge-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg@@ -0,0 +1 @@+<svg width="14" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m2.139 9.442-.007.088-.038-.105a5.451 5.451 0 0 0-.054-.142c-.01-.025.003-.045.039-.061.049-.022.054-.018.06.054a1.15 1.15 0 0 1 0 .166" fill-rule="evenodd"/></svg>\ No newline at end of filediff --git a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.jsonindex 41f94ebc32..ccea62eda4 100644--- a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json+++ b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",+ "id": "2b8a9d28-3a0e-48c9-9aa2-b26db7926a22","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",- "version": 29,- "createdAt": "2024-07-21T11:48:14.097",- "updatedAt": "2024-07-21T11:48:14.097",+ "version": 33,+ "createdAt": "2024-07-26T13:42:42.816",+ "updatedAt": "2024-07-26T13:42:42.816","pages": {"meta": {"siteName": "",@@ -151,6 +151,19 @@"value": 1}}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg:rKj-wYctg3-GnqL3WHN9I:width:",+ {+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",+ "styleSourceId": "mf2C07UBmGT7y_G4Du3yg",+ "property": "width",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 400+ }+ }]],"styleSources": [@@ -167,6 +180,13 @@"type": "local","id": "0KA68BwP9gdTzE1ESO2Zp"}+ ],+ [+ "mf2C07UBmGT7y_G4Du3yg",+ {+ "type": "local",+ "id": "mf2C07UBmGT7y_G4Du3yg"+ }]],"styleSourceSelections": [@@ -183,6 +203,13 @@"instanceId": "BMJfjOzunWs8XkQgvvx1e","values": ["0KA68BwP9gdTzE1ESO2Zp"]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "values": ["mf2C07UBmGT7y_G4Du3yg"]+ }]],"props": [@@ -195,6 +222,36 @@"type": "page","value": "WPPAbLFyJD_02vhjRd8P4"}+ ],+ [+ "su3ag3OxH9WTBjJg5eIyg",+ {+ "id": "su3ag3OxH9WTBjJg5eIyg",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "src",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "vGCYpBBB1QUPIPPIdyexn",+ {+ "id": "vGCYpBBB1QUPIPPIdyexn",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "width",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }+ ],+ [+ "JKAGY7DWpciEl0UdnWuKL",+ {+ "id": "JKAGY7DWpciEl0UdnWuKL",+ "instanceId": "uHB3Fjb7-NELG-bnH7bXB",+ "name": "height",+ "type": "asset",+ "value": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee"+ }]],"dataSources": [@@ -237,6 +294,10 @@{"type": "id","value": "pjkZo5EiBqaeUXBcyHf_O"+ },+ {+ "type": "id",+ "value": "uHB3Fjb7-NELG-bnH7bXB"}]}@@ -310,6 +371,15 @@}]}+ ],+ [+ "uHB3Fjb7-NELG-bnH7bXB",+ {+ "type": "instance",+ "id": "uHB3Fjb7-NELG-bnH7bXB",+ "component": "Image",+ "children": []+ }]],"deployment": {@@ -364,7 +434,22 @@"path": "/another-page"}],- "assets": [],+ "assets": [+ {+ "id": "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee",+ "name": "iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg",+ "description": null,+ "projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",+ "size": 999,+ "type": "image",+ "format": "svg",+ "createdAt": "2024-07-26T13:39:48.678Z",+ "meta": {+ "width": 14,+ "height": 16+ }+ }+ ],"user": {"email": "[email protected]"},diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.tsindex af4f4e6a39..f8e2489bc3 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts@@ -1,6 +1,6 @@export const sitemap = [{path: "/",- lastModified: "2024-07-21",+ lastModified: "2024-07-26",},];diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsxindex 134adccf84..7848d01d46 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.server.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.server.tsxindex 38333a7aa9..ec7f6f9e62 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.server.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsxindex b3f8b2e3ea..38fa1a51e4 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx@@ -11,6 +11,7 @@ import {import {Heading as Heading,Text as Text,+ Image as Image,} from "@webstudio-is/sdk-components-react";export const siteName = "";@@ -55,6 +56,14 @@ const Page = ({}: { system: any }) => {>{"Test another page link"}</Link>+ <Image+ data-ws-id="uHB3Fjb7-NELG-bnH7bXB"+ data-ws-component="Image"+ src={"/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg"}+ width={14}+ height={16}+ className="w-image c161qeci"+ /></Body>);};diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.cssindex bc9e936306..20fa46db3e 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css@@ -84,6 +84,17 @@ html {min-height: 1em;display: inline-block;}+ :where(img.w-image) {+ box-sizing: border-box;+ border-top-width: 1px;+ border-right-width: 1px;+ border-bottom-width: 1px;+ border-left-width: 1px;+ outline-width: 1px;+ max-width: 100%;+ display: block;+ height: auto;+ }}@media all {.c1jaw2zx {@@ -101,4 +112,7 @@ html {.cn3rfux {margin-bottom: 1em;}+ .c161qeci {+ width: 400px;+ }}diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsxindex b303d23e7b..6607c5547c 100644--- a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[another-page]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[another-page]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsxindex f6cc1d7435..aa8db5a3c4 100644--- a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/_index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/_index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-netlify-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg b/fixtures/webstudio-remix-netlify-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svgnew file mode 100644index 0000000000..bc70d3a453--- /dev/null+++ b/fixtures/webstudio-remix-netlify-functions/public/assets/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg@@ -0,0 +1 @@+<svg width="14" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M4.203.702a.713.713 0 0 0-.366.213c-.124.148-.137.208-.15.672l-.012.431-.443.015c-.481.017-.686.041-.991.117-.651.161-1.273.668-1.586 1.29a2.834 2.834 0 0 0-.252.839c-.038.241-.041.553-.041 4.366 0 4.4-.002 4.323.117 4.784.107.412.325.79.639 1.106.422.426.865.64 1.536.742.255.038.554.041 4.346.041s4.091-.003 4.346-.041c.671-.102 1.114-.316 1.536-.742.314-.316.532-.694.639-1.106.119-.461.117-.384.117-4.784 0-3.813-.003-4.125-.041-4.366a2.834 2.834 0 0 0-.252-.839c-.313-.622-.935-1.129-1.586-1.29-.305-.076-.51-.1-.991-.117l-.443-.015-.012-.431c-.013-.488-.039-.581-.204-.726C9.91.687 9.61.64 9.39.75c-.132.066-.302.249-.339.366a3.432 3.432 0 0 0-.038.5l-.011.414H4.998l-.011-.414a3.432 3.432 0 0 0-.038-.5c-.036-.115-.207-.3-.332-.361a.689.689 0 0 0-.414-.053m2.139 9.442-.007.088-.038-.105a5.451 5.451 0 0 0-.054-.142c-.01-.025.003-.045.039-.061.049-.022.054-.018.06.054a1.15 1.15 0 0 1 0 .166" fill-rule="evenodd"/></svg>\ No newline at end of filediff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.server.tsxindex 5a67dcfe3f..d6ece3c487 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.server.tsxindex 792b640473..d38af95560 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[form]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.server.tsxindex 53c83f3bae..b1fe579917 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[heading-with-id]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.server.tsxindex 07df7a9ec3..8806493692 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[nested].[nested-page]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.server.tsxindex c7bf405086..a73dbfece5 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.server.tsxindex 5a710194bf..a3b7721772 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[resources]._index.server.tsx@@ -2,35 +2,16 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-import { sitemap } from "./$resources.sitemap.xml";-export const loadResources = async (_props: { system: System }) => {- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);- }-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set("content-type", "application/json; charset=utf-8");- return Promise.resolve(response);- }-- return fetch(input, init);+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ const list_1: ResourceRequest = {+ id: "1vX6SQdaCjJN6MvJlG_cQ",+ name: "list",+ url: "https://gist.githubusercontent.com/TrySound/56507c301ec85669db5f1541406a9259/raw/a49548730ab592c86b9e7781f5b29beec4765494/collection.json",+ method: "get",+ headers: [],};- const [list_1] = await Promise.all([- loadResource(customFetch, {- id: "1vX6SQdaCjJN6MvJlG_cQ",- name: "list",- url: "https://gist.githubusercontent.com/TrySound/56507c301ec85669db5f1541406a9259/raw/a49548730ab592c86b9e7781f5b29beec4765494/collection.json",- method: "get",- headers: [],- }),- ]);- return {- list_1,- } as Record<string, unknown>;+ return new Map<string, ResourceRequest>([["list_1", list_1]]);};export const getPageMeta = ({diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/_index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/_index.server.tsxindex 138d41df94..a6a608da39 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/_index.server.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/_index.server.tsx@@ -2,9 +2,9 @@/* This is a auto generated file for building the project */import type { PageMeta } from "@webstudio-is/sdk";-import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {- return {} as Record<string, unknown>;+import type { System, ResourceRequest } from "@webstudio-is/sdk";+export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([]);};export const getPageMeta = ({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 877b51c99a..1c00c3fc97 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@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[_route_with_symbols_]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[_route_with_symbols_]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsxindex e9c9589e32..0ea540821f 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[form]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[form]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {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 0fc091f607..6f23b0c6ea 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@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[heading-with-id]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[heading-with-id]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {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 3455d84d54..afdf134191 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@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[nested].[nested-page]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[nested].[nested-page]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsxindex 92d6ef4994..c6a247b6f6 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[radix]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[radix]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsxindex da681e1663..dc0a58dc48 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/[resources]._index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/[resources]._index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx b/fixtures/webstudio-remix-vercel/app/routes/_index.tsxindex f6cc1d7435..aa8db5a3c4 100644--- a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "../__generated__/_index";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "../__generated__/_index.server";import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";import css from "../__generated__/index.css?url";+import { sitemap } from "../__generated__/$resources.sitemap.xml";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.tsindex f32c404030..c503e92162 100644--- a/packages/cli/src/prebuild.ts+++ b/packages/cli/src/prebuild.ts@@ -43,7 +43,7 @@ import {getPagePath,parseComponentName,generateFormsProperties,- generateResourcesLoader,+ generateResources,generatePageMeta,getStaticSiteMapXml,} from "@webstudio-is/sdk";@@ -675,7 +675,7 @@ export const prebuild = async (options: {/* This is a auto generated file for building the project */ \nimport type { PageMeta } from "@webstudio-is/sdk";- ${generateResourcesLoader({+ ${generateResources({scope,page: pageData.page,dataSources,@@ -711,6 +711,10 @@ export const prebuild = async (options: {for (const { file, template } of getTemplates({ pagePath })) {const content = template.replaceAll("__CONSTANTS__", importFrom("./app/constants.mjs", file))+ .replaceAll(+ "__SITEMAP__",+ importFrom(`./app/__generated__/$resources.sitemap.xml`, file)+ ).replaceAll("__CLIENT__",importFrom(`./app/__generated__/${generatedBasename}`, file)diff --git a/packages/cli/templates/defaults/app/route-templates/html.tsx b/packages/cli/templates/defaults/app/route-templates/html.tsxindex da704fbce3..8b3eb46eee 100644--- a/packages/cli/templates/defaults/app/route-templates/html.tsx+++ b/packages/cli/templates/defaults/app/route-templates/html.tsx@@ -10,6 +10,7 @@ import {redirect,} from "@remix-run/server-runtime";import { useLoaderData } from "@remix-run/react";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import {n8nHandler,@@ -25,7 +26,7 @@ import {} from "__CLIENT__";import {formsProperties,- loadResources,+ getResources,getPageMeta,getRemixParams,projectId,@@ -33,6 +34,22 @@ import {} from "__SERVER__";import { assetBaseUrl, imageBaseUrl, imageLoader } from "__CONSTANTS__";import css from "__CSS__?url";+import { sitemap } from "__SITEMAP__";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -50,7 +67,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/packages/cli/templates/defaults/app/route-templates/xml.tsx b/packages/cli/templates/defaults/app/route-templates/xml.tsxindex 0e86057f23..5dec649902 100644--- a/packages/cli/templates/defaults/app/route-templates/xml.tsx+++ b/packages/cli/templates/defaults/app/route-templates/xml.tsx@@ -1,10 +1,27 @@/* eslint-disable camelcase */import { renderToString } from "react-dom/server";import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime";+import { isLocalResource, loadResources } from "@webstudio-is/sdk";import { ReactSdkContext } from "@webstudio-is/react-sdk";import { Page } from "__CLIENT__";-import { loadResources, getPageMeta, getRemixParams } from "__SERVER__";+import { getPageMeta, getRemixParams, getResources } from "__SERVER__";import { assetBaseUrl, imageBaseUrl, imageLoader } from "__CONSTANTS__";+import { sitemap } from "__SITEMAP__";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "sitemap.xml")) {+ // @todo: dynamic import sitemap ???+ const response = new Response(JSON.stringify(sitemap));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};export const loader = async (arg: LoaderFunctionArgs) => {const url = new URL(arg.request.url);@@ -23,7 +40,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(customFetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/packages/cli/templates/ssg/app/route-templates/html/+data.ts b/packages/cli/templates/ssg/app/route-templates/html/+data.tsindex f449aa833d..6d2d1daab5 100644--- a/packages/cli/templates/ssg/app/route-templates/html/+data.ts+++ b/packages/cli/templates/ssg/app/route-templates/html/+data.ts@@ -1,6 +1,7 @@import type { PageContextServer } from "vike/types";import { redirect } from "vike/abort";-import { getPageMeta, loadResources } from "__SERVER__";+import { loadResources } from "@webstudio-is/sdk";+import { getPageMeta, getResources } from "__SERVER__";export const data = async (pageContext: PageContextServer) => {const url = new URL(pageContext.urlOriginal, "http://url");@@ -16,7 +17,7 @@ export const data = async (pageContext: PageContextServer) => {origin: url.origin,};- const resources = await loadResources({ system });+ const resources = await loadResources(fetch, getResources({ system }));const pageMeta = getPageMeta({ system, resources });if (pageMeta.redirect) {diff --git a/packages/react-sdk/placeholder.d.ts b/packages/react-sdk/placeholder.d.tsindex ff24f7d190..0d03e139f4 100644--- a/packages/react-sdk/placeholder.d.ts+++ b/packages/react-sdk/placeholder.d.ts@@ -6,7 +6,12 @@ declare module "__CONSTANTS__" {}declare module "__CLIENT__" {- import type { FontAsset, ImageAsset, System } from "@webstudio-is/sdk";+ import type {+ FontAsset,+ ImageAsset,+ ResourceRequest,+ System,+ } from "@webstudio-is/sdk";export const siteName: string;@@ -23,11 +28,11 @@ declare module "__CLIENT__" {}declare module "__SERVER__" {- import type { PageMeta, System } from "@webstudio-is/sdk";+ import type { PageMeta, System, ResourceRequest } from "@webstudio-is/sdk";- export const loadResources: (props: {+ export const getResources: (props: {system: System;- }) => Promise<Record<string, unknown>>;+ }) => Map<string, ResourceRequest>;export const getPageMeta: (props: {system: System;diff --git a/packages/sdk/src/resource-loader.ts b/packages/sdk/src/resource-loader.tsindex f43d985432..7b5e814878 100644--- a/packages/sdk/src/resource-loader.ts+++ b/packages/sdk/src/resource-loader.ts@@ -2,9 +2,9 @@ import type { ResourceRequest } from "./schema/resources";export const loadResource = async (customFetch: typeof fetch,- resourceData: ResourceRequest+ resourceRequest: ResourceRequest) => {- const { url, method, headers, body } = resourceData;+ const { url, method, headers, body } = resourceRequest;const requestHeaders = new Headers(headers.map(({ name, value }): [string, string] => [name, value]));@@ -49,3 +49,18 @@ export const loadResource = async (};}};++export const loadResources = async (+ customFetch: typeof fetch,+ requests: Map<string, ResourceRequest>+) => {+ return Object.fromEntries(+ await Promise.all(+ Array.from(+ requests,+ async ([name, request]) =>+ [name, await loadResource(customFetch, request)] as const+ )+ )+ );+};diff --git a/packages/sdk/src/resources-generator.test.ts b/packages/sdk/src/resources-generator.test.tsindex f10f123eff..d3119875e5 100644--- a/packages/sdk/src/resources-generator.test.ts+++ b/packages/sdk/src/resources-generator.test.ts@@ -1,14 +1,14 @@import { expect, test } from "@jest/globals";import type { Page } from "./schema/pages";import { createScope } from "./scope";-import { generateResourcesLoader } from "./resources-generator";+import { generateResources } from "./resources-generator";const toMap = <T extends { id: string }>(list: T[]) =>new Map(list.map((item) => [item.id, item] as const));test("generate resources loader", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: { rootInstanceId: "body" } as Page,dataSources: toMap([@@ -32,49 +32,29 @@ test("generate resources loader", () => {]),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-import { sitemap } from "./$resources.sitemap.xml";-export const loadResources = async (_props: { system: System }) => {-- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);- }-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set('content-type', 'application/json; charset=utf-8');- return Promise.resolve(response);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ const variableName: ResourceRequest = {+ id: "resourceId",+ name: "resourceName",+ url: "https://my-json.com",+ method: "post",+ headers: [+ { name: "Content-Type", value: "application/json" },+ ],+ body: { body: true },}-- return fetch(input, init);- };- const [-variableName,-] = await Promise.all([-loadResource(customFetch, {-id: "resourceId",-name: "resourceName",-url: "https://my-json.com",-method: "post",-headers: [-{ name: "Content-Type", value: "application/json" },-],-body: { body: true },-}),-])-return {-variableName,-} as Record<string, unknown>-}-"-`);+ return new Map<string, ResourceRequest>([+ ["variableName", variableName],+ ])+ }+ "+ `);});test("generate variable and use in resources loader", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: {rootInstanceId: "body",@@ -108,56 +88,35 @@ test("generate variable and use in resources loader", () => {value: `"Token " + $ws$dataSource$variableTokenId`,},],-body: `{ body: true }`,},]),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-import { sitemap } from "./$resources.sitemap.xml";-export const loadResources = async (_props: { system: System }) => {-let AccessToken = "my-token"-- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ let AccessToken = "my-token"+ const variableName: ResourceRequest = {+ id: "resourceId",+ name: "resourceName",+ url: "https://my-json.com/",+ method: "post",+ headers: [+ { name: "Authorization", value: "Token " + AccessToken },+ ],+ body: { body: true },}-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set('content-type', 'application/json; charset=utf-8');- return Promise.resolve(response);- }-- return fetch(input, init);- };- const [-variableName,-] = await Promise.all([-loadResource(customFetch, {-id: "resourceId",-name: "resourceName",-url: "https://my-json.com/",-method: "post",-headers: [-{ name: "Authorization", value: "Token " + AccessToken },-],-body: { body: true },-}),-])-return {-variableName,-} as Record<string, unknown>-}-"-`);+ return new Map<string, ResourceRequest>([+ ["variableName", variableName],+ ])+ }+ "+ `);});test("generate system variable and use in resources loader", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: {rootInstanceId: "body",@@ -190,68 +149,48 @@ test("generate system variable and use in resources loader", () => {]),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-import { sitemap } from "./$resources.sitemap.xml";-export const loadResources = async (_props: { system: System }) => {-const system = _props.system-- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ const system = _props.system+ const variableName: ResourceRequest = {+ id: "resourceId",+ name: "resourceName",+ url: "https://my-json.com/" + system?.params?.slug,+ method: "post",+ headers: [+ { name: "Content-Type", value: "application/json" },+ ],+ body: { body: true },}-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set('content-type', 'application/json; charset=utf-8');- return Promise.resolve(response);- }-- return fetch(input, init);- };- const [-variableName,-] = await Promise.all([-loadResource(customFetch, {-id: "resourceId",-name: "resourceName",-url: "https://my-json.com/" + system?.params?.slug,-method: "post",-headers: [-{ name: "Content-Type", value: "application/json" },-],-body: { body: true },-}),-])-return {-variableName,-} as Record<string, unknown>-}-"-`);+ return new Map<string, ResourceRequest>([+ ["variableName", variableName],+ ])+ }+ "+ `);});test("generate empty resources loader", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: { rootInstanceId: "body" } as Page,dataSources: new Map(),resources: new Map(),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {-return {-} as Record<string, unknown>-}-"-`);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([+ ])+ }+ "+ `);});test("prevent generating unused variables", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: { rootInstanceId: "body" } as Page,dataSources: toMap([@@ -266,18 +205,18 @@ test("prevent generating unused variables", () => {resources: new Map(),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {-return {-} as Record<string, unknown>-}-"-`);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([+ ])+ }+ "+ `);});test("prevent generating unused system variable", () => {expect(- generateResourcesLoader({+ generateResources({scope: createScope(),page: {rootInstanceId: "body",@@ -294,11 +233,11 @@ test("prevent generating unused system variable", () => {resources: new Map(),})).toMatchInlineSnapshot(`-"import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";-export const loadResources = async (_props: { system: System }) => {-return {-} as Record<string, unknown>-}-"-`);+ "import type { System, ResourceRequest } from "@webstudio-is/sdk";+ export const getResources = (_props: { system: System }) => {+ return new Map<string, ResourceRequest>([+ ])+ }+ "+ `);});diff --git a/packages/sdk/src/resources-generator.ts b/packages/sdk/src/resources-generator.tsindex 1634b7733b..2be03de987 100644--- a/packages/sdk/src/resources-generator.ts+++ b/packages/sdk/src/resources-generator.ts@@ -4,7 +4,7 @@ import type { Resources } from "./schema/resources";import type { Scope } from "./scope";import { generateExpression } from "./expression";-export const generateResourcesLoader = ({+export const generateResources = ({scope,page,dataSources,@@ -15,56 +15,57 @@ export const generateResourcesLoader = ({dataSources: DataSources;resources: Resources;}) => {- let generatedOutput = "";- let generatedLoaders = "";- let hasResources = false;+ let generatedRequests = "";+ let generatedPairs = "";const usedDataSources: DataSources = new Map();for (const dataSource of dataSources.values()) {- if (dataSource.type === "resource") {- const resource = resources.get(dataSource.resourceId);- if (resource === undefined) {- continue;- }- hasResources = true;- // call resource by bound variable name- const resourceName = scope.getName(resource.id, dataSource.name);- generatedOutput += `${resourceName},\n`;- generatedLoaders += `loadResource(customFetch, {\n`;- generatedLoaders += `id: "${resource.id}",\n`;- generatedLoaders += `name: ${JSON.stringify(resource.name)},\n`;- const url = generateExpression({- expression: resource.url,+ if (dataSource.type !== "resource") {+ continue;+ }+ const resource = resources.get(dataSource.resourceId);+ if (resource === undefined) {+ continue;+ }+ let generatedRequest = "";+ // call resource by bound variable name+ const resourceName = scope.getName(resource.id, dataSource.name);+ generatedRequest += ` const ${resourceName}: ResourceRequest = {\n`;+ generatedRequest += ` id: "${resource.id}",\n`;+ generatedRequest += ` name: ${JSON.stringify(resource.name)},\n`;+ const url = generateExpression({+ expression: resource.url,+ dataSources,+ usedDataSources,+ scope,+ });+ generatedRequest += ` url: ${url},\n`;+ generatedRequest += ` method: "${resource.method}",\n`;+ generatedRequest += ` headers: [\n`;+ for (const header of resource.headers) {+ const value = generateExpression({+ expression: header.value,dataSources,usedDataSources,scope,});- generatedLoaders += `url: ${url},\n`;- generatedLoaders += `method: "${resource.method}",\n`;- generatedLoaders += `headers: [\n`;- for (const header of resource.headers) {- const value = generateExpression({- expression: header.value,- dataSources,- usedDataSources,- scope,- });- generatedLoaders += `{ name: "${header.name}", value: ${value} },\n`;- }- generatedLoaders += `],\n`;- // prevent computing empty expression- if (resource.body !== undefined && resource.body.length > 0) {- const body = generateExpression({- expression: resource.body,- dataSources,- usedDataSources,- scope,- });- generatedLoaders += `body: ${body},\n`;- }- generatedLoaders += `}),\n`;+ generatedRequest += ` { name: "${header.name}", value: ${value} },\n`;}+ generatedRequest += ` ],\n`;+ // prevent computing empty expression+ if (resource.body !== undefined && resource.body.length > 0) {+ const body = generateExpression({+ expression: resource.body,+ dataSources,+ usedDataSources,+ scope,+ });+ generatedRequest += ` body: ${body},\n`;+ }+ generatedRequest += ` }\n`;+ generatedRequests += generatedRequest;+ generatedPairs += ` ["${resourceName}", ${resourceName}],\n`;}let generatedVariables = "";@@ -72,7 +73,7 @@ export const generateResourcesLoader = ({if (dataSource.type === "variable") {const name = scope.getName(dataSource.id, dataSource.name);const value = JSON.stringify(dataSource.value.value);- generatedVariables += `let ${name} = ${value}\n`;+ generatedVariables += ` let ${name} = ${value}\n`;}if (dataSource.type === "parameter") {@@ -81,45 +82,18 @@ export const generateResourcesLoader = ({continue;}const name = scope.getName(dataSource.id, dataSource.name);- generatedVariables += `const ${name} = _props.system\n`;+ generatedVariables += ` const ${name} = _props.system\n`;}}let generated = "";- generated += `import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";\n`;-- if (hasResources) {- generated += `import { sitemap } from "./$resources.sitemap.xml";\n`;- }-- generated += `export const loadResources = async (_props: { system: System }) => {\n`;+ generated += `import type { System, ResourceRequest } from "@webstudio-is/sdk";\n`;+ generated += `export const getResources = (_props: { system: System }) => {\n`;generated += generatedVariables;- if (hasResources) {- generated += `- const customFetch: typeof fetch = (input, init) => {- if (typeof input !== "string") {- return fetch(input, init);- }-- if (isLocalResource(input, "sitemap.xml")) {- // @todo: dynamic import sitemap ???- const response = new Response(JSON.stringify(sitemap));- response.headers.set('content-type', 'application/json; charset=utf-8');- return Promise.resolve(response);- }-- return fetch(input, init);- };- `;- generated += `const [\n`;- generated += generatedOutput;- generated += `] = await Promise.all([\n`;- generated += generatedLoaders;- generated += `])\n`;- }- generated += `return {\n`;- generated += generatedOutput;- generated += `} as Record<string, unknown>\n`;+ generated += generatedRequests;+ generated += ` return new Map<string, ResourceRequest>([\n`;+ generated += generatedPairs;+ generated += ` ])\n`;generated += `}\n`;return generated;};