From aeb34e3c708a443142f3e3d3e737fc79e6e9f162 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Tue, 17 Nov 2026 17:05:31 +0000 Subject: [PATCH] fix: Show origin-based resource data in canvas (#6710) A resource using `system.origin` can show the right value in Settings while Canvas and Preview stay empty. Canvas needs the same published host as Builder to find the cached resource response. This PR targets `main` from `org.staging`. It does not change stored project data or the published runtime. ## Plan and verification - [x] Apply the minimal host synchronization fix on top of `main`. - [x] Confirm the regression test fails before the fix and passes afterward. - [x] Run 97 focused tests, Builder typecheck, lint, format, and package-boundary checks on `main`. - [x] Check the staging behavior with a real shared project (confirmed by the reporter). - [x] Run a local database-backed Builder and Canvas check with a non-default publisher host (passed). - [x] Review documentation impact: existing behavior is restored; no docs update needed. - [x] Review fixture impact: the current `main` merge supplied the required E2E schema snapshot; no fixture change is needed in this PR. - [ ] Stabilize the two publish tests that failed in the full CI suite after the `main` merge. - [ ] Required PR checks pass. The local full Builder core suite also reported unrelated style and form test failures under parallel load; the focused publish tests passed. The PR run is the final verification for the CI test fix. Ref #3343 --- .../publish/publish-session.render.test.tsx | 18 +++++++++++++----- .../features/publish/publish-static.test.tsx | 4 +++- .../app/shared/nano-states/props.test.tsx | 15 +++++++++++---- apps/builder/app/shared/sync/sync-stores.ts | 3 ++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/builder/app/builder/features/publish/publish-session.render.test.tsx b/apps/builder/app/builder/features/publish/publish-session.render.test.tsx index 6e5e17498a..57eb67dc90 100644 --- a/apps/builder/app/builder/features/publish/publish-session.render.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-session.render.test.tsx @@ -245,12 +245,20 @@ const publish = async () => { document.body.querySelector('[role="checkbox"]')?.click() ); } - const button = Array.from( - domain!.closest("form")!.querySelectorAll("button") - ).at(-1)!; - await waitFor(() => expect(button.disabled).toBe(false)); + const getButton = () => + Array.from( + document.body + .querySelector('input[name="domainToPublish[]"]') + ?.closest("form") + ?.querySelectorAll("button") ?? [] + ).at(-1); + await waitFor(() => expect(getButton()?.disabled).toBe(false)); const previousRequests = publishRequests; - await act(async () => button.click()); + await act(async () => { + const button = getButton(); + expect(button).toBeDefined(); + button?.click(); + }); await waitFor(() => expect(publishRequests).toBe(previousRequests + 1)); }; const openReport = async () => { diff --git a/apps/builder/app/builder/features/publish/publish-static.test.tsx b/apps/builder/app/builder/features/publish/publish-static.test.tsx index 5db7be3e58..4b667cfcba 100644 --- a/apps/builder/app/builder/features/publish/publish-static.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-static.test.tsx @@ -307,12 +307,14 @@ test("the static failure alert opens an audit rejection instead of an older succ await act(async () => {}); expect(downloads).toHaveBeenCalledOnce(); expect(staticButton()?.dataset.state).not.toBe("pending"); + expect(staticButton()?.disabled).toBe(false); }); staticResponse = { success: false, auditFindings: [{ severity: "error", message: "audit-rejection" }], }; await act(async () => staticButton()?.click()); + await waitFor(() => expect(publishRequests).toBe(2)); const activeTab = () => document.body.querySelector('[role="tab"][aria-selected="true"]') ?.textContent; @@ -343,4 +345,4 @@ test("the static failure alert opens an audit rejection instead of an older succ ?.click() ); expect(activeTab()).toBe("Errors"); -}); +}, 30_000); diff --git a/apps/builder/app/shared/nano-states/props.test.tsx b/apps/builder/app/shared/nano-states/props.test.tsx index d9e779a244..5f67aff441 100644 --- a/apps/builder/app/shared/nano-states/props.test.tsx +++ b/apps/builder/app/shared/nano-states/props.test.tsx @@ -20,6 +20,7 @@ import { $dataSources, $props, $resources, + $publisherHost, } from "../sync/data-stores"; import { $propValuesByInstanceSelector, @@ -39,7 +40,7 @@ import { ws, } from "@webstudio-is/template"; import { $systemDataByPage, updateCurrentSystem } from "../system"; -import { registerContainers } from "../sync/sync-stores"; +import { createObjectPool, registerContainers } from "../sync/sync-stores"; import { $resourcesCache, getResourceKey } from "../resources"; import { $externalContentRoots } from "../external-content-mutations"; @@ -107,6 +108,7 @@ afterEach(() => { unsubscribeResourceRequestPlan?.(); unsubscribeResourceRequestPlan = undefined; resourceRequests = []; + $publisherHost.set("wstd.work"); }); test("provides occurrence frontmatter to a repeated Content Block", async () => { @@ -862,7 +864,7 @@ test("access parameter value from variables values", async () => { ); }); -test("compute props bound to resource variables", async () => { +test("compute props bound to resources using the synced published origin", async () => { $instances.set( toMap([{ id: "body", type: "instance", component: "Body", children: [] }]) ); @@ -884,7 +886,7 @@ test("compute props bound to resource variables", async () => { { id: "resourceId", name: "my-resource", - url: `""`, + url: "$ws$system.origin", method: "get", headers: [], }, @@ -892,12 +894,17 @@ test("compute props bound to resource variables", async () => { ); const key = getResourceKey({ name: "my-resource", - url: "", + url: "https://undefined.wstd.io", method: "get", headers: [], searchParams: [], }); $resourcesCache.set(new Map([[key, "my-value"]])); + createObjectPool().applyTransaction({ + id: "published-host", + object: "publisherHost", + payload: "wstd.io", + }); $props.set( toMap([ { diff --git a/apps/builder/app/shared/sync/sync-stores.ts b/apps/builder/app/shared/sync/sync-stores.ts index 3bca9cc157..627d9df75d 100644 --- a/apps/builder/app/shared/sync/sync-stores.ts +++ b/apps/builder/app/shared/sync/sync-stores.ts @@ -3,7 +3,7 @@ import { enableMapSet, setAutoFreeze } from "immer"; import { useEffect } from "react"; import { batched } from "nanostores"; import { createId } from "@webstudio-is/sdk"; -import { $project } from "./data-stores"; +import { $project, $publisherHost } from "./data-stores"; import { $selectedPageHash, $selectedInstanceSizes, @@ -345,6 +345,7 @@ export const createObjectPool = () => { new NanostoresSyncObject("temporaryInstances", $temporaryInstances), new NanostoresSyncObject("project", $project), + new NanostoresSyncObject("publisherHost", $publisherHost), new NanostoresSyncObject("dataSourceVariables", $dataSourceVariables), new NanostoresSyncObject("resourcesCache", $resourcesCache), new NanostoresSyncObject("resourcesState", $resourcesState),