Skip to content

Commit fa875ab

Browse files
authored
feat: use body element on new pages (#5222)
Ref #3632 Now new project and new page will have body element in the root instead of body component. <img width="422" alt="Screenshot 2025-05-20 at 00 15 37" src="https://github.com/user-attachments/assets/aee568c5-f0e4-40f5-a5a3-e94fc765505d" />
1 parent b50e053 commit fa875ab

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@webstudio-is/design-system";
1313
import { ChevronLeftIcon, ExternalLinkIcon } from "@webstudio-is/icons";
1414
import {
15+
elementComponent,
1516
ROOT_FOLDER_ID,
1617
type Asset,
1718
type Page,
@@ -50,9 +51,12 @@ const insertSection = ({
5051
);
5152
// remove body and use its children as root insrances
5253
if (body) {
53-
fragment.instances = fragment.instances.filter(
54-
(instance) => instance.component !== "Body"
55-
);
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+
});
5660
fragment.children = body.children;
5761
}
5862
const insertable = findClosestInsertable(fragment);

apps/builder/app/builder/features/pages/page-settings.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
isLiteralExpression,
3030
documentTypes,
3131
isRootFolder,
32+
elementComponent,
3233
} from "@webstudio-is/sdk";
3334
import {
3435
theme,
@@ -1307,7 +1308,8 @@ const createPage = (pageId: Page["id"], values: Values) => {
13071308
instances.set(rootInstanceId, {
13081309
type: "instance",
13091310
id: rootInstanceId,
1310-
component: "Body",
1311+
component: elementComponent,
1312+
tag: "body",
13111313
children: [],
13121314
});
13131315
registerFolderChildMutable(pages.folders, pageId, values.parentFolderId);

apps/builder/app/builder/features/settings-panel/controls/tag-control.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export const TagControl = ({ meta, prop }: ControlProps<"tag">) => {
4646
const instanceTag = instance?.tag;
4747
const defaultTag = meta.options[0];
4848
const computedTag = instanceTag ?? propTag ?? defaultTag;
49-
const satisfyingTags = useStore($satisfyingTags);
49+
let satisfyingTags = useStore($satisfyingTags);
50+
// forbid changing tag on body element
51+
if (computedTag === "body") {
52+
satisfyingTags = ["body"];
53+
}
5054
const options = meta.options.filter((tag) => satisfyingTags.includes(tag));
5155
const [value, setValue] = useState<undefined | string>();
5256
const updateTag = (value: string) => {

apps/builder/app/canvas/canvas.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import { subscribeSelected } from "./instance-selected";
7171
import { subscribeScrollNewInstanceIntoView } from "./shared/scroll-new-instance-into-view";
7272
import { $selectedPage } from "~/shared/awareness";
7373
import { createInstanceElement } from "./elements";
74-
import { Body } from "./shared/body";
7574
import { subscribeScrollbarSize } from "./scrollbar-width";
7675
import { compareMedia } from "@webstudio-is/css-engine";
7776
import { builderApi } from "~/shared/builder-api";
@@ -248,15 +247,6 @@ export const Canvas = () => {
248247
hooks: baseComponentHooks,
249248
templates: baseComponentTemplates,
250249
});
251-
registerComponentLibrary({
252-
components: {
253-
// override only canvas specific body component
254-
// not related to sdk-components-react-remix anymore
255-
Body,
256-
},
257-
metas: {},
258-
templates: {},
259-
});
260250
registerComponentLibrary({
261251
namespace: "@webstudio-is/sdk-components-react-radix",
262252
components: radixComponents,
@@ -321,7 +311,7 @@ export const Canvas = () => {
321311
}, []);
322312

323313
if (components.size === 0 || instances.size === 0) {
324-
return <Body />;
314+
return;
325315
}
326316

327317
return (

apps/builder/app/canvas/shared/body.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/builder/app/routes/_canvas.canvas.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { lazy } from "react";
2-
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
2+
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
3+
import { Scripts, ScrollRestoration } from "@remix-run/react";
34
import { isCanvas } from "~/shared/router-utils";
45
import { ClientOnly } from "~/shared/client-only";
5-
import { Body } from "~/canvas/shared/body";
66

77
export { ErrorBoundary } from "~/shared/error/error-boundary";
88

@@ -22,7 +22,16 @@ const Canvas = lazy(async () => {
2222

2323
const CanvasRoute = () => {
2424
return (
25-
<ClientOnly fallback={<Body />}>
25+
// this setup remix scripts on canvas and after rendering a website
26+
// scripts will continue to work even though removed from dom
27+
<ClientOnly
28+
fallback={
29+
<body>
30+
<Scripts />
31+
<ScrollRestoration />
32+
</body>
33+
}
34+
>
2635
<Canvas />
2736
</ClientOnly>
2837
);

packages/project-build/src/db/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
type StyleDecl,
2121
Pages,
2222
initialBreakpoints,
23+
elementComponent,
2324
} from "@webstudio-is/sdk";
2425
import type { Build, CompactBuild } from "../types";
2526
import { parseDeployment } from "./deployment";
@@ -229,7 +230,8 @@ const createNewPageInstances = (): Build["instances"] => {
229230
{
230231
type: "instance",
231232
id: instanceId,
232-
component: "Body",
233+
component: elementComponent,
234+
tag: "body",
233235
children: [],
234236
},
235237
],

0 commit comments

Comments
 (0)