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: publish projects with legacy settings (#6480)

Oleg Isonen8e4c080d95d1
diff --git a/packages/project-build/src/db/build.test.ts b/packages/project-build/src/db/build.test.ts
index f69f43fdf1..48061ede9b 100644
--- a/packages/project-build/src/db/build.test.ts
+++ b/packages/project-build/src/db/build.test.ts
@@ -401,6 +401,63 @@ describe("createBuild (msw)", () => {
// ---------------------------------------------------------------------------
describe("createProductionBuild (msw)", () => {
+ test.each([
+ { label: "without custom headers", headers: [], denied: false },
+ {
+ label: "with custom headers on a Free plan",
+ headers: [{ name: "X-Frame-Options", value: "DENY" }],
+ denied: true,
+ },
+ ])(
+ "reads legacy settings from the saved snapshot $label",
+ async ({ headers, denied }) => {
+ const removeBuild = vi.fn(() => empty({ status: 204 }));
+ server.use(
+ db.get("Project", () =>
+ json({
+ id: "proj-1",
+ userId: "project-owner",
+ domain: "project-domain",
+ })
+ ),
+ db.get("Build", ({ request }) => {
+ // Use the saved snapshot's legacy settings, even when the development
+ // build read before snapshot creation had different settings.
+ if (new URL(request.url).searchParams.get("id") === "eq.build-prod") {
+ return json([
+ {
+ projectSettings: null,
+ pages: JSON.stringify({
+ ...JSON.parse(buildRow.pages),
+ meta: { siteName: "Legacy site", customHeaders: headers },
+ }),
+ },
+ ]);
+ }
+ return json([buildRow]);
+ }),
+ db.post("rpc/create_production_build", () => json("build-prod")),
+ db.delete("Build", removeBuild)
+ );
+ const result = createProductionBuild(
+ {
+ projectId: "proj-1",
+ deployment: { destination: "saas", domains: ["example.com"] },
+ },
+ createContext()
+ );
+ if (denied) {
+ await expect(result).rejects.toThrow(
+ "Custom headers are a Pro feature"
+ );
+ expect(removeBuild).toHaveBeenCalledOnce();
+ } else {
+ await expect(result).resolves.toEqual({ id: "build-prod" });
+ expect(removeBuild).not.toHaveBeenCalled();
+ }
+ }
+ );
+
test.each([
{
label: "Free owner, custom domain",
@@ -583,7 +640,9 @@ describe("createProductionBuild (msw)", () => {
const url = new URL(request.url);
if (url.searchParams.get("id") === "eq.build-prod") {
readSnapshot();
- expect(url.searchParams.get("select")).toBe("projectSettings");
+ expect(url.searchParams.get("select")).toBe(
+ "projectSettings,pages"
+ );
return json([
{
projectSettings: JSON.stringify({
diff --git a/packages/project-build/src/db/build.ts b/packages/project-build/src/db/build.ts
index 1fa5fdf871..3430e6cc38 100644
--- a/packages/project-build/src/db/build.ts
+++ b/packages/project-build/src/db/build.ts
@@ -447,7 +447,7 @@ export const createProductionBuild = async (
// the Pro requirement. The caller publishes only after this check passes.
const snapshot = await context.postgrest.client
.from("Build")
- .select("projectSettings")
+ .select("projectSettings,pages")
.eq("id", buildId);
if (snapshot.error) {
throw snapshot.error;
@@ -455,9 +455,16 @@ export const createProductionBuild = async (
if (snapshot.data.length !== 1) {
throw new Error("Cannot verify published response headers");
}
- const settings = parseProjectSettings(
- parseConfig<unknown>(snapshot.data[0].projectSettings)
- );
+ const savedBuild = snapshot.data[0];
+ const settings =
+ savedBuild.projectSettings === undefined ||
+ savedBuild.projectSettings === null
+ ? createProjectSettingsFromPages(
+ migratePages(parseConfig<unknown>(savedBuild.pages))
+ )
+ : parseProjectSettings(
+ parseConfig<unknown>(savedBuild.projectSettings)
+ );
if (!hasCustomResponseHeaders(settings.meta.customHeaders)) {
return { id: buildId };
}