Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Fix asset resource on published sites (#5565)

Oleg Isonen33f720fb9f8c
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 96e03d9c27..9ab8bd49f3 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -13,6 +13,7 @@
- Never use the `function` keyword - always use arrow functions (`const name = () => {}`) or function expressions with arrow syntax
- Functions must never have more than 3 parameters - use an object parameter instead
- Never alias the same type or variable to different names (e.g., `type AliasName = OriginalName`) - always use the original name consistently throughout the codebase
+- Spreading `undefined` works fine in JavaScript/TypeScript - the spread operator skips it. Never return empty objects `{}` when you can just `return` (or omit return for `undefined`). Example: `return { ...obj, ...maybeUndefined }` works correctly.
## Running Checks
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index b0aad7cc39..3d109d7663 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -135,7 +135,7 @@ jobs:
const results = [
await assertSize('./fixtures/ssg/dist/client', 356),
await assertSize('./fixtures/react-router-netlify/build/client', 376),
- await assertSize('./fixtures/webstudio-features/build/client', 1056),
+ await assertSize('./fixtures/webstudio-features/build/client', 3312),
]
for (const result of results) {
if (result.passed) {
diff --git a/apps/builder/app/builder/shared/assets/asset-utils.test.ts b/apps/builder/app/builder/shared/assets/asset-utils.test.ts
index 8f37e7ee56..1bb926cbf2 100644
--- a/apps/builder/app/builder/shared/assets/asset-utils.test.ts
+++ b/apps/builder/app/builder/shared/assets/asset-utils.test.ts
@@ -269,7 +269,7 @@ describe("uploadingFileDataToAsset", () => {
id: "test-id",
name: "video.mp4",
format: "mp4",
- type: "image", // Videos are treated as images for now
+ type: "file",
});
});
diff --git a/apps/builder/app/builder/shared/assets/asset-utils.ts b/apps/builder/app/builder/shared/assets/asset-utils.ts
index 7000b21d5d..0bb0a5f96c 100644
--- a/apps/builder/app/builder/shared/assets/asset-utils.ts
+++ b/apps/builder/app/builder/shared/assets/asset-utils.ts
@@ -118,21 +118,17 @@ export const uploadingFileDataToAsset = (
const assetType = detectAssetType(fileName);
if (assetType === "video") {
- // Use image type for now
- const asset: ImageAsset = {
+ // Videos should be file type, not image type
+ const asset: Asset = {
id: fileData.assetId,
name: fileName,
format,
- type: "image",
+ type: "file",
description: "",
createdAt: "",
projectId: "",
size: 0,
-
- meta: {
- width: Number.NaN,
- height: Number.NaN,
- },
+ meta: {},
};
return asset;
diff --git a/apps/builder/app/shared/$resources/assets.server.ts b/apps/builder/app/shared/$resources/assets.server.ts
index 63571f615e..d6bc0ba5ba 100644
--- a/apps/builder/app/shared/$resources/assets.server.ts
+++ b/apps/builder/app/shared/$resources/assets.server.ts
@@ -1,9 +1,9 @@
import { json } from "@remix-run/server-runtime";
import { parseBuilderUrl } from "@webstudio-is/http-client";
import { loadAssetsByProject } from "@webstudio-is/asset-uploader/index.server";
+import { toRuntimeAsset } from "@webstudio-is/sdk";
import { isBuilder } from "../router-utils";
import { createContext } from "../context.server";
-import { getAssetUrl } from "~/builder/shared/assets/asset-utils";
/**
* System Resource that provides the list of assets for the current project.
@@ -31,15 +31,10 @@ export const loader = async ({ request }: { request: Request }) => {
const requestUrl = new URL(request.url);
const origin = `${requestUrl.protocol}//${requestUrl.host}`;
- // Convert array to object with asset IDs as keys and add URL to each asset
+ // Convert array to object with asset IDs as keys
+ // Use /cgi/ endpoint URLs (relative paths)
const assetsById = Object.fromEntries(
- assets.map((asset) => [
- asset.id,
- {
- ...asset,
- url: getAssetUrl(asset, origin).href,
- },
- ])
+ assets.map((asset) => [asset.id, toRuntimeAsset(asset, origin)])
);
return json(assetsById);
diff --git a/apps/builder/app/shared/db/canvas.server.ts b/apps/builder/app/shared/db/canvas.server.ts
index b6e6165314..4686e3a7fc 100644
--- a/apps/builder/app/shared/db/canvas.server.ts
+++ b/apps/builder/app/shared/db/canvas.server.ts
@@ -63,10 +63,11 @@ export const loadProductionCanvasData = async (
}
}
- // Filter unused font assets
+ // Filter unused font assets but include all other asset types (images, videos, audio, documents)
const assets = allAssets.filter(
(asset) =>
asset.type === "image" ||
+ asset.type === "file" ||
(asset.type === "font" && fontFamilySet.has(asset.meta.family))
);
diff --git a/fixtures/README.md b/fixtures/README.md
new file mode 100644
index 0000000000..2907ee380f
--- /dev/null
+++ b/fixtures/README.md
@@ -0,0 +1,86 @@
+# Webstudio Fixtures
+
+Fixtures are test projects that ensure the CLI and build process work correctly across different deployment targets.
+
+### Updating Fixtures After Changes
+
+```bash
+# From repository root - updates all fixtures
+pnpm fixtures
+```
+
+This command will:
+
+1. Link all fixtures to their respective projects
+2. Sync the latest data from the development environment
+3. Build all fixtures with the latest code
+
+### Working with Individual Fixtures
+
+```bash
+# Go to fixture folder
+cd fixtures/webstudio-features
+
+# Link to project
+pnpm fixtures:link
+
+# Sync latest data
+pnpm fixtures:sync
+
+# Build fixture
+pnpm fixtures:build
+
+# Start it
+pnpm run dev
+```
+
+## Adding Assets to Fixtures
+
+To add a new asset (image, video, audio, etc.) to a fixture:
+
+1. **Publish to staging**
+
+ - Make your changes in the builder
+ - Publish to the staging environment
+
+2. **Get the build ID from CI**
+
+ - After publishing, check the CI logs
+ - Find the build ID that was created
+
+3. **Update the fixture's build ID**
+
+ - Edit `fixtures/[fixture-name]/package.json`
+ - Update the `--buildId` parameter in the `fixtures:sync` script
+
+ ```json
+ "fixtures:sync": "pnpm cli sync --buildId NEW_BUILD_ID_HERE && pnpm prettier --write ./.webstudio/"
+ ```
+
+4. **Sync with the correct environment**
+
+ ```bash
+ # Go to fixture folder
+ cd fixtures/webstudio-features
+
+ # Sync from staging environment (replace with your branch)
+ BUILDER_HOST=fix-assets.staging.webstudio.is pnpm run fixtures
+ ```
+
+5. **Fix the origin URL**
+
+ - After syncing, edit `.webstudio/data.json`
+ - Change the origin back to:
+
+ ```json
+ "origin": "https://main.development.webstudio.is"
+ ```
+
+ - This is necessary because sync changes it to the current branch
+
+6. **Commit the changes**
+ ```bash
+ git add fixtures/
+ git commit -m "chore: update fixtures with new assets"
+ git push
+ ```
diff --git a/fixtures/react-router-cloudflare/app/__generated__/$resources.assets.ts b/fixtures/react-router-cloudflare/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/react-router-cloudflare/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx b/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
index 69b30748c6..327de57786 100644
--- a/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-cloudflare/app/routes/_index.tsx b/fixtures/react-router-cloudflare/app/routes/_index.tsx
index 386b9b584c..d9f3203999 100644
--- a/fixtures/react-router-cloudflare/app/routes/_index.tsx
+++ b/fixtures/react-router-cloudflare/app/routes/_index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-docker/README.md b/fixtures/react-router-docker/README.md
index c6f8cfa5b9..51898d78fe 100644
--- a/fixtures/react-router-docker/README.md
+++ b/fixtures/react-router-docker/README.md
@@ -1,20 +1,3 @@
-# Fixture to test/play with webstudio
+# React Router Docker Fixture
-## How to develop
-
-```bash
-# Terminal 1
-cd packages/webstudio
-pnpm dev
-```
-
-```bash
-# Terminal 2
-pnpm fixtures:link
-
-pnpm fixtures:sync
-# data.json generated
-
-pnpm fixtures:build
-# exec `pnpm run dev` to see result
-```
+See the [main fixtures README](../README.md) for complete documentation on how to use and update fixtures.
diff --git a/fixtures/react-router-docker/app/__generated__/$resources.assets.ts b/fixtures/react-router-docker/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/react-router-docker/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/react-router-docker/app/routes/[another-page]._index.tsx b/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
index 69b30748c6..327de57786 100644
--- a/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-docker/app/routes/_index.tsx b/fixtures/react-router-docker/app/routes/_index.tsx
index 386b9b584c..d9f3203999 100644
--- a/fixtures/react-router-docker/app/routes/_index.tsx
+++ b/fixtures/react-router-docker/app/routes/_index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-netlify/app/__generated__/$resources.assets.ts b/fixtures/react-router-netlify/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/react-router-netlify/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx b/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
index 69b30748c6..327de57786 100644
--- a/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-netlify/app/routes/_index.tsx b/fixtures/react-router-netlify/app/routes/_index.tsx
index 386b9b584c..d9f3203999 100644
--- a/fixtures/react-router-netlify/app/routes/_index.tsx
+++ b/fixtures/react-router-netlify/app/routes/_index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-vercel/app/__generated__/$resources.assets.ts b/fixtures/react-router-vercel/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/react-router-vercel/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx b/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
index 69b30748c6..327de57786 100644
--- a/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/react-router-vercel/app/routes/_index.tsx b/fixtures/react-router-vercel/app/routes/_index.tsx
index 386b9b584c..d9f3203999 100644
--- a/fixtures/react-router-vercel/app/routes/_index.tsx
+++ b/fixtures/react-router-vercel/app/routes/_index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.assets.ts b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..def0dafa8f
--- /dev/null
+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.assets.ts
@@ -0,0 +1 @@
+export const assets = {};
diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
index b4ee43ad55..8f86daf8a5 100644
--- a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
@@ -4,6 +4,7 @@ import {
getPageMeta,
getResources,
} from "../../app/__generated__/_index.server";
+import { assets } from "../../app/__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -28,6 +29,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts
index 5412467320..31c7efd090 100644
--- a/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts
+++ b/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts
@@ -4,6 +4,7 @@ import {
getPageMeta,
getResources,
} from "../../app/__generated__/[redirect]._index.server";
+import { assets } from "../../app/__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -28,6 +29,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/fixtures/ssg/app/__generated__/$resources.assets.ts b/fixtures/ssg/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/ssg/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/ssg/pages/another-page/+data.ts b/fixtures/ssg/pages/another-page/+data.ts
index b839c30933..35c8bd18f6 100644
--- a/fixtures/ssg/pages/another-page/+data.ts
+++ b/fixtures/ssg/pages/another-page/+data.ts
@@ -4,6 +4,7 @@ import {
getPageMeta,
getResources,
} from "../../app/__generated__/[another-page]._index.server";
+import { assets } from "../../app/__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -28,6 +29,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/fixtures/ssg/pages/index/+data.ts b/fixtures/ssg/pages/index/+data.ts
index b4ee43ad55..8f86daf8a5 100644
--- a/fixtures/ssg/pages/index/+data.ts
+++ b/fixtures/ssg/pages/index/+data.ts
@@ -4,6 +4,7 @@ import {
getPageMeta,
getResources,
} from "../../app/__generated__/_index.server";
+import { assets } from "../../app/__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -28,6 +29,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.assets.ts b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..fb507cabf1
--- /dev/null
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.assets.ts
@@ -0,0 +1,12 @@
+export const assets = {
+ "1d8bf4398f643f5333d415091507d778aaed62f28883642636cbed0be156a0ee": {
+ url: "/cgi/image/iconly_svg_converted-converted_zMaMiAAutUl8XrITgz7d1.svg?format=raw",
+ width: 14,
+ height: 16,
+ },
+ d0974db9300c1a3b0fb8b291dd9fabd45ad136478908394280af2f7087e3aecd: {
+ url: "/cgi/image/147-1478573_cat-icon-png-black-cat-png-icon.png_ZJ6-qJjk1RlFzuYwyCXdp.jpeg?format=raw",
+ width: 820,
+ height: 985,
+ },
+};
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
index 76a3d8b7b1..7e8389db11 100644
--- a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
@@ -41,6 +41,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -72,6 +73,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
index e6b4fd8a9b..39826a6bb6 100644
--- a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
@@ -41,6 +41,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -72,6 +73,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/.webstudio/data.json b/fixtures/webstudio-features/.webstudio/data.json
index 8c0a8144ce..4a48c417bf 100644
--- a/fixtures/webstudio-features/.webstudio/data.json
+++ b/fixtures/webstudio-features/.webstudio/data.json
@@ -1,14 +1,14 @@
{
"build": {
- "id": "043bda3f-0d77-4656-aa9c-652c1a1f272e",
+ "id": "1b66ee06-8ea5-4420-9a0e-e0d3a67aca32",
"projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
- "version": 593,
- "createdAt": "2025-05-15T22:04:05.511+00:00",
- "updatedAt": "2025-05-15T22:04:05.511+00:00",
+ "version": 634,
+ "createdAt": "2026-01-15T16:19:55.574+00:00",
+ "updatedAt": "2026-01-15T16:19:55.574+00:00",
"pages": {
"meta": {
"siteName": "KittyGuardedZone",
- "faviconAssetId": "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10",
+ "faviconAssetId": "7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59",
"code": "<script>console.log('KittyGuardedZone')</script>\n"
},
"homePage": {
@@ -47,6 +47,7 @@
"id": "szYLvBduHPmbtqQKCDY0b",
"name": "RouteWithSymbols",
"title": "\"RouteWithSymbols\"",
+ "history": ["/_route_with_symbols_"],
"rootInstanceId": "EDEfpMPRqDejthtwkH7ws",
"systemDataSourceId": "UiZtSC5BK8Ub-Ow7-XOdW",
"meta": {
@@ -291,6 +292,30 @@
"include": false
},
"path": "/text-duration"
+ },
+ {
+ "id": "yaneLQ-EP83HtTFnZtbbj",
+ "name": "Assets",
+ "title": "\"Untitled\"",
+ "rootInstanceId": "jVzCxkeTMBCb0S3JUhDsQ",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/assets1"
}
],
"folders": [
@@ -313,7 +338,8 @@
"8fF_9MQOwOqsLM9BhULUG",
"oc1Ra5zelesj-wiJwiw-P",
"GgJUcrFoHE6EGMccjLa4t",
- "uuYXNj4-XxzMtJpR8O5IH"
+ "uuYXNj4-XxzMtJpR8O5IH",
+ "yaneLQ-EP83HtTFnZtbbj"
]
},
{
@@ -4137,6 +4163,46 @@
"type": "string",
"value": "https://github.com/"
}
+ ],
+ [
+ "ZxrMS3X4PXwZxwVcIs8qJ",
+ {
+ "id": "ZxrMS3X4PXwZxwVcIs8qJ",
+ "instanceId": "a94S1sqeP8lT7aeVPBv6c",
+ "name": "controls",
+ "type": "boolean",
+ "value": true
+ }
+ ],
+ [
+ "uAf7YS4QAgaZwOJceKp70",
+ {
+ "id": "uAf7YS4QAgaZwOJceKp70",
+ "instanceId": "a94S1sqeP8lT7aeVPBv6c",
+ "name": "src",
+ "type": "expression",
+ "value": "$ws$dataSource$BV__DASH__6Do0Ww17cqZ0zP7Io3.data['2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e'].url"
+ }
+ ],
+ [
+ "cGY1ZGxYEUmexYtGPrqCr",
+ {
+ "id": "cGY1ZGxYEUmexYtGPrqCr",
+ "instanceId": "aAVR8Rg52_1qq8NV5rKKe",
+ "name": "controls",
+ "type": "boolean",
+ "value": true
+ }
+ ],
+ [
+ "YFS85MWqKhrhYouWYJ3Ui",
+ {
+ "id": "YFS85MWqKhrhYouWYJ3Ui",
+ "instanceId": "aAVR8Rg52_1qq8NV5rKKe",
+ "name": "src",
+ "type": "expression",
+ "value": "$ws$dataSource$BV__DASH__6Do0Ww17cqZ0zP7Io3.data['4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d'].url"
+ }
]
],
"dataSources": [
@@ -4365,6 +4431,16 @@
"value": "globalValue"
}
}
+ ],
+ [
+ "BV-6Do0Ww17cqZ0zP7Io3",
+ {
+ "type": "resource",
+ "id": "BV-6Do0Ww17cqZ0zP7Io3",
+ "scopeInstanceId": "jVzCxkeTMBCb0S3JUhDsQ",
+ "name": "assets",
+ "resourceId": "oIYuHoIwG7GM5J9cCSsai"
+ }
]
],
"resources": [
@@ -4388,6 +4464,18 @@
"url": "\"https://httpbin.org/get?hello=world\"",
"headers": []
}
+ ],
+ [
+ "oIYuHoIwG7GM5J9cCSsai",
+ {
+ "id": "oIYuHoIwG7GM5J9cCSsai",
+ "name": "assets",
+ "control": "system",
+ "method": "get",
+ "url": "\"/$resources/assets\"",
+ "searchParams": [],
+ "headers": []
+ }
]
],
"instances": [
@@ -6755,6 +6843,45 @@
}
]
}
+ ],
+ [
+ "jVzCxkeTMBCb0S3JUhDsQ",
+ {
+ "type": "instance",
+ "id": "jVzCxkeTMBCb0S3JUhDsQ",
+ "component": "ws:element",
+ "tag": "body",
+ "children": [
+ {
+ "type": "id",
+ "value": "a94S1sqeP8lT7aeVPBv6c"
+ },
+ {
+ "type": "id",
+ "value": "aAVR8Rg52_1qq8NV5rKKe"
+ }
+ ]
+ }
+ ],
+ [
+ "a94S1sqeP8lT7aeVPBv6c",
+ {
+ "type": "instance",
+ "id": "a94S1sqeP8lT7aeVPBv6c",
+ "component": "ws:element",
+ "tag": "audio",
+ "children": []
+ }
+ ],
+ [
+ "aAVR8Rg52_1qq8NV5rKKe",
+ {
+ "type": "instance",
+ "id": "aAVR8Rg52_1qq8NV5rKKe",
+ "component": "ws:element",
+ "tag": "video",
+ "children": []
+ }
]
],
"deployment": {
@@ -6818,6 +6945,7 @@
"id": "szYLvBduHPmbtqQKCDY0b",
"name": "RouteWithSymbols",
"title": "\"RouteWithSymbols\"",
+ "history": ["/_route_with_symbols_"],
"rootInstanceId": "EDEfpMPRqDejthtwkH7ws",
"systemDataSourceId": "UiZtSC5BK8Ub-Ow7-XOdW",
"meta": {
@@ -7062,9 +7190,53 @@
"include": false
},
"path": "/text-duration"
+ },
+ {
+ "id": "yaneLQ-EP83HtTFnZtbbj",
+ "name": "Assets",
+ "title": "\"Untitled\"",
+ "rootInstanceId": "jVzCxkeTMBCb0S3JUhDsQ",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/assets1"
}
],
"assets": [
+ {
+ "id": "2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e",
+ "name": "e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3",
+ "projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ "size": 19680,
+ "type": "file",
+ "format": "mp3",
+ "createdAt": "2026-01-14T01:59:48.958+00:00",
+ "meta": {}
+ },
+ {
+ "id": "4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d",
+ "name": "webm-example_2r_6VmRBjhAy3ldaqz0gk.webm",
+ "projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ "size": 901185,
+ "type": "file",
+ "format": "webm",
+ "createdAt": "2026-01-14T02:59:19.806+00:00",
+ "meta": {}
+ },
{
"id": "7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59",
"name": "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png",
@@ -7091,6 +7263,16 @@
"height": 100
}
},
+ {
+ "id": "cbf6b1b052e52b256cef54a032a546bf43bf3f5441be4d1c5eeaabce26903d78",
+ "name": "video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4",
+ "projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
+ "size": 170479,
+ "type": "file",
+ "format": "mp4",
+ "createdAt": "2026-01-14T02:59:28.168+00:00",
+ "meta": {}
+ },
{
"id": "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",
"name": "_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg",
diff --git a/fixtures/webstudio-features/README.md b/fixtures/webstudio-features/README.md
index 417402843c..87bd10419e 100644
--- a/fixtures/webstudio-features/README.md
+++ b/fixtures/webstudio-features/README.md
@@ -1,20 +1,3 @@
-# Fixture to test/play with webstudio-cli
+# Webstudio Features Fixture
-## How to develop
-
-```bash
-# Terminal 1
-cd packages/webstudio-cli
-pnpm dev
-```
-
-```bash
-# Terminal 2
-pnpm fixtures:link
-
-pnpm fixtures:sync
-# data.json generated
-
-pnpm fixtures:build
-# exec `pnpm run dev` to see result
-```
+See the [main fixtures README](../README.md) for complete documentation on how to use and update fixtures.
diff --git a/fixtures/webstudio-features/app/__generated__/$resources.assets.ts b/fixtures/webstudio-features/app/__generated__/$resources.assets.ts
new file mode 100644
index 0000000000..f3e3d47278
--- /dev/null
+++ b/fixtures/webstudio-features/app/__generated__/$resources.assets.ts
@@ -0,0 +1,26 @@
+export const assets = {
+ "2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e": {
+ url: "/cgi/asset/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3?format=raw",
+ },
+ "4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d": {
+ url: "/cgi/asset/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm?format=raw",
+ },
+ "7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59": {
+ url: "/cgi/image/cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png?format=raw",
+ width: 790,
+ height: 786,
+ },
+ "9a8bc926-7804-4d3f-af81-69196b1d2ed8": {
+ url: "/cgi/image/small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp?format=raw",
+ width: 100,
+ height: 100,
+ },
+ cbf6b1b052e52b256cef54a032a546bf43bf3f5441be4d1c5eeaabce26903d78: {
+ url: "/cgi/asset/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4?format=raw",
+ },
+ "cd939c56-bcdd-4e64-bd9c-567a9bccd3da": {
+ url: "/cgi/image/_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg?format=raw",
+ width: 1024,
+ height: 1024,
+ },
+};
diff --git a/fixtures/webstudio-features/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-features/app/__generated__/$resources.sitemap.xml.ts
index 4adf5d883e..72fdad78cc 100644
--- a/fixtures/webstudio-features/app/__generated__/$resources.sitemap.xml.ts
+++ b/fixtures/webstudio-features/app/__generated__/$resources.sitemap.xml.ts
@@ -1,26 +1,26 @@
export const sitemap = [
{
path: "/",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
{
path: "/_route_with_symbols_",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
{
path: "/form",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
{
path: "/heading-with-id",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
{
path: "/resources",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
{
path: "/nested/nested-page",
- lastModified: "2025-05-15",
+ lastModified: "2026-01-15",
},
];
diff --git a/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
index 9a559f28e0..4ab92a17d1 100644
--- a/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[_route_with_symbols_]._index.tsx
@@ -8,7 +8,7 @@ import { Image as Image } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -18,7 +18,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx b/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
index 5c7bea4afc..0d4e7a67f8 100644
--- a/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[animations]._index.tsx
@@ -15,7 +15,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -25,7 +25,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[assets1]._index.server.tsx b/fixtures/webstudio-features/app/__generated__/[assets1]._index.server.tsx
new file mode 100644
index 0000000000..902fc6ffe2
--- /dev/null
+++ b/fixtures/webstudio-features/app/__generated__/[assets1]._index.server.tsx
@@ -0,0 +1,44 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import type { PageMeta } from "@webstudio-is/sdk";
+import type { System, ResourceRequest } from "@webstudio-is/sdk";
+export const getResources = (_props: { system: System }) => {
+ const assets_1: ResourceRequest = {
+ name: "assets",
+ url: "/$resources/assets",
+ searchParams: [],
+ method: "get",
+ headers: [],
+ };
+ const _data = new Map<string, ResourceRequest>([["assets_1", assets_1]]);
+ const _action = new Map<string, ResourceRequest>([]);
+ return { data: _data, action: _action };
+};
+
+export const getPageMeta = ({
+ system,
+ resources,
+}: {
+ system: System;
+ resources: Record<string, any>;
+}): PageMeta => {
+ return {
+ title: "Untitled",
+ description: "",
+ excludePageFromSearch: true,
+ language: "",
+ socialImageAssetName: undefined,
+ socialImageUrl: "",
+ status: undefined,
+ redirect: "",
+ custom: [],
+ };
+};
+
+type Params = Record<string, string | undefined>;
+export const getRemixParams = ({ ...params }: Params): Params => {
+ return params;
+};
+
+export const contactEmail = "[email protected]";
diff --git a/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx b/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx
new file mode 100644
index 0000000000..b1f3810b02
--- /dev/null
+++ b/fixtures/webstudio-features/app/__generated__/[assets1]._index.tsx
@@ -0,0 +1,54 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import { Fragment, useState } from "react";
+import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";
+import { Body as Body } from "@webstudio-is/sdk-components-react-router";
+
+export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
+
+export const lastPublished = "2026-01-15T16:19:55.574Z";
+
+export const siteName = "KittyGuardedZone";
+
+export const breakpoints = [
+ { id: "UoTkWyaFuTYJihS3MFYK5" },
+ { id: "ZMaWCtWpH-ao0e_kgIHqR", minWidth: 372 },
+ { id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
+];
+
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
+
+// Font assets on current page (can be preloaded)
+export const pageFontAssets: string[] = [];
+
+export const pageBackgroundImageAssets: string[] = [];
+
+const Page = (_props: { system: any }) => {
+ let assets = useResource("assets_1");
+ return (
+ <Body className={`w-element`}>
+ <audio
+ controls={true}
+ src={
+ assets?.data?.[
+ "2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e"
+ ]?.url
+ }
+ className={`w-element`}
+ />
+ <video
+ controls={true}
+ src={
+ assets?.data?.[
+ "4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d"
+ ]?.url
+ }
+ className={`w-element`}
+ />
+ </Body>
+ );
+};
+
+export { Page };
diff --git a/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx b/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
index 7454cb61a9..847f7fa20a 100644
--- a/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[class-names]._index.tsx
@@ -8,7 +8,7 @@ import { Box as Box } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -18,7 +18,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
index 94e5a886c7..bfc23d4ab0 100644
--- a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
@@ -12,7 +12,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -22,7 +22,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx b/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
index f224b81c7c..dc53e0629a 100644
--- a/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[duration]._index.tsx
@@ -9,7 +9,7 @@ import { Heading as Heading } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -19,7 +19,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx b/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
index f0d78338de..f82ba859ee 100644
--- a/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[expressions]._index.tsx
@@ -12,7 +12,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -22,7 +22,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[form]._index.tsx b/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
index 36cfe4def4..7c704829c0 100644
--- a/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[form]._index.tsx
@@ -17,7 +17,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -27,7 +27,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx b/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
index 409b21d24d..afdbceba5b 100644
--- a/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[head-tag]._index.tsx
@@ -17,7 +17,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -27,7 +27,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx b/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
index 59ee4563b7..23f046e77f 100644
--- a/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[heading-with-id]._index.tsx
@@ -8,7 +8,7 @@ import { Heading as Heading } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -18,7 +18,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx b/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
index 621c5d2752..16d5b0ee72 100644
--- a/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[nested].[nested-page]._index.tsx
@@ -8,7 +8,7 @@ import { Heading as Heading } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -18,7 +18,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
index 0ed12fe1ec..6cd6a7c62b 100644
--- a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
@@ -19,7 +19,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -29,7 +29,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx b/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
index 8c21d99973..192cf2722b 100644
--- a/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[resources]._index.tsx
@@ -11,7 +11,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -21,7 +21,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx b/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
index d78822ad93..0f8741f09b 100644
--- a/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[sitemap.xml]._index.tsx
@@ -10,7 +10,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -20,7 +20,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx b/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
index 74000ad739..7a0b99c428 100644
--- a/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[text-duration]._index.tsx
@@ -12,7 +12,7 @@ import { Heading as Heading } from "@webstudio-is/sdk-components-react";
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -22,7 +22,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/_index.tsx b/fixtures/webstudio-features/app/__generated__/_index.tsx
index 66f3aef6c4..c01c55a379 100644
--- a/fixtures/webstudio-features/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/_index.tsx
@@ -18,7 +18,7 @@ import {
export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d";
-export const lastPublished = "2025-05-15T22:04:05.511Z";
+export const lastPublished = "2026-01-15T16:19:55.574Z";
export const siteName = "KittyGuardedZone";
@@ -28,7 +28,8 @@ export const breakpoints = [
{ id: "Z8WjyXWkCrr35PXgjHdpY", minWidth: 472 },
];
-export const favIconAsset: string | undefined = undefined;
+export const favIconAsset: string | undefined =
+ "cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png";
// Font assets on current page (can be preloaded)
export const pageFontAssets: string[] = [];
diff --git a/fixtures/webstudio-features/app/__generated__/index.css b/fixtures/webstudio-features/app/__generated__/index.css
index fe52cf1ef5..dc5b37af56 100644
--- a/fixtures/webstudio-features/app/__generated__/index.css
+++ b/fixtures/webstudio-features/app/__generated__/index.css
@@ -11,6 +11,12 @@
a.w-element {
box-sizing: border-box;
}
+ body.w-element {
+ box-sizing: border-box;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ margin: 0;
+ }
body.w-body {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
diff --git a/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
index e2fd5fd585..9c69f8ebb0 100644
--- a/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[animations]._index.tsx b/fixtures/webstudio-features/app/routes/[animations]._index.tsx
index 012dd6b682..20c9f9f78e 100644
--- a/fixtures/webstudio-features/app/routes/[animations]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[animations]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[assets1]._index.tsx b/fixtures/webstudio-features/app/routes/[assets1]._index.tsx
new file mode 100644
index 0000000000..a8a34cf5c4
--- /dev/null
+++ b/fixtures/webstudio-features/app/routes/[assets1]._index.tsx
@@ -0,0 +1,322 @@
+import {
+ type MetaFunction,
+ type LinksFunction,
+ type LinkDescriptor,
+ type ActionFunctionArgs,
+ type LoaderFunctionArgs,
+ type HeadersFunction,
+ data,
+ redirect,
+ useLoaderData,
+} from "react-router";
+import {
+ isLocalResource,
+ loadResource,
+ loadResources,
+ formIdFieldName,
+ formBotFieldName,
+ cachedFetch,
+} from "@webstudio-is/sdk/runtime";
+import {
+ ReactSdkContext,
+ PageSettingsMeta,
+ PageSettingsTitle,
+} from "@webstudio-is/react-sdk/runtime";
+import {
+ projectId,
+ Page,
+ siteName,
+ favIconAsset,
+ pageFontAssets,
+ pageBackgroundImageAssets,
+ breakpoints,
+} from "../__generated__/[assets1]._index";
+import {
+ getResources,
+ getPageMeta,
+ getRemixParams,
+ contactEmail,
+} from "../__generated__/[assets1]._index.server";
+import * as constants from "../constants.mjs";
+import css from "../__generated__/index.css?url";
+import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
+
+const customFetch: typeof fetch = (input, init) => {
+ if (typeof input !== "string") {
+ return cachedFetch(projectId, 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);
+ }
+
+ if (isLocalResource(input, "current-date")) {
+ const now = new Date();
+ // Normalize to midnight UTC to prevent hydration mismatches
+ const startOfDay = new Date(
+ Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
+ );
+ const data = {
+ iso: startOfDay.toISOString(),
+ year: startOfDay.getUTCFullYear(),
+ month: startOfDay.getUTCMonth() + 1, // 1-12 instead of 0-11
+ day: startOfDay.getUTCDate(),
+ timestamp: startOfDay.getTime(),
+ };
+ const response = new Response(JSON.stringify(data));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
+ return cachedFetch(projectId, input, init);
+};
+
+export const loader = async (arg: LoaderFunctionArgs) => {
+ const url = new URL(arg.request.url);
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+ url.host = host;
+ url.protocol = "https";
+
+ const params = getRemixParams(arg.params);
+ const system = {
+ params,
+ search: Object.fromEntries(url.searchParams),
+ origin: url.origin,
+ pathname: url.pathname,
+ };
+
+ const resources = await loadResources(
+ customFetch,
+ getResources({ system }).data
+ );
+ const pageMeta = getPageMeta({ system, resources });
+
+ if (pageMeta.redirect) {
+ const status =
+ pageMeta.status === 301 || pageMeta.status === 302
+ ? pageMeta.status
+ : 302;
+ throw redirect(pageMeta.redirect, status);
+ }
+
+ // typecheck
+ arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
+
+ if (arg.context.EXCLUDE_FROM_SEARCH) {
+ pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
+ }
+
+ return data(
+ {
+ host,
+ url: url.href,
+ system,
+ resources,
+ pageMeta,
+ },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ {
+ status: pageMeta.status,
+ headers: {
+ "Cache-Control": "public, max-age=600",
+ },
+ }
+ );
+};
+
+export const headers: HeadersFunction = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: MetaFunction<typeof loader> = ({ data }) => {
+ const metas: ReturnType<MetaFunction> = [];
+ if (data === undefined) {
+ return metas;
+ }
+
+ const origin = `https://${data.host}`;
+
+ if (siteName) {
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: siteName,
+ url: origin,
+ },
+ });
+ }
+
+ return metas;
+};
+
+export const links: LinksFunction = () => {
+ const result: LinkDescriptor[] = [];
+
+ result.push({
+ rel: "stylesheet",
+ href: css,
+ });
+
+ if (favIconAsset) {
+ result.push({
+ rel: "icon",
+ href: constants.imageLoader({
+ src: `${constants.assetBaseUrl}${favIconAsset}`,
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
+ width: 144,
+ height: 144,
+ fit: "pad",
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+
+ for (const asset of pageFontAssets) {
+ result.push({
+ rel: "preload",
+ href: `${constants.assetBaseUrl}${asset}`,
+ as: "font",
+ crossOrigin: "anonymous",
+ });
+ }
+
+ for (const backgroundImageAsset of pageBackgroundImageAssets) {
+ result.push({
+ rel: "preload",
+ href: `${constants.assetBaseUrl}${backgroundImageAsset}`,
+ as: "image",
+ });
+ }
+
+ return result;
+};
+
+const getRequestHost = (request: Request): string =>
+ request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
+
+export const action = async ({
+ request,
+ context,
+}: ActionFunctionArgs): Promise<
+ { success: true } | { success: false; errors: string[] }
+> => {
+ try {
+ const url = new URL(request.url);
+ url.host = getRequestHost(request);
+
+ const formData = await request.formData();
+
+ const system = {
+ params: {},
+ search: {},
+ origin: url.origin,
+ pathname: url.pathname,
+ };
+
+ const resourceName = formData.get(formIdFieldName);
+ let resource =
+ typeof resourceName === "string"
+ ? getResources({ system }).action.get(resourceName)
+ : undefined;
+
+ const formBotValue = formData.get(formBotFieldName);
+
+ if (formBotValue == null || typeof formBotValue !== "string") {
+ throw new Error("Form bot field not found");
+ }
+
+ const submitTime = parseInt(formBotValue, 16);
+ // Assumes that the difference between the server time and the form submission time,
+ // including any client-server time drift, is within a 5-minute range.
+ // Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
+ // Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
+ if (
+ Number.isNaN(submitTime) ||
+ Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
+ ) {
+ throw new Error(`Form bot value invalid ${formBotValue}`);
+ }
+
+ formData.delete(formIdFieldName);
+ formData.delete(formBotFieldName);
+
+ if (resource) {
+ resource.body = Object.fromEntries(formData);
+ } else {
+ if (contactEmail === undefined) {
+ throw new Error("Contact email not found");
+ }
+
+ resource = context.getDefaultActionResource?.({
+ url,
+ projectId,
+ contactEmail,
+ formData,
+ });
+ }
+
+ if (resource === undefined) {
+ throw Error("Resource not found");
+ }
+ const { ok, statusText } = await loadResource(fetch, resource);
+ if (ok) {
+ return { success: true };
+ }
+ return { success: false, errors: [statusText] };
+ } catch (error) {
+ console.error(error);
+
+ return {
+ success: false,
+ errors: [error instanceof Error ? error.message : "Unknown error"],
+ };
+ }
+};
+
+const Outlet = () => {
+ const { system, resources, url, pageMeta, host } =
+ useLoaderData<typeof loader>();
+ return (
+ <ReactSdkContext.Provider
+ value={{
+ ...constants,
+ resources,
+ breakpoints,
+ onError: console.error,
+ }}
+ >
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
+ <Page key={url} system={system} />
+ <PageSettingsMeta
+ url={url}
+ pageMeta={pageMeta}
+ host={host}
+ siteName={siteName}
+ imageLoader={constants.imageLoader}
+ assetBaseUrl={constants.assetBaseUrl}
+ />
+ <PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
+ </ReactSdkContext.Provider>
+ );
+};
+
+export default Outlet;
diff --git a/fixtures/webstudio-features/app/routes/[class-names]._index.tsx b/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
index d848e9b17d..d76dbd3d6b 100644
--- a/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[content-block]._index.tsx b/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
index 2818d10680..9ff7f64ed8 100644
--- a/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[duration]._index.tsx b/fixtures/webstudio-features/app/routes/[duration]._index.tsx
index b6cde3979c..fb58abafb9 100644
--- a/fixtures/webstudio-features/app/routes/[duration]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[duration]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[expressions]._index.tsx b/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
index a1a6e50f47..f38b863326 100644
--- a/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[form]._index.tsx b/fixtures/webstudio-features/app/routes/[form]._index.tsx
index 51260d77c9..afbba63718 100644
--- a/fixtures/webstudio-features/app/routes/[form]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[form]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx b/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
index 3b7de02fa0..e3f49886fc 100644
--- a/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
index ea3af3468f..3ad987722c 100644
--- a/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx b/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
index 2d5fc593dc..1be009c970 100644
--- a/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[radix]._index.tsx b/fixtures/webstudio-features/app/routes/[radix]._index.tsx
index f6345b1de4..d04a936a09 100644
--- a/fixtures/webstudio-features/app/routes/[radix]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[radix]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[resources]._index.tsx b/fixtures/webstudio-features/app/routes/[resources]._index.tsx
index 6186419d6c..df0e4df1de 100644
--- a/fixtures/webstudio-features/app/routes/[resources]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[resources]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
index f2df2340d3..bc760b95f1 100644
--- a/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
@@ -13,6 +13,7 @@ import {
} from "../__generated__/[sitemap.xml]._index.server";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -44,6 +45,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx b/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
index 3555f5eb4b..b0d4de5472 100644
--- a/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/app/routes/_index.tsx b/fixtures/webstudio-features/app/routes/_index.tsx
index 386b9b584c..d9f3203999 100644
--- a/fixtures/webstudio-features/app/routes/_index.tsx
+++ b/fixtures/webstudio-features/app/routes/_index.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";
+import { assets } from "../__generated__/$resources.assets";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/fixtures/webstudio-features/package.json b/fixtures/webstudio-features/package.json
index b50c50a4c8..1e3fd17712 100644
--- a/fixtures/webstudio-features/package.json
+++ b/fixtures/webstudio-features/package.json
@@ -6,7 +6,7 @@
"dev": "react-router dev",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
"fixtures:link": "pnpm cli link --link https://p-cddc1d44-af37-4cb6-a430-d300cf6f932d-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'",
- "fixtures:sync": "pnpm cli sync --buildId 043bda3f-0d77-4656-aa9c-652c1a1f272e && pnpm prettier --write ./.webstudio/",
+ "fixtures:sync": "pnpm cli sync --buildId 1b66ee06-8ea5-4420-9a0e-e0d3a67aca32 && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template react-router --template ./.template && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
},
"private": true,
diff --git a/fixtures/webstudio-features/public/assets/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3 b/fixtures/webstudio-features/public/assets/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3
new file mode 100644
index 0000000000..e7f4bbf8f9
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3 differ
diff --git a/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_BsTI5QxvAbqOcBwK4HpfZ.mp4 b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_BsTI5QxvAbqOcBwK4HpfZ.mp4
new file mode 100644
index 0000000000..bca9bf62af
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_BsTI5QxvAbqOcBwK4HpfZ.mp4 differ
diff --git a/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4 b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4
new file mode 100644
index 0000000000..2868ea936e
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4 differ
diff --git a/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_iUsqxbreCq0PcxoSahkmr.mp4 b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_iUsqxbreCq0PcxoSahkmr.mp4
new file mode 100644
index 0000000000..bca9bf62af
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/video_QamtUWsD-ShifhzZLoNIv_iUsqxbreCq0PcxoSahkmr.mp4 differ
diff --git a/fixtures/webstudio-features/public/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm b/fixtures/webstudio-features/public/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm
new file mode 100644
index 0000000000..7456528682
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm differ
diff --git a/fixtures/webstudio-features/public/assets/webm-example_zNrAFpO1v78xz91jYpaiE.webm b/fixtures/webstudio-features/public/assets/webm-example_zNrAFpO1v78xz91jYpaiE.webm
new file mode 100644
index 0000000000..7456528682
Binary files /dev/null and b/fixtures/webstudio-features/public/assets/webm-example_zNrAFpO1v78xz91jYpaiE.webm differ
diff --git a/package.json b/package.json
index 604f433127..218228a764 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,8 @@
"dts": "pnpm -r dts",
"dev": "pnpm --filter='@webstudio-is/builder' dev",
"lint": "eslint \"**/*.{ts,tsx}\" --max-warnings 0",
- "checks": "pnpm -r test && pnpm -r typecheck && pnpm lint",
+ "fixtures": "pnpm -r fixtures:link && pnpm -r fixtures:sync && pnpm -r fixtures:build",
+ "checks": "pnpm -r test && pnpm -r typecheck && pnpm lint && pnpm fixtures",
"playwright": "pnpm -r playwright-init",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"storybook:dev": "storybook dev -p 6006",
diff --git a/packages/asset-uploader/src/utils/format-asset.test.ts b/packages/asset-uploader/src/utils/format-asset.test.ts
new file mode 100644
index 0000000000..e0cb25f220
--- /dev/null
+++ b/packages/asset-uploader/src/utils/format-asset.test.ts
@@ -0,0 +1,215 @@
+import { describe, test, expect } from "vitest";
+import { formatAsset } from "./format-asset";
+
+describe("formatAsset", () => {
+ const baseParams = {
+ assetId: "test-asset-id",
+ projectId: "test-project-id",
+ filename: "custom-filename",
+ description: "Test description",
+ };
+
+ test("formats font asset correctly", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "Inter-Regular.woff2",
+ format: "woff2",
+ description: null,
+ size: 50000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({
+ family: "Inter",
+ style: "normal",
+ weight: 400,
+ }),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "Inter-Regular.woff2",
+ projectId: "test-project-id",
+ type: "font",
+ format: "woff2",
+ size: 50000,
+ meta: {
+ family: "Inter",
+ style: "normal",
+ weight: 400,
+ },
+ });
+ });
+
+ test("formats image asset with width and height correctly", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "photo.jpg",
+ format: "jpg",
+ description: null,
+ size: 100000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({
+ width: 1920,
+ height: 1080,
+ }),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "photo.jpg",
+ projectId: "test-project-id",
+ type: "image",
+ format: "jpg",
+ size: 100000,
+ meta: {
+ width: 1920,
+ height: 1080,
+ },
+ });
+ });
+
+ test("formats video asset with width and height as file type", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "video.mp4",
+ format: "mp4",
+ description: null,
+ size: 5000000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({
+ width: 1920,
+ height: 1080,
+ }),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "video.mp4",
+ projectId: "test-project-id",
+ type: "file",
+ format: "mp4",
+ size: 5000000,
+ meta: {},
+ });
+ });
+
+ test("formats webm video with width and height as file type", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "video.webm",
+ format: "webm",
+ description: null,
+ size: 3000000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({
+ width: 1280,
+ height: 720,
+ }),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "video.webm",
+ projectId: "test-project-id",
+ type: "file",
+ format: "webm",
+ size: 3000000,
+ meta: {},
+ });
+ });
+
+ test("formats audio file as file type", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "audio.mp3",
+ format: "mp3",
+ description: null,
+ size: 2000000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({}),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "audio.mp3",
+ projectId: "test-project-id",
+ type: "file",
+ format: "mp3",
+ size: 2000000,
+ meta: {},
+ });
+ });
+
+ test("formats document file as file type", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "document.pdf",
+ format: "pdf",
+ description: null,
+ size: 500000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({}),
+ },
+ });
+
+ expect(result).toMatchObject({
+ id: "test-asset-id",
+ name: "document.pdf",
+ projectId: "test-project-id",
+ type: "file",
+ format: "pdf",
+ size: 500000,
+ meta: {},
+ });
+ });
+
+ test("handles null filename and description", () => {
+ const result = formatAsset({
+ assetId: "test-asset-id",
+ projectId: "test-project-id",
+ filename: null,
+ description: null,
+ file: {
+ name: "file.pdf",
+ format: "pdf",
+ description: null,
+ size: 100000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({}),
+ },
+ });
+
+ expect(result.filename).toBeUndefined();
+ expect(result.description).toBeUndefined();
+ });
+
+ test("formats image without dimensions as file type", () => {
+ const result = formatAsset({
+ ...baseParams,
+ file: {
+ name: "image.png",
+ format: "png",
+ description: null,
+ size: 50000,
+ createdAt: "2024-01-01T00:00:00Z",
+ meta: JSON.stringify({}),
+ },
+ });
+
+ expect(result).toMatchObject({
+ type: "file",
+ format: "png",
+ meta: {},
+ });
+ });
+});
diff --git a/packages/asset-uploader/src/utils/format-asset.ts b/packages/asset-uploader/src/utils/format-asset.ts
index 8bfc009d80..2b9bf44b42 100644
--- a/packages/asset-uploader/src/utils/format-asset.ts
+++ b/packages/asset-uploader/src/utils/format-asset.ts
@@ -1,5 +1,5 @@
import { type FontFormat, FontMeta, FONT_FORMATS } from "@webstudio-is/fonts";
-import { type Asset, ImageMeta } from "@webstudio-is/sdk";
+import { type Asset, ImageMeta, detectAssetType } from "@webstudio-is/sdk";
export const formatAsset = ({
assetId,
@@ -39,8 +39,13 @@ export const formatAsset = ({
};
}
- // Check if it's an image by checking if meta has width and height
+ // Detect actual asset type based on file extension
+ const detectedType = detectAssetType(file.name);
+
+ // Check if it's an image by verifying both metadata AND file extension
+ // Videos also have width/height but should not be treated as images
const isImage =
+ detectedType === "image" &&
parsedMeta &&
typeof parsedMeta.width === "number" &&
typeof parsedMeta.height === "number";
@@ -60,7 +65,7 @@ export const formatAsset = ({
};
}
- // Default to file type for everything else
+ // Default to file type for everything else (including videos)
return {
id: assetId,
name: file.name,
diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts
index 2b99621e9c..579a7331bd 100644
--- a/packages/cli/src/prebuild.ts
+++ b/packages/cli/src/prebuild.ts
@@ -47,6 +47,7 @@ import {
ROOT_INSTANCE_ID,
elementComponent,
getAssetUrl,
+ toRuntimeAsset,
} from "@webstudio-is/sdk";
import type { Data } from "@webstudio-is/http-client";
import { LOCAL_DATA_FILE } from "./config";
@@ -433,17 +434,16 @@ export const prebuild = async (options: {
}
for (const asset of siteData.assets) {
- if (asset.type === "image" || asset.type === "font") {
- assetsToDownload.push(
- limit(() =>
- downloadAsset(
- getAssetUrl(asset, assetOrigin || "").href,
- asset.name,
- assetBaseUrl
- )
+ // Download all assets (images, fonts, videos, audio, documents, etc.)
+ assetsToDownload.push(
+ limit(() =>
+ downloadAsset(
+ getAssetUrl(asset, assetOrigin || "").href,
+ asset.name,
+ assetBaseUrl
)
- );
- }
+ )
+ );
}
}
@@ -691,6 +691,10 @@ export const prebuild = async (options: {
"__SITEMAP__",
importFrom(`./app/__generated__/$resources.sitemap.xml`, file)
)
+ .replaceAll(
+ "__ASSETS__",
+ importFrom(`./app/__generated__/$resources.assets`, file)
+ )
.replaceAll(
"__CLIENT__",
importFrom(`./app/__generated__/${generatedBasename}`, file)
@@ -727,6 +731,23 @@ export const prebuild = async (options: {
`
);
+ // Generate assets resource file
+ // Assets use /cgi/ endpoints on both builder and published sites
+ // Use a placeholder origin for URL construction, result will be relative paths
+ const assetsById = Object.fromEntries(
+ siteData.assets.map((asset) => [
+ asset.id,
+ toRuntimeAsset(asset, "https://placeholder.local"),
+ ])
+ );
+
+ await createFileIfNotExists(
+ join(generatedDir, "$resources.assets.ts"),
+ `
+ export const assets = ${JSON.stringify(assetsById, null, 2)};
+ `
+ );
+
const redirects = siteData.build.pages?.redirects;
if (redirects !== undefined && redirects.length > 0) {
for (const redirect of redirects) {
diff --git a/packages/cli/templates/defaults/app/route-templates/html.tsx b/packages/cli/templates/defaults/app/route-templates/html.tsx
index 7a3e0d6e37..b183fa898b 100644
--- a/packages/cli/templates/defaults/app/route-templates/html.tsx
+++ b/packages/cli/templates/defaults/app/route-templates/html.tsx
@@ -41,6 +41,7 @@ import {
import * as constants from "__CONSTANTS__";
import css from "__CSS__?url";
import { sitemap } from "__SITEMAP__";
+import { assets } from "__ASSETS__";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -72,6 +73,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/packages/cli/templates/defaults/app/route-templates/xml.tsx b/packages/cli/templates/defaults/app/route-templates/xml.tsx
index 3a8ccf6a72..0617d1fd39 100644
--- a/packages/cli/templates/defaults/app/route-templates/xml.tsx
+++ b/packages/cli/templates/defaults/app/route-templates/xml.tsx
@@ -9,6 +9,7 @@ import { Page, breakpoints } from "__CLIENT__";
import { getPageMeta, getRemixParams, getResources } from "__SERVER__";
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
import { sitemap } from "__SITEMAP__";
+import { assets } from "__ASSETS__";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -40,6 +41,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/packages/cli/templates/react-router/app/route-templates/html.tsx b/packages/cli/templates/react-router/app/route-templates/html.tsx
index 77ffc2f4b8..dd9f5df307 100644
--- a/packages/cli/templates/react-router/app/route-templates/html.tsx
+++ b/packages/cli/templates/react-router/app/route-templates/html.tsx
@@ -40,6 +40,7 @@ import {
import * as constants from "__CONSTANTS__";
import css from "__CSS__?url";
import { sitemap } from "__SITEMAP__";
+import { assets } from "__ASSETS__";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -71,6 +72,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return cachedFetch(projectId, input, init);
};
diff --git a/packages/cli/templates/react-router/app/route-templates/xml.tsx b/packages/cli/templates/react-router/app/route-templates/xml.tsx
index 05ad59f6c9..9785f66700 100644
--- a/packages/cli/templates/react-router/app/route-templates/xml.tsx
+++ b/packages/cli/templates/react-router/app/route-templates/xml.tsx
@@ -9,6 +9,7 @@ import { Page, breakpoints } from "__CLIENT__";
import { getPageMeta, getRemixParams, getResources } from "__SERVER__";
import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
import { sitemap } from "__SITEMAP__";
+import { assets } from "__ASSETS__";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -40,6 +41,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/packages/cli/templates/ssg/app/route-templates/html/+data.ts b/packages/cli/templates/ssg/app/route-templates/html/+data.ts
index 13e0e4ff61..058735e51e 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 { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";
import { getPageMeta, getResources } from "__SERVER__";
+import { assets } from "__ASSETS__";
const customFetch: typeof fetch = (input, init) => {
if (typeof input !== "string") {
@@ -25,6 +26,12 @@ const customFetch: typeof fetch = (input, init) => {
return Promise.resolve(response);
}
+ if (isLocalResource(input, "assets")) {
+ const response = new Response(JSON.stringify(assets));
+ response.headers.set("content-type", "application/json; charset=utf-8");
+ return Promise.resolve(response);
+ }
+
return fetch(input, init);
};
diff --git a/packages/react-sdk/placeholder.d.ts b/packages/react-sdk/placeholder.d.ts
index 5cb28b269c..bd7346066d 100644
--- a/packages/react-sdk/placeholder.d.ts
+++ b/packages/react-sdk/placeholder.d.ts
@@ -58,6 +58,11 @@ declare module "__SITEMAP__" {
}>;
}
+declare module "__ASSETS__" {
+ import type { RuntimeAsset } from "@webstudio-is/sdk";
+ export const assets: Record<string, RuntimeAsset>;
+}
+
declare module "__REDIRECT__" {
export const url: string;
export const status: number;
diff --git a/packages/sdk/src/assets.test.ts b/packages/sdk/src/assets.test.ts
index f7aad41d3e..3f0fb8bef9 100644
--- a/packages/sdk/src/assets.test.ts
+++ b/packages/sdk/src/assets.test.ts
@@ -15,6 +15,7 @@ import {
detectAssetType,
decodePathFragment,
getAssetUrl,
+ toRuntimeAsset,
acceptToMimePatterns,
acceptToMimeCategories,
getAssetMime,
@@ -470,19 +471,25 @@ describe("allowed-file-types", () => {
test("generates correct URL for video assets", () => {
const url = getAssetUrl(mockVideoAsset, "https://example.com");
- expect(url.href).toBe("https://example.com/cgi/video/video.mp4");
- expect(url.pathname).toBe("/cgi/video/video.mp4");
+ expect(url.href).toBe(
+ "https://example.com/cgi/asset/video.mp4?format=raw"
+ );
+ expect(url.pathname).toBe("/cgi/asset/video.mp4");
});
test("generates correct URL for font assets", () => {
const url = getAssetUrl(mockFontAsset, "https://example.com");
- expect(url.href).toBe("https://example.com/cgi/asset/font.woff2");
+ expect(url.href).toBe(
+ "https://example.com/cgi/asset/font.woff2?format=raw"
+ );
expect(url.pathname).toBe("/cgi/asset/font.woff2");
});
test("generates correct URL for generic file assets", () => {
const url = getAssetUrl(mockGenericAsset, "https://example.com");
- expect(url.href).toBe("https://example.com/cgi/asset/document.pdf");
+ expect(url.href).toBe(
+ "https://example.com/cgi/asset/document.pdf?format=raw"
+ );
expect(url.pathname).toBe("/cgi/asset/document.pdf");
});
@@ -512,7 +519,7 @@ describe("allowed-file-types", () => {
format: "MP4",
};
const url = getAssetUrl(upperCaseVideo, "https://example.com");
- expect(url.pathname).toBe("/cgi/video/video.mp4");
+ expect(url.pathname).toBe("/cgi/asset/video.mp4");
});
test("handles assets with special characters in name", () => {
@@ -833,4 +840,119 @@ describe("allowed-file-types", () => {
).toBe(false);
});
});
+
+ describe("toRuntimeAsset", () => {
+ const mockImageAsset = {
+ id: "image-1",
+ name: "photo.jpg",
+ projectId: "project-1",
+ size: 1024,
+ type: "image" as const,
+ format: "jpg",
+ description: "A photo",
+ createdAt: "2024-01-01",
+ meta: { width: 1920, height: 1080 },
+ };
+
+ const mockFontAsset = {
+ id: "font-1",
+ name: "font.woff2",
+ projectId: "project-1",
+ size: 512,
+ type: "font" as const,
+ format: "woff2" as const,
+ description: null,
+ createdAt: "2024-01-01",
+ meta: {
+ family: "Arial",
+ style: "normal" as const,
+ weight: 400,
+ },
+ };
+
+ const mockVariableFontAsset = {
+ id: "font-2",
+ name: "variable-font.woff2",
+ projectId: "project-1",
+ size: 768,
+ type: "font" as const,
+ format: "woff2" as const,
+ description: null,
+ createdAt: "2024-01-01",
+ meta: {
+ family: "Inter",
+ variationAxes: {},
+ },
+ };
+
+ const mockGenericAsset = {
+ id: "doc-1",
+ name: "document.pdf",
+ projectId: "project-1",
+ size: 4096,
+ type: "file" as const,
+ format: "pdf",
+ description: null,
+ createdAt: "2024-01-01",
+ meta: {},
+ };
+
+ test("converts image asset with all fields", () => {
+ const result = toRuntimeAsset(mockImageAsset, "https://example.com");
+ expect(result).toEqual({
+ url: "/cgi/image/photo.jpg?format=raw",
+ width: 1920,
+ height: 1080,
+ });
+ });
+
+ test("converts static font asset with metadata", () => {
+ const result = toRuntimeAsset(mockFontAsset, "https://example.com");
+ expect(result).toEqual({
+ url: "/cgi/asset/font.woff2?format=raw",
+ family: "Arial",
+ style: "normal",
+ weight: 400,
+ });
+ });
+
+ test("converts variable font asset without style/weight", () => {
+ const result = toRuntimeAsset(
+ mockVariableFontAsset,
+ "https://example.com"
+ );
+ expect(result).toEqual({
+ url: "/cgi/asset/variable-font.woff2?format=raw",
+ family: "Inter",
+ });
+ });
+
+ test("converts generic file asset with minimal fields", () => {
+ const result = toRuntimeAsset(mockGenericAsset, "https://example.com");
+ expect(result).toEqual({
+ url: "/cgi/asset/document.pdf?format=raw",
+ });
+ });
+
+ test("returns relative URLs regardless of origin", () => {
+ const result1 = toRuntimeAsset(mockImageAsset, "https://cdn.example.com");
+ const result2 = toRuntimeAsset(mockImageAsset, "http://localhost:3000");
+ // Both should return the same relative URL
+ expect(result1.url).toBe("/cgi/image/photo.jpg?format=raw");
+ expect(result2.url).toBe("/cgi/image/photo.jpg?format=raw");
+ });
+
+ test("handles image without dimensions", () => {
+ const assetWithoutDimensions = {
+ ...mockImageAsset,
+ meta: { width: 0, height: 0 },
+ };
+ const result = toRuntimeAsset(
+ assetWithoutDimensions,
+ "https://example.com"
+ );
+ expect(result).not.toHaveProperty("width");
+ expect(result).not.toHaveProperty("height");
+ });
+ });
});
diff --git a/packages/sdk/src/assets.ts b/packages/sdk/src/assets.ts
index 492b3dd8d9..b4f202bd63 100644
--- a/packages/sdk/src/assets.ts
+++ b/packages/sdk/src/assets.ts
@@ -399,8 +399,7 @@ export const decodePathFragment = (fragment: string): string => {
/**
* Generates the appropriate URL for an asset based on its type and format.
* - Images use /cgi/image/ with format=raw
- * - Videos use /cgi/video/
- * - Other assets use /cgi/asset/
+ * - All other assets (videos, audio, fonts, documents) use /cgi/asset/ with format=raw
*
* @param asset - The asset to generate URL for
* @param origin - Origin to prepend (e.g., "https://example.com"). When provided, returns an absolute URL.
@@ -412,11 +411,96 @@ export const getAssetUrl = (asset: Asset, origin: string): URL => {
if (assetType === "image") {
path = `/cgi/image/${asset.name}?format=raw`;
- } else if (assetType === "video") {
- path = `/cgi/video/${asset.name}`;
} else {
- path = `/cgi/asset/${asset.name}`;
+ // Videos, audio, fonts, documents all use /cgi/asset/
+ path = `/cgi/asset/${asset.name}?format=raw`;
}
return new URL(path, origin);
};
+
+/**
+ * Runtime asset data structure with only fields needed at runtime.
+ * This is a simplified version of the Asset type, optimized for client-side usage.
+ */
+export type RuntimeAsset = {
+ url: string;
+ width?: number;
+ height?: number;
+ family?: string;
+ style?: string;
+ weight?: number;
+};
+
+/**
+ * Type-specific metadata extractors that define what runtime data each asset type needs.
+ * Adding a new asset type requires implementing its extractor here.
+ */
+type RuntimeMetadata = Omit<RuntimeAsset, "url"> | undefined;
+
+const extractImageMetadata = (asset: Asset): RuntimeMetadata => {
+ if (asset.type !== "image") {
+ return;
+ }
+ // Only include dimensions if they're non-zero
+ if (asset.meta.width && asset.meta.height) {
+ return {
+ width: asset.meta.width,
+ height: asset.meta.height,
+ };
+ }
+};
+
+const extractFontMetadata = (asset: Asset): RuntimeMetadata => {
+ if (asset.type !== "font") {
+ return;
+ }
+ const metadata: Omit<RuntimeAsset, "url"> = {
+ family: asset.meta.family,
+ };
+ // Static fonts have style and weight, variable fonts have variationAxes
+ if ("style" in asset.meta) {
+ metadata.style = asset.meta.style;
+ metadata.weight = asset.meta.weight;
+ }
+ return metadata;
+};
+
+const extractFileMetadata = (_asset: Asset): RuntimeMetadata => {
+ // Generic files don't need additional metadata at runtime
+ return;
+};
+
+const metadataExtractors: Record<
+ Asset["type"],
+ (asset: Asset) => RuntimeMetadata
+> = {
+ image: extractImageMetadata,
+ font: extractFontMetadata,
+ file: extractFileMetadata,
+};
+
+/**
+ * Converts a full Asset to a minimal RuntimeAsset format.
+ * This reduces payload size by including only runtime-needed data.
+ *
+ * Each asset type defines its own metadata extractor to ensure we only
+ * include the fields that are actually needed at runtime.
+ *
+ * @param asset - The full asset object
+ * @param origin - Origin to use for generating the asset URL (only used for URL construction, result is always a relative path)
+ * @returns A minimal RuntimeAsset object with relative URL
+ */
+export const toRuntimeAsset = (asset: Asset, origin: string): RuntimeAsset => {
+ const extractor = metadataExtractors[asset.type];
+ const metadata = extractor(asset);
+
+ const url = getAssetUrl(asset, origin);
+ // Use pathname + search to get the relative path with query string
+ const relativeUrl = url.pathname + url.search;
+
+ return {
+ url: relativeUrl,
+ ...metadata,
+ };
+};