Skip to content

Commit c8e81dd

Browse files
committed
fix: use current page patches in release
1 parent 702f5ee commit c8e81dd

5 files changed

Lines changed: 27 additions & 205 deletions

File tree

apps/builder/app/shared/sync/sync-stores.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import { useEffect } from "react";
44
import { batched } from "nanostores";
55
import { nanoid } from "nanoid";
66
import { $project } from "./data-stores";
7-
import {
8-
normalizePagesPatch,
9-
denormalizePagesPatch,
10-
} from "@webstudio-is/project/pages-patch-normalizer";
117
import {
128
$selectedPageHash,
139
$selectedInstanceSizes,

packages/project/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
"./build-patch-core.server": {
4141
"webstudio": "./src/db/build-patch-core.ts",
4242
"import": "./src/db/build-patch-core.ts"
43-
},
44-
"./pages-patch-normalizer": {
45-
"webstudio": "./src/shared/pages-patch-normalizer.ts",
46-
"import": "./src/shared/pages-patch-normalizer.ts"
4743
}
4844
},
4945
"license": "AGPL-3.0-or-later",

packages/project/src/db/build-patch-core.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
serializeData,
3434
} from "@webstudio-is/project-build";
3535
import type { Database } from "@webstudio-is/postgrest/index.server";
36-
import { denormalizePagesPatch } from "../shared/pages-patch-normalizer";
3736

3837
enableMapSet();
3938
enablePatches();
@@ -67,12 +66,6 @@ export const singlePlayerVersionMismatchResult = {
6766
errors: singlePlayerVersionMismatchError,
6867
} as const satisfies BuildPatchUpdateResult;
6968

70-
const denormalizePagesPatches = (patches: Patch[], pages: Pages): Patch[] => {
71-
return denormalizePagesPatch([{ namespace: "pages", patches }], pages, {
72-
onMissing: "throw",
73-
})[0].patches;
74-
};
75-
7669
export const createBuildPatchUpdate = async ({
7770
build,
7871
clientVersion,
@@ -127,13 +120,10 @@ export const createBuildPatchUpdate = async ({
127120
if (namespace === "pages") {
128121
const pages = buildData.pages ?? parsePages(build.pages);
129122
const currentSocialImageAssetId =
130-
pages.homePage.meta.socialImageAssetId;
131-
buildData.pages = applyPatches(
132-
pages,
133-
denormalizePagesPatches(patches, pages)
134-
);
135-
const newSocialImageAssetId =
136-
buildData.pages.homePage.meta.socialImageAssetId;
123+
getHomePage(pages).meta.socialImageAssetId;
124+
buildData.pages = applyPatches(pages, patches);
125+
const newSocialImageAssetId = getHomePage(buildData.pages).meta
126+
.socialImageAssetId;
137127
if (currentSocialImageAssetId !== newSocialImageAssetId) {
138128
previewImageAssetId = newSocialImageAssetId || null;
139129
}

packages/project/src/db/build-patch.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,18 @@ describe("patchBuild", () => {
135135
{
136136
...buildRow,
137137
pages: JSON.stringify({
138-
...JSON.parse(buildRow.pages),
138+
meta: {},
139+
homePageId: "page-1",
140+
rootFolderId: "root",
139141
pages: [
142+
{
143+
id: "page-1",
144+
name: "Home",
145+
path: "",
146+
title: "Home",
147+
meta: {},
148+
rootInstanceId: "body-1",
149+
},
140150
{
141151
id: "page-2",
142152
name: "About",
@@ -146,6 +156,14 @@ describe("patchBuild", () => {
146156
rootInstanceId: "body-1",
147157
},
148158
],
159+
folders: [
160+
{
161+
id: "root",
162+
name: "Root",
163+
slug: "",
164+
children: ["page-1", "page-2"],
165+
},
166+
],
149167
}),
150168
},
151169
])
@@ -169,7 +187,7 @@ describe("patchBuild", () => {
169187
patches: [
170188
{
171189
op: "replace",
172-
path: ["pages", "@page-2", "path"],
190+
path: ["pages", "page-2", "path"],
173191
value: "/company",
174192
},
175193
],
@@ -183,7 +201,9 @@ describe("patchBuild", () => {
183201

184202
expect(result).toEqual({ status: "ok", version: 4 });
185203
expect(
186-
JSON.parse((updatedBuild as { pages: string }).pages).pages[0].path
204+
JSON.parse((updatedBuild as { pages: string }).pages).pages.find(
205+
(page: { id: string }) => page.id === "page-2"
206+
)?.path
187207
).toBe("/company");
188208
});
189209

packages/project/src/shared/pages-patch-normalizer.ts

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)