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: retain MDX identity in runtime asset queries (#6495)

Oleg Isonenac75dcdd730c
diff --git a/packages/content-engine/src/asset-index.test.ts b/packages/content-engine/src/asset-index.test.ts
index 2775d7148f..9347ab8b16 100644
--- a/packages/content-engine/src/asset-index.test.ts
+++ b/packages/content-engine/src/asset-index.test.ts
@@ -128,6 +128,60 @@ describe("shared asset index", () => {
).resolves.toMatchObject({ items: [{ id: "alpha" }] });
});
+ test("keeps MDX source identity for runtime queries without content", async () => {
+ const mdxDocument = {
+ ...entry({ id: "article" }).document,
+ name: "article.mdx",
+ path: "articles/article.mdx",
+ extension: "mdx",
+ mimeType: "text/mdx",
+ revision: "article-revision",
+ contentRef: "articles/article.mdx",
+ properties: { title: "Article" },
+ };
+ const query = assetQuery.parse({
+ where: { all: [{ field: ["extension"], operator: "eq", value: "mdx" }] },
+ limit: 1,
+ output: {
+ mode: "fields",
+ includeMetadata: false,
+ fields: [["properties", "title"]],
+ },
+ content: { mode: "none" },
+ });
+ const plan = createContentCompilationPlan([
+ {
+ ...createLiteralContentCompilationQuery({ id: "article", query }),
+ limit: { type: "dynamic" },
+ },
+ ]);
+ if (plan === undefined) {
+ throw new Error("Expected a dynamic content compilation plan");
+ }
+
+ const artifact = await createAssetIndex({
+ projectId: "project",
+ entries: [
+ createCanonicalAssetFileEntry({
+ projectId: "project",
+ document: mdxDocument,
+ }),
+ ],
+ plan,
+ });
+
+ expect(artifact.documents).toMatchObject([
+ {
+ _id: "article",
+ extension: "mdx",
+ revision: "article-revision",
+ contentRef: "articles/article.mdx",
+ properties: { title: "Article" },
+ },
+ ]);
+ expect(artifact.contents).toBeUndefined();
+ });
+
test("materializes a static overview query without storing candidate documents", async () => {
const posts = [
{
diff --git a/packages/content-engine/src/compilation-plan.ts b/packages/content-engine/src/compilation-plan.ts
index 2d903aa300..b128b0f69a 100644
--- a/packages/content-engine/src/compilation-plan.ts
+++ b/packages/content-engine/src/compilation-plan.ts
@@ -649,7 +649,8 @@ export const projectContentDatabaseDocument = ({
if (plan === undefined) {
return document;
}
- const includeContentIdentity = requiresHydratedContent(plan);
+ const includeContentIdentity =
+ requiresHydratedContent(plan) || document.extension.toLowerCase() === "mdx";
const properties =
plan.structuredPropertyPaths === "all"
? document.properties
@@ -661,7 +662,9 @@ export const projectContentDatabaseDocument = ({
_id: document._id,
...selectAssetDocumentFields({
document,
- includes: (field) => hasField(plan.standardFields, field),
+ includes: (field) =>
+ hasField(plan.standardFields, field) ||
+ (includeContentIdentity && field === "revision"),
}),
...(includeContentIdentity ? { contentRef: document.contentRef } : {}),
...(plan.structuredPropertyPaths === "all" ||