Skip to content

Commit d5d1fed

Browse files
authored
fix: avoid body when insert section from marketplace (#5329)
We remove body from pages when insert section but I forgot to add a check for body element which replaced Body component for new pages.
1 parent f46095e commit d5d1fed

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

apps/builder/app/builder/features/marketplace/templates.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { ChevronLeftIcon, ExternalLinkIcon } from "@webstudio-is/icons";
1414
import {
1515
elementComponent,
16+
Instance,
1617
ROOT_FOLDER_ID,
1718
type Asset,
1819
type Page,
@@ -33,6 +34,10 @@ import { Card } from "./card";
3334
import type { MarketplaceOverviewItem } from "~/shared/marketplace/types";
3435
import { selectPage } from "~/shared/awareness";
3536

37+
const isBody = (instance: Instance) =>
38+
instance.component === "Body" ||
39+
(instance.component === elementComponent && instance.tag === "body");
40+
3641
/**
3742
* Insert page as a template.
3843
* - Currently only supports inserting everything from the body
@@ -46,17 +51,12 @@ const insertSection = ({
4651
instanceId: string;
4752
}) => {
4853
const fragment = extractWebstudioFragment(data, instanceId);
49-
const body = fragment.instances.find(
50-
(instance) => instance.component === "Body"
51-
);
54+
const body = fragment.instances.find(isBody);
5255
// remove body and use its children as root insrances
5356
if (body) {
54-
fragment.instances = fragment.instances.filter((instance) => {
55-
const isBody =
56-
instance.component === "Body" ||
57-
(instance.component === elementComponent && instance.tag === "body");
58-
return !isBody;
59-
});
57+
fragment.instances = fragment.instances.filter(
58+
(instance) => !isBody(instance)
59+
);
6060
fragment.children = body.children;
6161
}
6262
const insertable = findClosestInsertable(fragment);

0 commit comments

Comments
 (0)