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: Preserve Global root tokens when importing templates (#6348)
Oleg Isonen13952a7d3404
diff --git a/apps/builder/e2e/tests/mdx-content-block.[shard-4].e2e.ts b/apps/builder/e2e/tests/mdx-content-block.[shard-4].e2e.tsindex 0a8b102c76..ef4ebd556c 100644--- a/apps/builder/e2e/tests/mdx-content-block.[shard-4].e2e.ts+++ b/apps/builder/e2e/tests/mdx-content-block.[shard-4].e2e.ts@@ -491,6 +491,15 @@ test("Empty MDX content supports slash menu keyboard and mouse insertion", asyncauthToken: fixture.editorToken,mode: "content",});+ const revisionPatches: string[] = [];+ page.on("request", (request) => {+ if (request.url().includes("/trpc/build.patch")) {+ const body = request.postData() ?? "";+ if (body.includes('"namespace":"assets"')) {+ revisionPatches.push(body);+ }+ }+ });await insertTemplateIntoEmptyContentBlock({page,templateName: "Empty Heading Template",@@ -607,6 +616,12 @@ test("Empty MDX content supports slash menu keyboard and mouse insertion", async}await page.mouse.click(5, 5);const finalSource = (await finalWrite).request().postData() ?? "";+ await waitForSyncStatus({ page, status: "idle" });+ if (revisionPatches.length > 0) {+ throw new Error(+ "Saved MDX revisions must not be persisted again by build.patch"+ );+ }const expectedContentOrder = ["# First heading","Keyboard anchor",diff --git a/packages/project-build/src/runtime/style-copy.test.ts b/packages/project-build/src/runtime/style-copy.test.tsindex a96b11e0fe..4b8db674b3 100644--- a/packages/project-build/src/runtime/style-copy.test.ts+++ b/packages/project-build/src/runtime/style-copy.test.ts@@ -310,6 +310,87 @@ describe("style source insertion", () => {]);});+ test.each([+ { incoming: [], expected: ["first-token", "second-token", "root-local"] },+ {+ incoming: ["incoming-local"],+ expected: ["first-token", "second-token", "root-local"],+ },+ {+ incoming: ["incoming-token"],+ expected: ["first-token", "second-token", "root-local", "mapped-token"],+ },+ {+ incoming: ["incoming-token", "reused-token", "incoming-local"],+ expected: ["first-token", "second-token", "root-local", "mapped-token"],+ },+ ])(+ "preserves root sources when importing $incoming",+ ({ incoming, expected }) => {+ const styleSources = toMap([+ token("first-token", "Spacing"),+ token("second-token", "Colors"),+ token("mapped-token", "Imported"),+ local("root-local"),+ ]);+ const styleSourceSelections: StyleSourceSelections = new Map([+ [+ ROOT_INSTANCE_ID,+ {+ instanceId: ROOT_INSTANCE_ID,+ values: ["first-token", "second-token", "root-local"],+ },+ ],+ ]);+ const originalStyle = style("root-local", "base", "color", blue);+ const styles = styleMap([originalStyle]);+ const incomingStyles = incoming.includes("incoming-local")+ ? [style("incoming-local", "incoming-base", "backgroundColor", red)]+ : [];++ // Repeated page imports must not detach sources or duplicate selections.+ for (let index = 0; index < 2; index += 1) {+ insertLocalStyleSourcesWithNewIds({+ fragmentStyleSources: [+ local("incoming-local"),+ token("incoming-token", "Imported"),+ token("reused-token", "Spacing"),+ ],+ fragmentStyleSourceSelections: [+ { instanceId: ROOT_INSTANCE_ID, values: incoming },+ ],+ fragmentStyles: incomingStyles,+ fragmentInstanceIds: new Set([ROOT_INSTANCE_ID]),+ newInstanceIds: new Map([[ROOT_INSTANCE_ID, ROOT_INSTANCE_ID]]),+ styleSources,+ styleSourceSelections,+ styles,+ styleSourceIdMap: new Map([+ ["incoming-token", "mapped-token"],+ ["reused-token", "first-token"],+ ]),+ mergedBreakpointIds: new Map([["incoming-base", "base"]]),+ });++ expect(styleSourceSelections.get(ROOT_INSTANCE_ID)?.values).toEqual(+ expected+ );+ expect(styles.get(getStyleDeclKey(originalStyle))).toEqual(+ originalStyle+ );+ if (incomingStyles.length > 0) {+ const mergedStyle = style(+ "root-local",+ "base",+ "backgroundColor",+ red+ );+ expect(styles.get(getStyleDeclKey(mergedStyle))).toEqual(mergedStyle);+ }+ }+ }+ );+test("copies local style sources with new ids and maps selections", () => {const styleSources: StyleSources = new Map([["existing-token", token("existing-token", "Primary")],diff --git a/packages/project-build/src/runtime/style-copy.ts b/packages/project-build/src/runtime/style-copy.tsindex c97db5da1e..6d4178e3ec 100644--- a/packages/project-build/src/runtime/style-copy.ts+++ b/packages/project-build/src/runtime/style-copy.ts@@ -700,7 +700,14 @@ export const insertLocalStyleSourcesWithNewIds = ({}styleSourceSelections.set(targetInstanceId, {instanceId: targetInstanceId,- values: newStyleSourceIds,+ // Global root is shared by every page, so importing a fragment must+ // preserve its existing tokens and their cascade order.+ values:+ contentMode === false && instanceId === ROOT_INSTANCE_ID+ ? Array.from(+ new Set([...existingStyleSourceIds, ...newStyleSourceIds])+ )+ : newStyleSourceIds,});}