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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: prevent canvas page switch reconciliation errors (#6494)
Oleg Isonen3e310ddae397
diff --git a/apps/builder/app/canvas/canvas.tsx b/apps/builder/app/canvas/canvas.tsxindex a1fb31a854..4925390044 100644--- a/apps/builder/app/canvas/canvas.tsx+++ b/apps/builder/app/canvas/canvas.tsx@@ -331,7 +331,10 @@ export const Canvas = () => {<><GlobalStyles />{/* catch all errors in rendered components */}- <ErrorBoundary FallbackComponent={FallbackComponent}>+ <ErrorBoundary+ key={selectedPage?.id}+ FallbackComponent={FallbackComponent}+ >{elements}</ErrorBoundary>{diff --git a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsxindex c45fcb6a13..6871151712 100644--- a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx+++ b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx@@ -691,6 +691,24 @@ const getUpdatedText = (return visit(rootInstanceId);};+const getCanvasPageChildren = (+ instance: Instance,+ instanceSelector: InstanceSelector,+ children: ReactNode+) => {+ if (+ instanceSelector.length !== 1 ||+ instance.component !== elementComponent ||+ instance.tag !== "body"+ ) {+ return children;+ }++ // React keeps <body> mounted across page changes. Give its authored content+ // one removable host node so teardown does not visit component-mutated DOM.+ return <div style={{ display: "contents" }}>{children}</div>;+};+const WebstudioComponentCanvasInner = forwardRef<HTMLElement,WebstudioComponentProps@@ -838,7 +856,7 @@ const WebstudioComponentCanvasInner = forwardRef<const instanceElement = (<><Component key={key} {...props} ref={ref}>- {children}+ {getCanvasPageChildren(instance, instanceSelector, children)}</Component></>);@@ -1093,14 +1111,18 @@ const WebstudioComponentPreviewInner = forwardRef<const element = (<Component {...props} ref={ref}>- {getTextContent(instanceProps) ??- createInstanceChildrenElements({- instances,- instanceSelector,- children: instance.children,- Component: WebstudioComponentPreview,- components,- })}+ {getCanvasPageChildren(+ instance,+ instanceSelector,+ getTextContent(instanceProps) ??+ createInstanceChildrenElements({+ instances,+ instanceSelector,+ children: instance.children,+ Component: WebstudioComponentPreview,+ components,+ })+ )}</Component>);diff --git a/apps/builder/e2e/tests/pages-actions-pages.[shard-2].[shard-5].[shard-6].e2e.ts b/apps/builder/e2e/tests/pages-actions-pages.[shard-2].[shard-5].[shard-6].e2e.tsindex e9856188fa..a579319c0c 100644--- a/apps/builder/e2e/tests/pages-actions-pages.[shard-2].[shard-5].[shard-6].e2e.ts+++ b/apps/builder/e2e/tests/pages-actions-pages.[shard-2].[shard-5].[shard-6].e2e.ts@@ -1,6 +1,10 @@-import type { Page } from "@playwright/test";+import { expect, type Page } from "@playwright/test";import { expectTextHidden } from "../flows/assertions";-import { openProjectBuilder, waitForCanvasText } from "../flows/builder";+import {+ getCanvasFrame,+ openProjectBuilder,+ waitForCanvasText,+} from "../flows/builder";import { expectGeneratedAppBuild } from "../flows/generated-app";import {createFolder,@@ -19,7 +23,7 @@ import { createContentModeProject } from "../fixtures/content-mode-suite";import type { SeededContentModeProject } from "../fixtures/content-mode-project";import { test, withBrowserContext } from "../test";import { measure } from "../perf";-import { loadDevBuild } from "../db";+import { loadDevBuild, updateBuild } from "../db";let fixture: SeededContentModeProject;let pasteFixture: SeededContentModeProject;@@ -63,6 +67,11 @@ const waitForFolderRow = async ({.waitFor();};+const getTreeButton = ({ page, itemName }: { page: Page; itemName: string }) =>+ page+ .locator("[data-tree-button]")+ .filter({ has: page.getByText(itemName, { exact: true }) });+const waitForTemplate = async ({page,templateName,@@ -70,7 +79,7 @@ const waitForTemplate = async ({page: Page;templateName: string;}) => {- await page.getByText(templateName, { exact: true }).first().waitFor();+ await getTreeButton({ page, itemName: templateName }).waitFor();};const waitForCopiedPageTransferData = async ({ page }: { page: Page }) => {@@ -177,9 +186,7 @@ const selectContextAction = async ({itemName: string;action: "Paste" | "Copy" | "Duplicate" | "Delete";}) => {- await page.getByText(itemName, { exact: true }).first().click({- button: "right",- });+ await getTreeButton({ page, itemName }).click({ button: "right" });await page.getByRole("menuitem", { name: action }).click();};@@ -222,6 +229,95 @@ test.beforeAll(async ({ browser }, workerInfo) => {});});+test("Canvas switches away from text animation without reloading", async ({+ browser,+ page,+}, workerInfo) => {+ const animationFixture = await withBrowserContext(browser, (context) =>+ createContentModeProject({+ context,+ email: `pages-animation-${workerInfo.parallelIndex}@webstudio.test`,+ title: "Animated Page Switch E2E",+ assetNamePrefix: `pages-animation-${workerInfo.parallelIndex}-`,+ editorToken: `pages-animation-${workerInfo.parallelIndex}-editor-token`,+ builderToken: `pages-animation-${workerInfo.parallelIndex}-builder-token`,+ })+ );+ const build = await loadDevBuild({ projectId: animationFixture.projectId });+ const instances = JSON.parse(build.instances) as Array<{+ type: "instance";+ id: string;+ component: string;+ tag?: string;+ children: Array<{ type: "id" | "text"; value: string }>;+ }>;+ const templateRoot = instances.find(+ (instance) => instance.id === "content-page-template-root"+ );+ if (templateRoot === undefined) {+ throw new Error("Expected page template root");+ }+ templateRoot.children.push({ type: "id", value: "animated-children" });+ instances.push(+ {+ type: "instance",+ id: "animated-children",+ component: "@webstudio-is/sdk-components-animation:AnimateChildren",+ children: [{ type: "id", value: "animated-text" }],+ },+ {+ type: "instance",+ id: "animated-text",+ component: "@webstudio-is/sdk-components-animation:AnimateText",+ children: [{ type: "id", value: "animated-inner" }],+ },+ {+ type: "instance",+ id: "animated-inner",+ component: "ws:element",+ tag: "div",+ children: [{ type: "id", value: "animated-span" }],+ },+ {+ type: "instance",+ id: "animated-span",+ component: "ws:element",+ tag: "span",+ children: [{ type: "text", value: "Animated page text" }],+ }+ );+ await updateBuild(build.id, { instances: JSON.stringify(instances) });++ await openProjectBuilder({+ page,+ projectId: animationFixture.projectId,+ authToken: animationFixture.builderToken,+ });+ await createPageFromTemplate({+ page,+ templateName: animationFixture.pageTemplateName,+ pageName: "Animated Page",+ canvasText: "Animated page text",+ });+ const canvas = await getCanvasFrame(page);+ if (canvas === undefined) {+ throw new Error("Expected canvas frame");+ }+ await canvas.locator("[data-ws-text-animate]").first().waitFor();+ await openPage({+ page,+ pageName: "Home",+ canvasText: animationFixture.shareLinkEditableText,+ });+ expect(await getCanvasFrame(page)).toBe(canvas);+ await openPage({+ page,+ pageName: "Animated Page",+ canvasText: "Animated page text",+ });+ expect(await getCanvasFrame(page)).toBe(canvas);+});+test("Builder can draft, stage, copy, duplicate, and delete a page from the header menu", async ({page,}) => {@@ -309,11 +405,21 @@ test("Builder can draft, stage, copy, duplicate, and delete a page from the headawait pasteFromClipboardShortcut({ page });await waitForPageRow({ page, pageName: copiedPageName });+ const previousCanvas = await getCanvasFrame(page);+ if (previousCanvas === undefined) {+ throw new Error("Expected canvas before switching pages");+ }+ // Reproduce a component changing React-owned DOM before page teardown.+ await previousCanvas+ .getByText(fixture.pageTemplateText, { exact: true })+ .first()+ .evaluate((element) => element.remove());await openPage({page,pageName: copiedPageName,canvasText: fixture.pageTemplateText,});+ expect(await getCanvasFrame(page)).toBe(previousCanvas);await openPageSettings({ page, pageName: renamedPageName });await selectHeaderAction({diff --git a/apps/builder/e2e/tests/preview-links.[shard-1].e2e.ts b/apps/builder/e2e/tests/preview-links.[shard-1].e2e.tsindex 1c4d821cd7..e9bfe399e4 100644--- a/apps/builder/e2e/tests/preview-links.[shard-1].e2e.ts+++ b/apps/builder/e2e/tests/preview-links.[shard-1].e2e.ts@@ -1,5 +1,9 @@-import type { Locator } from "@playwright/test";-import { openBuilderUrl, waitForCanvasFrame } from "../flows/builder";+import { expect, type Locator } from "@playwright/test";+import {+ getCanvasFrame,+ openBuilderUrl,+ waitForCanvasFrame,+} from "../flows/builder";import {expectGeneratedAppNavigation,expectGeneratedAppToRender,@@ -343,7 +347,9 @@ test("Preview links expose current page state for components and element anchorsactive: false,});+ const previousCanvas = canvas;await canvas.getByRole("link", { name: previewLinkText.pageLink }).click();+ expect(await getCanvasFrame(page)).toBe(previousCanvas);canvas = await waitForCanvasFrame({ page });await expectActiveLink({canvas,diff --git a/packages/sdk-components-animation/private-src b/packages/sdk-components-animation/private-srcindex 59b1be51fd..008dd3e92a 160000--- a/packages/sdk-components-animation/private-src+++ b/packages/sdk-components-animation/private-src@@ -1 +1 @@-Subproject commit 59b1be51fdf13cef4355aedfb104f97922402fef+Subproject commit 008dd3e92a4d28605151d5111fd611653830e874