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: Restore hosted Assets queries (#6454)

Oleg Isonen9b1100f25bc6
diff --git a/apps/builder/app/shared/db/canvas.server.test.ts b/apps/builder/app/shared/db/canvas.server.test.ts
index e21f6d4bd8..1457295f21 100644
--- a/apps/builder/app/shared/db/canvas.server.test.ts
+++ b/apps/builder/app/shared/db/canvas.server.test.ts
@@ -1,5 +1,17 @@
import { expect, test, vi } from "vitest";
-import type { Asset } from "@webstudio-is/sdk";
+import {
+ createAssetResourceRequest,
+ createStructuredAssetQueryResourceBody,
+ type Asset,
+} from "@webstudio-is/sdk";
+import { loadResource } from "@webstudio-is/sdk/runtime";
+import {
+ createAssetIndex,
+ createCanonicalAssetFileEntry,
+ createContentRuntimeArtifact,
+} from "@webstudio-is/content-engine/compiler";
+import { createGeneratedAssetResourceRuntime } from "@webstudio-is/content-engine/runtime";
+import { createDocumentGraph } from "@webstudio-is/content-engine";
import type { StyleValue } from "@webstudio-is/css-engine";
import {
createImageAssetFixture,
@@ -244,7 +256,7 @@ test("build-id bundles do not read MDX bodies while preparing the RPC response",
project,
{} as never,
dependencies,
- { prepareContentIndex: false }
+ { contentIndex: "client" }
);
expect(preparePublishedAssetData).not.toHaveBeenCalled();
@@ -253,6 +265,174 @@ test("build-id bundles do not read MDX bodies while preparing the RPC response",
expect(result.assets).toContainEqual(article);
});
+test.each([
+ { origin: "https://project.wstd.io", destination: "saas" as const },
+ { origin: "https://custom.example", destination: "saas" as const },
+ { origin: "https://project.wstd.io", destination: "static" as const },
+])(
+ "prepares Assets queries for $destination builds on $origin",
+ async ({ origin, destination }) => {
+ const source = "---\nslug: post\ntitle: Post\n---\nArticle body\n";
+ const article: Asset = {
+ ...createImageAssetFixture(),
+ id: "article",
+ name: "article.md",
+ type: "file",
+ format: "md",
+ size: new TextEncoder().encode(source).byteLength,
+ meta: {},
+ };
+ const configuration = {
+ result: "one" as const,
+ where: {
+ field: ["properties", "slug"],
+ operator: "eq" as const,
+ value: "system.params.slug",
+ },
+ sort: [],
+ limit: "1",
+ offset: "0",
+ output: { mode: "all" as const, includeMetadata: false },
+ content: { mode: "markdown-body-ref" as const },
+ };
+ const build = createBundleBuild({
+ deployment:
+ destination === "saas"
+ ? { destination, domains: [] }
+ : {
+ destination,
+ name: "site.zip",
+ assetsDomain: origin,
+ templates: ["ssg"],
+ },
+ resources: [
+ {
+ id: "article-query",
+ name: "Article",
+ control: "system",
+ method: "post",
+ url: '"/$resources/assets"',
+ headers: [],
+ body: createStructuredAssetQueryResourceBody(configuration),
+ },
+ ],
+ dataSources: [
+ {
+ id: "article-data",
+ type: "resource",
+ name: "Article",
+ resourceId: "article-query",
+ },
+ ],
+ });
+ const artifact = await createAssetIndex({
+ projectId: build.projectId,
+ entries: [
+ createCanonicalAssetFileEntry({
+ projectId: build.projectId,
+ document: {
+ _id: article.id,
+ _type: "asset.file",
+ name: article.name,
+ path: article.name,
+ key: "article",
+ extension: "md",
+ mimeType: "text/markdown",
+ size: article.size,
+ revision: "article-r1",
+ contentRef: article.name,
+ properties: { slug: "post", title: "Post" },
+ },
+ }),
+ ],
+ documentGraph: createDocumentGraph({
+ nodes: [
+ {
+ id: article.id,
+ revision: "article-r1",
+ contentRef: article.name,
+ format: "markdown",
+ },
+ ],
+ edges: [],
+ }),
+ });
+ const preparePublishedAssetData = vi.fn(async () => ({
+ artifact,
+ assets: [article],
+ assetFolders: [],
+ }));
+ const bundle = await addProjectMetadata(
+ serializeProjectBundle({ build, assets: [article] }),
+ {
+ id: build.projectId,
+ userId: null,
+ domain: "project.wstd.io",
+ title: "Example",
+ } as never,
+ {} as never,
+ {
+ getUserById: vi.fn(),
+ preparePublishedAssetData,
+ validatePublishedAssetCollections: vi.fn(async () => ({
+ assets: [article],
+ assetFolders: [],
+ })),
+ createAssetClient: vi.fn(() => ({}) as never),
+ },
+ { contentIndex: "client" }
+ );
+ if (destination === "static") {
+ expect(preparePublishedAssetData).not.toHaveBeenCalled();
+ expect(bundle.assetIndex).toBeUndefined();
+ return;
+ }
+ const fetchDocument = vi.fn<typeof fetch>(async () => new Response(source));
+ // Match the generated runtime: a bundle without an index uses ordinary fetch.
+ const generatedFetch =
+ bundle.assetIndex === undefined
+ ? fetch
+ : await createGeneratedAssetResourceRuntime({
+ deploymentId: build.id,
+ artifact: createContentRuntimeArtifact(bundle.assetIndex),
+ runtimeAssets: {
+ [article.id]: {
+ url: `/assets/${article.name}`,
+ contentRef: article.name,
+ },
+ },
+ })({
+ request: new Request(`${origin}/blog/post`),
+ fallback: fetchDocument,
+ });
+ const result = await loadResource(
+ generatedFetch,
+ createAssetResourceRequest({
+ query: {
+ ...configuration,
+ where: { ...configuration.where, value: "post" },
+ limit: undefined,
+ offset: undefined,
+ },
+ })
+ );
+ expect(result).toMatchObject({
+ ok: true,
+ status: 200,
+ data: {
+ properties: { title: "Post" },
+ content: { text: "Article body\n" },
+ },
+ });
+ expect(preparePublishedAssetData).toHaveBeenCalledOnce();
+ expect(bundle.assetIndex?.contents).toBeUndefined();
+ expect(fetchDocument).toHaveBeenCalledOnce();
+ expect((fetchDocument.mock.calls[0][0] as Request).url).toBe(
+ `${origin}/assets/article.md`
+ );
+ }
+);
+
test("loads project-id bundles from the published build", async () => {
const data = createPublishedProjectBundleFixture();
const project = {
diff --git a/apps/builder/app/shared/db/canvas.server.ts b/apps/builder/app/shared/db/canvas.server.ts
index 0922275931..99bd197e17 100644
--- a/apps/builder/app/shared/db/canvas.server.ts
+++ b/apps/builder/app/shared/db/canvas.server.ts
@@ -178,7 +178,7 @@ const addProjectMetadata = async (
onMdxTemplateOmissions?: (
issues: readonly PublishedMdxTemplateOmission[]
) => void;
- prepareContentIndex?: boolean;
+ contentIndex?: "client";
} = {}
): Promise<PublishedProjectBundle> => {
const user =
@@ -186,20 +186,23 @@ const addProjectMetadata = async (
? undefined
: await dependencies.getUserById(context, project.userId);
- let publicationBuild:
- | Parameters<typeof createPublishedBuildContentCompilationPlan>[0]
- | undefined;
+ const publicationBuild = {
+ ...data.build,
+ pages: migratePages(data.build.pages),
+ };
let candidateDiscoveryPlan: ReturnType<
typeof createBuildContentCompilationPlan
>;
let assetRequirements: ReturnType<
typeof createPublishedBuildContentCompilationPlan
>;
- if (options.prepareContentIndex !== false) {
- publicationBuild = {
- ...data.build,
- pages: migratePages(data.build.pages),
- };
+ if (options.contentIndex === "client") {
+ // Static builds compile downloaded sources in the runner. Hosted builds
+ // still need query metadata; Markdown body references resolve at runtime.
+ if (data.build.deployment?.destination !== "static") {
+ assetRequirements = createBuildContentCompilationPlan(publicationBuild);
+ }
+ } else {
const dynamicBlockIds =
getDynamicPublishedMdxSourceBlockIds(publicationBuild);
const projectCandidates = resolvePublishedMdxAssetCandidates({
@@ -223,7 +226,7 @@ const addProjectMetadata = async (
let publishedAssets = data.assets;
let publishedAssetFolders = data.assetFolders;
let mdxTemplateOmissions: PublishedMdxTemplateOmission[] = [];
- if (assetRequirements !== undefined && publicationBuild !== undefined) {
+ if (assetRequirements !== undefined) {
const resolveMdxDependencies =
createPublishedMdxDependencyClosureResolver();
const publishedAssetData = await dependencies.preparePublishedAssetData({
@@ -367,7 +370,7 @@ export const loadProjectBundleByBuildId = async (
project,
context,
addProjectMetadataDependencies,
- { prepareContentIndex: contentIndex !== "client" }
+ { contentIndex }
);
};
diff --git a/docs/university/foundations/content-engine.md b/docs/university/foundations/content-engine.md
index 4383239d00..e978c48c67 100644
--- a/docs/university/foundations/content-engine.md
+++ b/docs/university/foundations/content-engine.md
@@ -47,10 +47,11 @@ Choose the file format based on how editors will work with the article body:
| `.mdx` with a Content Block | Publishing downloads the article files and compiles the MDX for every article the page can render. More articles can make publishing slower. | Editors can change the article visually on the canvas with a Notion-style experience, or edit the MDX source file. |
| `.md` with Markdown Embed | No per-article MDX compilation is needed. A hosted page reads the selected Markdown body when it is requested. | Editors can edit the `.md` file in the Markdown source editor in Assets, but cannot edit its body visually on the canvas. |
-The publish runner currently synchronizes Asset files for either format. That
-transfer still takes time; the difference is the additional per-article MDX
-compilation. Static pages can also read Markdown bodies while generating their
-HTML. Use [Content Block](../core-components/content-block.md) when visual
+Hosted builds receive a content database for their Assets queries. Markdown
+body-reference queries use stored frontmatter for that database and fetch the
+selected body when a visitor opens the page. Static exports download article
+sources and build the database in the publish runner; this transfer and any
+MDX compilation still take time. Use [Content Block](../core-components/content-block.md) when visual
article editing matters, or [Markdown Embed](../core-components/markdown-embed.md)
when source editing is enough.
diff --git a/fixtures/react-router-cloudflare/.webstudio/data.json b/fixtures/react-router-cloudflare/.webstudio/data.json
index 83a8bd3120..e643fcb9c2 100644
--- a/fixtures/react-router-cloudflare/.webstudio/data.json
+++ b/fixtures/react-router-cloudflare/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -427,9 +416,7 @@
},
"deployment": {
"destination": "saas",
- "domains": [
- "cli-basic-test-d0osr"
- ],
+ "domains": ["cli-basic-test-d0osr"],
"assetsDomain": "cli-basic-test-d0osr",
"excludeWstdDomainFromSearch": false
}
@@ -457,9 +444,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/react-router-docker/.webstudio/data.json b/fixtures/react-router-docker/.webstudio/data.json
index 83a8bd3120..e643fcb9c2 100644
--- a/fixtures/react-router-docker/.webstudio/data.json
+++ b/fixtures/react-router-docker/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -427,9 +416,7 @@
},
"deployment": {
"destination": "saas",
- "domains": [
- "cli-basic-test-d0osr"
- ],
+ "domains": ["cli-basic-test-d0osr"],
"assetsDomain": "cli-basic-test-d0osr",
"excludeWstdDomainFromSearch": false
}
@@ -457,9 +444,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/react-router-netlify/.webstudio/data.json b/fixtures/react-router-netlify/.webstudio/data.json
index 83a8bd3120..e643fcb9c2 100644
--- a/fixtures/react-router-netlify/.webstudio/data.json
+++ b/fixtures/react-router-netlify/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -427,9 +416,7 @@
},
"deployment": {
"destination": "saas",
- "domains": [
- "cli-basic-test-d0osr"
- ],
+ "domains": ["cli-basic-test-d0osr"],
"assetsDomain": "cli-basic-test-d0osr",
"excludeWstdDomainFromSearch": false
}
@@ -457,9 +444,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/react-router-vercel/.webstudio/data.json b/fixtures/react-router-vercel/.webstudio/data.json
index 83a8bd3120..e643fcb9c2 100644
--- a/fixtures/react-router-vercel/.webstudio/data.json
+++ b/fixtures/react-router-vercel/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -427,9 +416,7 @@
},
"deployment": {
"destination": "saas",
- "domains": [
- "cli-basic-test-d0osr"
- ],
+ "domains": ["cli-basic-test-d0osr"],
"assetsDomain": "cli-basic-test-d0osr",
"excludeWstdDomainFromSearch": false
}
@@ -457,9 +444,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/ssg-cloudflare-pages/.webstudio/data.json b/fixtures/ssg-cloudflare-pages/.webstudio/data.json
index c2cbe7fbae..27aa15b986 100644
--- a/fixtures/ssg-cloudflare-pages/.webstudio/data.json
+++ b/fixtures/ssg-cloudflare-pages/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -453,9 +442,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json
index acd4a7e1ac..5bb8b8d7a7 100644
--- a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json
+++ b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json
@@ -51,10 +51,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "Y60VJnVZMU_ifI0GnAR1N",
- "fOBamlMdmM461hLaITmV7"
- ]
+ "children": ["Y60VJnVZMU_ifI0GnAR1N", "fOBamlMdmM461hLaITmV7"]
}
]
},
diff --git a/fixtures/webstudio-cloudflare-template/.webstudio/data.json b/fixtures/webstudio-cloudflare-template/.webstudio/data.json
index c2cbe7fbae..27aa15b986 100644
--- a/fixtures/webstudio-cloudflare-template/.webstudio/data.json
+++ b/fixtures/webstudio-cloudflare-template/.webstudio/data.json
@@ -23,9 +23,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
@@ -55,10 +53,7 @@
"id": "root",
"name": "Root",
"slug": "",
- "children": [
- "9di_L14CzctvSruIoKVvE",
- "WPPAbLFyJD_02vhjRd8P4"
- ]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -199,27 +194,21 @@
"MMimeobf_zi4ZkRGXapju",
{
"instanceId": "MMimeobf_zi4ZkRGXapju",
- "values": [
- "7_QL45cpvP-zG8Hkgf4cr"
- ]
+ "values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
],
[
"BMJfjOzunWs8XkQgvvx1e",
{
"instanceId": "BMJfjOzunWs8XkQgvvx1e",
- "values": [
- "0KA68BwP9gdTzE1ESO2Zp"
- ]
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
}
],
[
"uHB3Fjb7-NELG-bnH7bXB",
{
"instanceId": "uHB3Fjb7-NELG-bnH7bXB",
- "values": [
- "mf2C07UBmGT7y_G4Du3yg"
- ]
+ "values": ["mf2C07UBmGT7y_G4Du3yg"]
}
]
],
@@ -453,9 +442,7 @@
"id": "WPPAbLFyJD_02vhjRd8P4",
"name": "Another page",
"title": "\"Another page\"",
- "history": [
- "/another-page"
- ],
+ "history": ["/another-page"],
"rootInstanceId": "n_VBMr7klpx25buS0NV7R",
"systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
"meta": {
diff --git a/fixtures/webstudio-features/.webstudio/data.json b/fixtures/webstudio-features/.webstudio/data.json
index a47e19ff2c..8e01e5cfb9 100644
--- a/fixtures/webstudio-features/.webstudio/data.json
+++ b/fixtures/webstudio-features/.webstudio/data.json
@@ -45,9 +45,7 @@
"id": "szYLvBduHPmbtqQKCDY0b",
"name": "RouteWithSymbols",
"title": "\"RouteWithSymbols\"",
- "history": [
- "/_route_with_symbols_"
- ],
+ "history": ["/_route_with_symbols_"],
"rootInstanceId": "EDEfpMPRqDejthtwkH7ws",
"systemDataSourceId": "UiZtSC5BK8Ub-Ow7-XOdW",
"meta": {
@@ -347,9 +345,7 @@
"id": "42cWhASQ3tTtKDnsvzhUF",
"name": "Nested",
"slug": "nested",
- "children": [
- "Pnz-BxUm6XmvFygk_XdEy"
- ]
+ "children": ["Pnz-BxUm6XmvFygk_XdEy"]
}
]
},
@@ -2534,414 +2530,322 @@
"nVMWvMsaLCcb0o1wuNQgg",
{
"instanceId": "nVMWvMsaLCcb0o1wuNQgg",
- "values": [
- "y3sBN2gB0KCBXkheM6GMm"
- ]
+ "values": ["y3sBN2gB0KCBXkheM6GMm"]
}
],
[
"f0kF-WmL7DQg7MSyRvqY1",
{
"instanceId": "f0kF-WmL7DQg7MSyRvqY1",
- "values": [
- "NeVTA8c7vqOjhHotkd0Dv"
- ]
+ "values": ["NeVTA8c7vqOjhHotkd0Dv"]
}
],
[
"5XDbqPrZDeCwq4YJ3CHsc",
{
"instanceId": "5XDbqPrZDeCwq4YJ3CHsc",
- "values": [
- "ureLSWiLGOYeWpki2JUeu"
- ]
+ "values": ["ureLSWiLGOYeWpki2JUeu"]
}
],
[
"qPnkiFGDj8dITWb1kmpGl",
{
"instanceId": "qPnkiFGDj8dITWb1kmpGl",
- "values": [
- "7HeiD-PCsn4VW6_fz5Skr"
- ]
+ "values": ["7HeiD-PCsn4VW6_fz5Skr"]
}
],
[
"pX1ovPI7NdC0HRjkw6Kpw",
{
"instanceId": "pX1ovPI7NdC0HRjkw6Kpw",
- "values": [
- "8VVhDFG7dmCfwcwD4DH8D"
- ]
+ "values": ["8VVhDFG7dmCfwcwD4DH8D"]
}
],
[
"On9cvWCxr5rdZtY9O1Bv0",
{
"instanceId": "On9cvWCxr5rdZtY9O1Bv0",
- "values": [
- "_t7PW0R2Naz9Zy7J1f8eQ"
- ]
+ "values": ["_t7PW0R2Naz9Zy7J1f8eQ"]
}
],
[
"zJ927zk9txwUbYycKB7QA",
{
"instanceId": "zJ927zk9txwUbYycKB7QA",
- "values": [
- "dPMbxwoxmuFjloniiOQb-"
- ]
+ "values": ["dPMbxwoxmuFjloniiOQb-"]
}
],
[
"sMxg7xT1hwYt05hbOvoPL",
{
"instanceId": "sMxg7xT1hwYt05hbOvoPL",
- "values": [
- "wVw5XxXIHCKE0ye-4HNeK"
- ]
+ "values": ["wVw5XxXIHCKE0ye-4HNeK"]
}
],
[
"qQSA4NoyKC88O68mBiQe2",
{
"instanceId": "qQSA4NoyKC88O68mBiQe2",
- "values": [
- "h9BV0WW02L74rm4w_yY7e"
- ]
+ "values": ["h9BV0WW02L74rm4w_yY7e"]
}
],
[
"RSk81lLj2IGXgchTuXF7V",
{
"instanceId": "RSk81lLj2IGXgchTuXF7V",
- "values": [
- "8Mg2sVpRQaHDWI8DG7Qjz"
- ]
+ "values": ["8Mg2sVpRQaHDWI8DG7Qjz"]
}
],
[
"IUftdfjK-ilSzfOTdIx1u",
{
"instanceId": "IUftdfjK-ilSzfOTdIx1u",
- "values": [
- "ZLyayr_Puk3HM35c44F2J"
- ]
+ "values": ["ZLyayr_Puk3HM35c44F2J"]
}
],
[
"C838wkvIcA1BQu30Xu2G8",
{
"instanceId": "C838wkvIcA1BQu30Xu2G8",
- "values": [
- "n6w3ORlRsss2eBGMq3bW1"
- ]
+ "values": ["n6w3ORlRsss2eBGMq3bW1"]
}
],
[
"fYUOB_brm6s0Ky68lzMfU",
{
"instanceId": "fYUOB_brm6s0Ky68lzMfU",
- "values": [
- "ANkU37d5ZGfcSzPhzwnGD"
- ]
+ "values": ["ANkU37d5ZGfcSzPhzwnGD"]
}
],
[
"dfd4gonev_AX6BpuCsxjb",
{
"instanceId": "dfd4gonev_AX6BpuCsxjb",
- "values": [
- "s6cuBxkGT20NUG_kWpsQI"
- ]
+ "values": ["s6cuBxkGT20NUG_kWpsQI"]
}
],
[
"wRw75kuvFzl5NWD8IGJoI",
{
"instanceId": "wRw75kuvFzl5NWD8IGJoI",
- "values": [
- "eIzOGCjVa5lQceZUhtIVK"
- ]
+ "values": ["eIzOGCjVa5lQceZUhtIVK"]
}
],
[
"wNRVuu0L5E8TVufKdswp1",
{
"instanceId": "wNRVuu0L5E8TVufKdswp1",
- "values": [
- "4pgxDxhhX5AvMmL4olZw0"
- ]
+ "values": ["4pgxDxhhX5AvMmL4olZw0"]
}
],
[
"65djoTmSBGemZ2L5izQ5M",
{
"instanceId": "65djoTmSBGemZ2L5izQ5M",
- "values": [
- "dWnaFMuWYYTjdOgCbt0LQ"
- ]
+ "values": ["dWnaFMuWYYTjdOgCbt0LQ"]
}
],
[
"UJYfe6kH7HqhH0YYeJwe7",
{
"instanceId": "UJYfe6kH7HqhH0YYeJwe7",
- "values": [
- "rpyoufLHt2eYUBYVUvsvU"
- ]
+ "values": ["rpyoufLHt2eYUBYVUvsvU"]
}
],
[
"600nGddaNxGGdsuGgpxJR",
{
"instanceId": "600nGddaNxGGdsuGgpxJR",
- "values": [
- "T633SDU2F_Tk_BEOYeis6"
- ]
+ "values": ["T633SDU2F_Tk_BEOYeis6"]
}
],
[
"Ta70VqUb_fGJXBT_zsnxQ",
{
"instanceId": "Ta70VqUb_fGJXBT_zsnxQ",
- "values": [
- "-tj0IHwf7a17jeBULU-OR"
- ]
+ "values": ["-tj0IHwf7a17jeBULU-OR"]
}
],
[
"mOVPnIrlt6IwVAzI_i2Fc",
{
"instanceId": "mOVPnIrlt6IwVAzI_i2Fc",
- "values": [
- "EG1HUMyU4Rw4xD2pnGi28"
- ]
+ "values": ["EG1HUMyU4Rw4xD2pnGi28"]
}
],
[
"AdXSAYCx4QDo5QN6nLoGs",
{
"instanceId": "AdXSAYCx4QDo5QN6nLoGs",
- "values": [
- "49DYl_wcHv6juFsJK5Qv3"
- ]
+ "values": ["49DYl_wcHv6juFsJK5Qv3"]
}
],
[
"9I4GRU1sev48hREkQcKQ-",
{
"instanceId": "9I4GRU1sev48hREkQcKQ-",
- "values": [
- "USUcfFPW4YwsvbvNORkpm"
- ]
+ "values": ["USUcfFPW4YwsvbvNORkpm"]
}
],
[
"81ejLVXyFEV1SxiJrWhyw",
{
"instanceId": "81ejLVXyFEV1SxiJrWhyw",
- "values": [
- "y8DFYnVCeQ_smp3u6CSTn"
- ]
+ "values": ["y8DFYnVCeQ_smp3u6CSTn"]
}
],
[
"drCx7m8q_gnNQLrhPDA-g",
{
"instanceId": "drCx7m8q_gnNQLrhPDA-g",
- "values": [
- "o9VRyqmvIarF6HrGMccU8"
- ]
+ "values": ["o9VRyqmvIarF6HrGMccU8"]
}
],
[
"T-rqx2b12pRrWcafRRoIG",
{
"instanceId": "T-rqx2b12pRrWcafRRoIG",
- "values": [
- "g6Z7dAxi6LYB-XtI6SaRR"
- ]
+ "values": ["g6Z7dAxi6LYB-XtI6SaRR"]
}
],
[
"LYBzzBvHLrfSOmPLs52dP",
{
"instanceId": "LYBzzBvHLrfSOmPLs52dP",
- "values": [
- "LnOCG1kkSViZaAVoz4GXw"
- ]
+ "values": ["LnOCG1kkSViZaAVoz4GXw"]
}
],
[
"3rtiNx74sdhz1rNTQBmRA",
{
"instanceId": "3rtiNx74sdhz1rNTQBmRA",
- "values": [
- "MX5X3_9QBk2KNCj9_oKWA"
- ]
+ "values": ["MX5X3_9QBk2KNCj9_oKWA"]
}
],
[
"Dwv02N8aJoxXacL58cmf-",
{
"instanceId": "Dwv02N8aJoxXacL58cmf-",
- "values": [
- "9manQUfGxXPqfUvJR7nx_"
- ]
+ "values": ["9manQUfGxXPqfUvJR7nx_"]
}
],
[
"TNyJ2G7r6h267foLukveQ",
{
"instanceId": "TNyJ2G7r6h267foLukveQ",
- "values": [
- "FdQDnQuBGdJjsbJJkurgl"
- ]
+ "values": ["FdQDnQuBGdJjsbJJkurgl"]
}
],
[
"YCTo59XfqTGNPH7ow1rvU",
{
"instanceId": "YCTo59XfqTGNPH7ow1rvU",
- "values": [
- "-S9zvxalqR_PGnY3STOlK"
- ]
+ "values": ["-S9zvxalqR_PGnY3STOlK"]
}
],
[
"VJAhRG8CDslSQStNf0C_A",
{
"instanceId": "VJAhRG8CDslSQStNf0C_A",
- "values": [
- "2fMK05sbKQLCp_N7ES5cH"
- ]
+ "values": ["2fMK05sbKQLCp_N7ES5cH"]
}
],
[
"67Te7ahXi4mbqb0CMC6Xh",
{
"instanceId": "67Te7ahXi4mbqb0CMC6Xh",
- "values": [
- "w3UQay-q-ZxidA7tiKjlT"
- ]
+ "values": ["w3UQay-q-ZxidA7tiKjlT"]
}
],
[
"RHGykFKK2R4PyjNtIuSEk",
{
"instanceId": "RHGykFKK2R4PyjNtIuSEk",
- "values": [
- "nlUHVVdPJqX4ucX3QvPHQ"
- ]
+ "values": ["nlUHVVdPJqX4ucX3QvPHQ"]
}
],
[
"ccyTkEM40ar6Z2UTXhFvY",
{
"instanceId": "ccyTkEM40ar6Z2UTXhFvY",
- "values": [
- "z9mqrlxshNacx8dvtUKFI"
- ]
+ "values": ["z9mqrlxshNacx8dvtUKFI"]
}
],
[
"1e-3lR1XsDg2IsPu4mSNr",
{
"instanceId": "1e-3lR1XsDg2IsPu4mSNr",
- "values": [
- "Eboa64A1ivGBt9vVhHdkx"
- ]
+ "values": ["Eboa64A1ivGBt9vVhHdkx"]
}
],
[
"YrVDoWK0I_9hpQs5yJzLt",
{
"instanceId": "YrVDoWK0I_9hpQs5yJzLt",
- "values": [
- "C-HNDjw4PJgh2x3Xt-zaT"
- ]
+ "values": ["C-HNDjw4PJgh2x3Xt-zaT"]
}
],
[
"Qrpsu4yKLKARA-82TnhLI",
{
"instanceId": "Qrpsu4yKLKARA-82TnhLI",
- "values": [
- "iseTqeMVub0Y6Q_3eOQ0S"
- ]
+ "values": ["iseTqeMVub0Y6Q_3eOQ0S"]
}
],
[
"3hPo1LW5P_4VAyXUmVtpY",
{
"instanceId": "3hPo1LW5P_4VAyXUmVtpY",
- "values": [
- "Uhs5fZ65aKJ2wz5eB2fCJ"
- ]
+ "values": ["Uhs5fZ65aKJ2wz5eB2fCJ"]
}
],
[
"KCX8plaeWZXn98-4qmHBW",
{
"instanceId": "KCX8plaeWZXn98-4qmHBW",
- "values": [
- "9GVBj1HWWhCsENaCEZID-"
- ]
+ "values": ["9GVBj1HWWhCsENaCEZID-"]
}
],
[
"81TW-o_0QLHlfmBAKFyCQ",
{
"instanceId": "81TW-o_0QLHlfmBAKFyCQ",
- "values": [
- "mcplLi9TYqk__JBKYzuss"
- ]
+ "values": ["mcplLi9TYqk__JBKYzuss"]
}
],
[
"cvCjIfx9TJ3XeeSpCnW1w",
{
"instanceId": "cvCjIfx9TJ3XeeSpCnW1w",
- "values": [
- "8WyGOidmbyXhMWoXUdEkK"
- ]
+ "values": ["8WyGOidmbyXhMWoXUdEkK"]
}
],
[
"hi1l-ro0pCVQpHFIwIhFO",
{
"instanceId": "hi1l-ro0pCVQpHFIwIhFO",
- "values": [
- "hSMd0d2O_5ogkTfvV8g8B"
- ]
+ "values": ["hSMd0d2O_5ogkTfvV8g8B"]
}
],
[
"tOdjbQbLEf52thwmubL7R",
{
"instanceId": "tOdjbQbLEf52thwmubL7R",
- "values": [
- "SdJcDQJhrZ0zxtPqj546x"
- ]
+ "values": ["SdJcDQJhrZ0zxtPqj546x"]
}
],
[
"g__o13UKOkD0KImnp-sWp",
{
"instanceId": "g__o13UKOkD0KImnp-sWp",
- "values": [
- "hEVSzkOEBn_3dNyo65PAM"
- ]
+ "values": ["hEVSzkOEBn_3dNyo65PAM"]
}
],
[
"Ol5bklKKxyJaS7Q3jcCfD",
{
"instanceId": "Ol5bklKKxyJaS7Q3jcCfD",
- "values": [
- "U6kV-2LTnN9kR4jWfLb1c"
- ]
+ "values": ["U6kV-2LTnN9kR4jWfLb1c"]
}
]
],
@@ -2986,9 +2890,7 @@
"value": [
{
"type": "execute",
- "args": [
- "value"
- ],
+ "args": ["value"],
"code": "$ws$dataSource$RR_FthRebEUcAKUJIXl0j = value"
}
]
@@ -3064,9 +2966,7 @@
"value": [
{
"type": "execute",
- "args": [
- "state"
- ],
+ "args": ["state"],
"code": "$ws$dataSource$KvfuNNCNslj7nAGsD69Fl = state"
}
]
@@ -3142,9 +3042,7 @@
"value": [
{
"type": "execute",
- "args": [
- "state"
- ],
+ "args": ["state"],
"code": "$ws$dataSource$Ip0FRY7L24QrIMdtuMN5j = state"
}
]
@@ -6998,9 +6896,7 @@
},
"deployment": {
"destination": "saas",
- "domains": [
- "webstudio-fixture-project-a-0su3o"
- ],
+ "domains": ["webstudio-fixture-project-a-0su3o"],
"assetsDomain": "webstudio-fixture-project-a-0su3o",
"excludeWstdDomainFromSearch": false
}
@@ -7059,9 +6955,7 @@
"id": "szYLvBduHPmbtqQKCDY0b",
"name": "RouteWithSymbols",
"title": "\"RouteWithSymbols\"",
- "history": [
- "/_route_with_symbols_"
- ],
+ "history": ["/_route_with_symbols_"],
"rootInstanceId": "EDEfpMPRqDejthtwkH7ws",
"systemDataSourceId": "UiZtSC5BK8Ub-Ow7-XOdW",
"meta": {
diff --git a/packages/cli/src/prebuild.test.ts b/packages/cli/src/prebuild.test.ts
index ac35d878b5..77ced49795 100644
--- a/packages/cli/src/prebuild.test.ts
+++ b/packages/cli/src/prebuild.test.ts
@@ -10,7 +10,7 @@ import {
utimes,
writeFile,
} from "node:fs/promises";
-import { join } from "node:path";
+import { dirname, join } from "node:path";
import { pathToFileURL } from "node:url";
import { tmpdir } from "node:os";
import { execFile } from "node:child_process";
@@ -788,6 +788,41 @@ test("hydrates encoded filenames from an embedded SSG database", async () => {
});
describe("prebuild", () => {
+ test("rejects Assets queries without a content database without changing generated files", async () => {
+ const siteData = createSiteData();
+ siteData.build.resources = [["posts", createQueryResource()]] as never;
+ siteData.build.dataSources = [
+ [
+ "posts-data",
+ {
+ id: "posts-data",
+ type: "resource",
+ name: "posts",
+ resourceId: "posts",
+ scopeInstanceId: "root",
+ },
+ ],
+ ] as never;
+ await writeSiteData(siteData);
+ const existingFiles = [
+ "app/routes/_index.tsx",
+ "app/__generated__/index.ts",
+ ];
+ for (const file of existingFiles) {
+ await mkdir(dirname(file), { recursive: true });
+ await writeFile(file, "previous build");
+ }
+
+ await expect(
+ prebuild({ assets: false, template: ["defaults"] })
+ ).rejects.toThrow(
+ "Assets queries require a content database. Sync the project again before building."
+ );
+ for (const file of existingFiles) {
+ await expect(readFile(file, "utf8")).resolves.toBe("previous build");
+ }
+ });
+
test("publishes custom headers and refreshes them on incremental builds", async () => {
const projectSettings = {
meta: {
diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts
index 68eabd7a7a..2734cd20a1 100644
--- a/packages/cli/src/prebuild.ts
+++ b/packages/cli/src/prebuild.ts
@@ -73,6 +73,7 @@ import {
createAssetUrlsByPath,
} from "@webstudio-is/project-build/runtime";
import {
+ createBuildContentCompilationPlan,
createPublishedBuildContentCompilationPlan,
getDynamicPublishedMdxSourceBlockIds,
hasDynamicPublishedMdxSources,
@@ -950,6 +951,41 @@ export const prebuild = async (options: {
}
}
+ const loadedSiteData = await loadJSONFile<unknown>(LOCAL_DATA_FILE);
+
+ if (loadedSiteData === null) {
+ throw new Error(
+ `Project bundle is missing, please make sure the project is synced.`
+ );
+ }
+ const parsedSiteData = publishedProjectBundle.safeParse(loadedSiteData);
+ if (parsedSiteData.success === false) {
+ throw Object.assign(
+ new Error(
+ `Project bundle is invalid, please make sure the project is synced. Invalid fields: ${formatZodIssues(
+ parsedSiteData.error.issues,
+ loadedSiteData
+ )}`
+ ),
+ {
+ code: "PROJECT_BUNDLE_INVALID",
+ bundleVersion,
+ issues: getZodValidationIssues(parsedSiteData.error),
+ }
+ );
+ }
+ const siteData = parsedSiteData.data;
+ const pages = migratePages(siteData.build.pages);
+ const publicationBuild = { ...siteData.build, pages };
+ if (
+ siteData.assetIndex === undefined &&
+ createBuildContentCompilationPlan(publicationBuild) !== undefined
+ ) {
+ throw new Error(
+ "Assets queries require a content database. Sync the project again before building."
+ );
+ }
+
feedback.step("Scaffolding the project files");
if (options.incremental !== true) {
@@ -1001,32 +1037,6 @@ export const prebuild = async (options: {
const assetBaseUrl = await readAssetBaseUrl(join(cwd(), "app/constants.mjs"));
- const loadedSiteData = await loadJSONFile<unknown>(LOCAL_DATA_FILE);
-
- if (loadedSiteData === null) {
- throw new Error(
- `Project bundle is missing, please make sure the project is synced.`
- );
- }
- const parsedSiteData = publishedProjectBundle.safeParse(loadedSiteData);
- if (parsedSiteData.success === false) {
- throw Object.assign(
- new Error(
- `Project bundle is invalid, please make sure the project is synced. Invalid fields: ${formatZodIssues(
- parsedSiteData.error.issues,
- loadedSiteData
- )}`
- ),
- {
- code: "PROJECT_BUNDLE_INVALID",
- bundleVersion,
- issues: getZodValidationIssues(parsedSiteData.error),
- }
- );
- }
- const siteData = parsedSiteData.data;
- const pages = migratePages(siteData.build.pages);
- const publicationBuild = { ...siteData.build, pages };
let verifiedAssetIndex =
siteData.assetIndex === undefined
? undefined