Skip to content

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.

refactor: add page link to basic fixture (#3769)

Bogdan Chadkinc60e55feea47
diff --git a/fixtures/webstudio-cloudflare-template/.webstudio/data.json b/fixtures/webstudio-cloudflare-template/.webstudio/data.json
index bb2309af90..41f94ebc32 100644
--- a/fixtures/webstudio-cloudflare-template/.webstudio/data.json
+++ b/fixtures/webstudio-cloudflare-template/.webstudio/data.json
@@ -1,35 +1,59 @@
{
"build": {
- "id": "6ee09eba-d953-48c0-8ca7-77b5d8f0dff1",
+ "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
- "version": 21,
- "createdAt": "2024-02-01T08:34:11.957Z",
- "updatedAt": "2024-02-01T08:34:11.957Z",
+ "version": 29,
+ "createdAt": "2024-07-21T11:48:14.097",
+ "updatedAt": "2024-07-21T11:48:14.097",
"pages": {
"meta": {
"siteName": "",
"faviconAssetId": "",
"code": ""
},
- "settings": {
- "atomicStyles": false
- },
"homePage": {
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
- "pages": [],
+ "pages": [
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
+ }
+ ],
"folders": [
{
"id": "root",
"name": "Root",
"slug": "",
- "children": ["9di_L14CzctvSruIoKVvE"]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -114,6 +138,19 @@
"value": "column"
}
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp:rKj-wYctg3-GnqL3WHN9I:marginBottom:",
+ {
+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",
+ "styleSourceId": "0KA68BwP9gdTzE1ESO2Zp",
+ "property": "marginBottom",
+ "value": {
+ "type": "unit",
+ "unit": "em",
+ "value": 1
+ }
+ }
]
],
"styleSources": [
@@ -123,6 +160,13 @@
"type": "local",
"id": "7_QL45cpvP-zG8Hkgf4cr"
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp",
+ {
+ "type": "local",
+ "id": "0KA68BwP9gdTzE1ESO2Zp"
+ }
]
],
"styleSourceSelections": [
@@ -132,17 +176,44 @@
"instanceId": "MMimeobf_zi4ZkRGXapju",
"values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
+ ],
+ [
+ "BMJfjOzunWs8XkQgvvx1e",
+ {
+ "instanceId": "BMJfjOzunWs8XkQgvvx1e",
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
+ }
+ ]
+ ],
+ "props": [
+ [
+ "1p34InvRgqoKVqeNZ1uBb",
+ {
+ "id": "1p34InvRgqoKVqeNZ1uBb",
+ "instanceId": "pjkZo5EiBqaeUXBcyHf_O",
+ "name": "href",
+ "type": "page",
+ "value": "WPPAbLFyJD_02vhjRd8P4"
+ }
]
],
- "props": [],
"dataSources": [
[
- "HdKSzlJZasGmZlW8b-va0",
+ "2KT4-bRzToj9cAGAN_woK",
{
- "id": "HdKSzlJZasGmZlW8b-va0",
+ "type": "parameter",
+ "id": "2KT4-bRzToj9cAGAN_woK",
"scopeInstanceId": "MMimeobf_zi4ZkRGXapju",
- "name": "system",
- "type": "parameter"
+ "name": "system"
+ }
+ ],
+ [
+ "tdXe9gFf83hSo9BLWU6xl",
+ {
+ "type": "parameter",
+ "id": "tdXe9gFf83hSo9BLWU6xl",
+ "scopeInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "name": "system"
}
]
],
@@ -162,6 +233,10 @@
{
"type": "id",
"value": "BMJfjOzunWs8XkQgvvx1e"
+ },
+ {
+ "type": "id",
+ "value": "pjkZo5EiBqaeUXBcyHf_O"
}
]
}
@@ -193,6 +268,48 @@
}
]
}
+ ],
+ [
+ "pjkZo5EiBqaeUXBcyHf_O",
+ {
+ "type": "instance",
+ "id": "pjkZo5EiBqaeUXBcyHf_O",
+ "component": "Link",
+ "children": [
+ {
+ "type": "text",
+ "value": "Test another page link"
+ }
+ ]
+ }
+ ],
+ [
+ "n_VBMr7klpx25buS0NV7R",
+ {
+ "type": "instance",
+ "id": "n_VBMr7klpx25buS0NV7R",
+ "component": "Body",
+ "children": [
+ {
+ "type": "id",
+ "value": "wthNByqb3RPmheb-56VYI"
+ }
+ ]
+ }
+ ],
+ [
+ "wthNByqb3RPmheb-56VYI",
+ {
+ "type": "instance",
+ "id": "wthNByqb3RPmheb-56VYI",
+ "component": "Heading",
+ "children": [
+ {
+ "type": "text",
+ "value": "Another page"
+ }
+ ]
+ }
]
],
"deployment": {
@@ -205,20 +322,46 @@
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
"pages": [
{
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
+ },
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
}
],
"assets": [],
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts
index 80e6d6e474..af4f4e6a39 100644
--- a/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/$resources.sitemap.xml.ts
@@ -1,6 +1,6 @@
export const sitemap = [
{
path: "/",
- lastModified: "2024-02-01",
+ lastModified: "2024-07-21",
},
];
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx
new file mode 100644
index 0000000000..134adccf84
--- /dev/null
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.server.tsx
@@ -0,0 +1,40 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import type { PageMeta } from "@webstudio-is/sdk";
+import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";
+export const loadResources = async (_props: { system: System }) => {
+ return {} as Record<string, unknown>;
+};
+
+export const getPageMeta = ({
+ system,
+ resources,
+}: {
+ system: System;
+ resources: Record<string, any>;
+}): PageMeta => {
+ return {
+ title: "Another page",
+ description: "",
+ excludePageFromSearch: true,
+ language: "",
+ socialImageAssetName: undefined,
+ socialImageUrl: "",
+ status: 200,
+ redirect: "",
+ custom: [],
+ };
+};
+
+type FormProperties = { method?: string; action?: string };
+export const formsProperties = new Map<string, FormProperties>([]);
+
+type Params = Record<string, string | undefined>;
+export const getRemixParams = ({ ...params }: Params): Params => {
+ return params;
+};
+
+export const projectId = "d845c167-ea07-4875-b08d-83e97c09dcce";
+
+export const contactEmail = "[email protected]";
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx
new file mode 100644
index 0000000000..7cf0971d61
--- /dev/null
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/[another-page]._index.tsx
@@ -0,0 +1,29 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import { Fragment, useState } from "react";
+import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
+import { useResource } from "@webstudio-is/react-sdk";
+import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import { Heading as Heading } from "@webstudio-is/sdk-components-react";
+
+export const siteName = "";
+
+export const favIconAsset: ImageAsset | undefined = undefined;
+
+// Font assets on current page (can be preloaded)
+export const pageFontAssets: FontAsset[] = [];
+
+export const pageBackgroundImageAssets: ImageAsset[] = [];
+
+const Page = ({}: { system: any }) => {
+ return (
+ <Body data-ws-id="n_VBMr7klpx25buS0NV7R" data-ws-component="Body">
+ <Heading data-ws-id="wthNByqb3RPmheb-56VYI" data-ws-component="Heading">
+ {"Another page"}
+ </Heading>
+ </Body>
+ );
+};
+
+export { Page };
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
index f8d7aae4e1..3ceab9547b 100644
--- a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx
@@ -4,7 +4,10 @@
import { Fragment, useState } from "react";
import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
import { useResource } from "@webstudio-is/react-sdk";
-import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import {
+ Body as Body,
+ Link as Link,
+} from "@webstudio-is/sdk-components-react-remix";
import {
Heading as Heading,
Text as Text,
@@ -33,9 +36,20 @@ const Page = ({}: { system: any }) => {
<Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">
{"Simple Project to test CLI"}
</Heading>
- <Text data-ws-id="BMJfjOzunWs8XkQgvvx1e" data-ws-component="Text">
+ <Text
+ data-ws-id="BMJfjOzunWs8XkQgvvx1e"
+ data-ws-component="Text"
+ className="cn3rfux"
+ >
{"Please don't change directly in the fixture"}
</Text>
+ <Link
+ data-ws-id="pjkZo5EiBqaeUXBcyHf_O"
+ data-ws-component="Link"
+ href={"/another-page"}
+ >
+ {"Test another page link"}
+ </Link>
</Body>
);
};
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css b/fixtures/webstudio-cloudflare-template/app/__generated__/index.css
index b4de25d1b5..2370a7e646 100644
--- a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css
+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/index.css
@@ -74,6 +74,16 @@ html {
outline-width: 1px;
min-height: 1em;
}
+ a:where([data-ws-component="Link"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ min-height: 1em;
+ display: inline-block;
+ }
}
@media all {
.c1jaw2zx {
@@ -88,4 +98,7 @@ html {
.ctgx88l {
flex-direction: column;
}
+ .cn3rfux {
+ margin-bottom: 1em;
+ }
}
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
new file mode 100644
index 0000000000..1f27ce9be8
--- /dev/null
+++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
@@ -0,0 +1,337 @@
+/* eslint-disable camelcase */
+import {
+ type ServerRuntimeMetaFunction as MetaFunction,
+ type LinksFunction,
+ type LinkDescriptor,
+ type ActionFunctionArgs,
+ type LoaderFunctionArgs,
+ type HeadersFunction,
+ json,
+ redirect,
+} from "@remix-run/server-runtime";
+import { useLoaderData } from "@remix-run/react";
+import { ReactSdkContext } from "@webstudio-is/react-sdk";
+import {
+ n8nHandler,
+ formIdFieldName,
+ formBotFieldName,
+} from "@webstudio-is/form-handlers";
+import {
+ Page,
+ siteName,
+ favIconAsset,
+ pageFontAssets,
+ pageBackgroundImageAssets,
+} from "../__generated__/[another-page]._index";
+import {
+ formsProperties,
+ loadResources,
+ getPageMeta,
+ getRemixParams,
+ projectId,
+ contactEmail,
+} from "../__generated__/[another-page]._index.server";
+
+import css from "../__generated__/index.css?url";
+import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
+
+export const loader = async (arg: LoaderFunctionArgs) => {
+ const url = new URL(arg.request.url);
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+ url.host = host;
+ url.protocol = "https";
+
+ const params = getRemixParams(arg.params);
+ const system = {
+ params,
+ search: Object.fromEntries(url.searchParams),
+ origin: url.origin,
+ };
+
+ const resources = await loadResources({ system });
+ const pageMeta = getPageMeta({ system, resources });
+
+ if (pageMeta.redirect) {
+ const status =
+ pageMeta.status === 301 || pageMeta.status === 302
+ ? pageMeta.status
+ : 302;
+ return redirect(pageMeta.redirect, status);
+ }
+
+ // typecheck
+ arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
+
+ if (arg.context.EXCLUDE_FROM_SEARCH) {
+ pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
+ }
+
+ return json(
+ {
+ host,
+ url: url.href,
+ system,
+ resources,
+ pageMeta,
+ },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ {
+ status: pageMeta.status,
+ headers: {
+ "Cache-Control": "public, max-age=600",
+ },
+ }
+ );
+};
+
+export const headers: HeadersFunction = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: MetaFunction<typeof loader> = ({ data }) => {
+ const metas: ReturnType<MetaFunction> = [];
+ if (data === undefined) {
+ return metas;
+ }
+ const { pageMeta } = data;
+
+ if (data.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (pageMeta.title) {
+ metas.push({ title: pageMeta.title });
+
+ metas.push({
+ property: "og:title",
+ content: pageMeta.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data.host}`;
+
+ if (siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: siteName,
+ url: origin,
+ },
+ });
+ }
+
+ if (pageMeta.excludePageFromSearch) {
+ metas.push({
+ name: "robots",
+ content: "noindex, nofollow",
+ });
+ }
+
+ if (pageMeta.description) {
+ metas.push({
+ name: "description",
+ content: pageMeta.description,
+ });
+ metas.push({
+ property: "og:description",
+ content: pageMeta.description,
+ });
+ }
+
+ if (pageMeta.socialImageAssetName) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data.host}${imageLoader({
+ src: pageMeta.socialImageAssetName,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ } else if (pageMeta.socialImageUrl) {
+ metas.push({
+ property: "og:image",
+ content: pageMeta.socialImageUrl,
+ });
+ }
+
+ metas.push(...pageMeta.custom);
+
+ return metas;
+};
+
+export const links: LinksFunction = () => {
+ const result: LinkDescriptor[] = [];
+
+ result.push({
+ rel: "stylesheet",
+ href: css,
+ });
+
+ if (favIconAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: favIconAsset.name,
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
+ width: 144,
+ height: 144,
+ fit: "pad",
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+
+ for (const asset of pageFontAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${asset.name}`,
+ as: "font",
+ crossOrigin: "anonymous",
+ });
+ }
+
+ for (const backgroundImageAsset of pageBackgroundImageAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${backgroundImageAsset.name}`,
+ as: "image",
+ });
+ }
+
+ return result;
+};
+
+const getRequestHost = (request: Request): string =>
+ request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
+
+const getMethod = (value: string | undefined) => {
+ if (value === undefined) {
+ return "post";
+ }
+
+ switch (value.toLowerCase()) {
+ case "get":
+ return "get";
+ default:
+ return "post";
+ }
+};
+
+export const action = async ({
+ request,
+ context,
+}: ActionFunctionArgs): Promise<
+ { success: true } | { success: false; errors: string[] }
+> => {
+ try {
+ const formData = await request.formData();
+
+ const formId = formData.get(formIdFieldName);
+
+ if (formId == null || typeof formId !== "string") {
+ throw new Error("No form id in FormData");
+ }
+
+ const formBotValue = formData.get(formBotFieldName);
+
+ if (formBotValue == null || typeof formBotValue !== "string") {
+ throw new Error("Form bot field not found");
+ }
+
+ const submitTime = parseInt(formBotValue, 16);
+ // Assumes that the difference between the server time and the form submission time,
+ // including any client-server time drift, is within a 5-minute range.
+ // Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
+ // Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
+ if (
+ Number.isNaN(submitTime) ||
+ Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
+ ) {
+ throw new Error(`Form bot value invalid ${formBotValue}`);
+ }
+
+ const formProperties = formsProperties.get(formId);
+
+ // form properties are not defined when defaults are used
+ const { action, method } = formProperties ?? {};
+
+ if (contactEmail === undefined) {
+ throw new Error("Contact email not found");
+ }
+
+ const pageUrl = new URL(request.url);
+ pageUrl.host = getRequestHost(request);
+
+ if (action !== undefined) {
+ try {
+ // Test that action is full URL
+ new URL(action);
+ } catch {
+ throw new Error(
+ "Invalid action URL, must be valid http/https protocol"
+ );
+ }
+ }
+
+ const formInfo = {
+ formData,
+ projectId,
+ action: action ?? null,
+ method: getMethod(method),
+ pageUrl: pageUrl.toString(),
+ toEmail: contactEmail,
+ fromEmail: pageUrl.hostname + "@webstudio.email",
+ } as const;
+
+ const result = await n8nHandler({
+ formInfo,
+ hookUrl: context.N8N_FORM_EMAIL_HOOK,
+ });
+
+ return result;
+ } catch (error) {
+ console.error(error);
+
+ return {
+ success: false,
+ errors: [error instanceof Error ? error.message : "Unknown error"],
+ };
+ }
+};
+
+const Outlet = () => {
+ const { system, resources, url } = useLoaderData<typeof loader>();
+ return (
+ <ReactSdkContext.Provider
+ value={{
+ imageLoader,
+ assetBaseUrl,
+ imageBaseUrl,
+ resources,
+ }}
+ >
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
+ <Page key={url} system={system} />
+ </ReactSdkContext.Provider>
+ );
+};
+
+export default Outlet;
diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.json
index 6530f55731..0421c96b56 100644
--- a/fixtures/webstudio-custom-template/.webstudio/data.json
+++ b/fixtures/webstudio-custom-template/.webstudio/data.json
@@ -3,8 +3,8 @@
"id": "d48c7c5e-fdd3-4ef6-9173-ff2eaaf851d9",
"projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",
"version": 244,
- "createdAt": "2024-05-06T21:23:44.086Z",
- "updatedAt": "2024-05-06T21:23:44.086Z",
+ "createdAt": "2024-05-06T21:23:44.086",
+ "updatedAt": "2024-05-06T21:23:44.086",
"pages": {
"meta": {
"siteName": "Fixture Site",
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
index bb2309af90..41f94ebc32 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
+++ b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json
@@ -1,35 +1,59 @@
{
"build": {
- "id": "6ee09eba-d953-48c0-8ca7-77b5d8f0dff1",
+ "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
- "version": 21,
- "createdAt": "2024-02-01T08:34:11.957Z",
- "updatedAt": "2024-02-01T08:34:11.957Z",
+ "version": 29,
+ "createdAt": "2024-07-21T11:48:14.097",
+ "updatedAt": "2024-07-21T11:48:14.097",
"pages": {
"meta": {
"siteName": "",
"faviconAssetId": "",
"code": ""
},
- "settings": {
- "atomicStyles": false
- },
"homePage": {
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
- "pages": [],
+ "pages": [
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
+ }
+ ],
"folders": [
{
"id": "root",
"name": "Root",
"slug": "",
- "children": ["9di_L14CzctvSruIoKVvE"]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -114,6 +138,19 @@
"value": "column"
}
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp:rKj-wYctg3-GnqL3WHN9I:marginBottom:",
+ {
+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",
+ "styleSourceId": "0KA68BwP9gdTzE1ESO2Zp",
+ "property": "marginBottom",
+ "value": {
+ "type": "unit",
+ "unit": "em",
+ "value": 1
+ }
+ }
]
],
"styleSources": [
@@ -123,6 +160,13 @@
"type": "local",
"id": "7_QL45cpvP-zG8Hkgf4cr"
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp",
+ {
+ "type": "local",
+ "id": "0KA68BwP9gdTzE1ESO2Zp"
+ }
]
],
"styleSourceSelections": [
@@ -132,17 +176,44 @@
"instanceId": "MMimeobf_zi4ZkRGXapju",
"values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
+ ],
+ [
+ "BMJfjOzunWs8XkQgvvx1e",
+ {
+ "instanceId": "BMJfjOzunWs8XkQgvvx1e",
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
+ }
+ ]
+ ],
+ "props": [
+ [
+ "1p34InvRgqoKVqeNZ1uBb",
+ {
+ "id": "1p34InvRgqoKVqeNZ1uBb",
+ "instanceId": "pjkZo5EiBqaeUXBcyHf_O",
+ "name": "href",
+ "type": "page",
+ "value": "WPPAbLFyJD_02vhjRd8P4"
+ }
]
],
- "props": [],
"dataSources": [
[
- "HdKSzlJZasGmZlW8b-va0",
+ "2KT4-bRzToj9cAGAN_woK",
{
- "id": "HdKSzlJZasGmZlW8b-va0",
+ "type": "parameter",
+ "id": "2KT4-bRzToj9cAGAN_woK",
"scopeInstanceId": "MMimeobf_zi4ZkRGXapju",
- "name": "system",
- "type": "parameter"
+ "name": "system"
+ }
+ ],
+ [
+ "tdXe9gFf83hSo9BLWU6xl",
+ {
+ "type": "parameter",
+ "id": "tdXe9gFf83hSo9BLWU6xl",
+ "scopeInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "name": "system"
}
]
],
@@ -162,6 +233,10 @@
{
"type": "id",
"value": "BMJfjOzunWs8XkQgvvx1e"
+ },
+ {
+ "type": "id",
+ "value": "pjkZo5EiBqaeUXBcyHf_O"
}
]
}
@@ -193,6 +268,48 @@
}
]
}
+ ],
+ [
+ "pjkZo5EiBqaeUXBcyHf_O",
+ {
+ "type": "instance",
+ "id": "pjkZo5EiBqaeUXBcyHf_O",
+ "component": "Link",
+ "children": [
+ {
+ "type": "text",
+ "value": "Test another page link"
+ }
+ ]
+ }
+ ],
+ [
+ "n_VBMr7klpx25buS0NV7R",
+ {
+ "type": "instance",
+ "id": "n_VBMr7klpx25buS0NV7R",
+ "component": "Body",
+ "children": [
+ {
+ "type": "id",
+ "value": "wthNByqb3RPmheb-56VYI"
+ }
+ ]
+ }
+ ],
+ [
+ "wthNByqb3RPmheb-56VYI",
+ {
+ "type": "instance",
+ "id": "wthNByqb3RPmheb-56VYI",
+ "component": "Heading",
+ "children": [
+ {
+ "type": "text",
+ "value": "Another page"
+ }
+ ]
+ }
]
],
"deployment": {
@@ -205,20 +322,46 @@
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
"pages": [
{
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
+ },
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
}
],
"assets": [],
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts
index 80e6d6e474..af4f4e6a39 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/$resources.sitemap.xml.ts
@@ -1,6 +1,6 @@
export const sitemap = [
{
path: "/",
- lastModified: "2024-02-01",
+ lastModified: "2024-07-21",
},
];
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx
new file mode 100644
index 0000000000..134adccf84
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.server.tsx
@@ -0,0 +1,40 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import type { PageMeta } from "@webstudio-is/sdk";
+import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";
+export const loadResources = async (_props: { system: System }) => {
+ return {} as Record<string, unknown>;
+};
+
+export const getPageMeta = ({
+ system,
+ resources,
+}: {
+ system: System;
+ resources: Record<string, any>;
+}): PageMeta => {
+ return {
+ title: "Another page",
+ description: "",
+ excludePageFromSearch: true,
+ language: "",
+ socialImageAssetName: undefined,
+ socialImageUrl: "",
+ status: 200,
+ redirect: "",
+ custom: [],
+ };
+};
+
+type FormProperties = { method?: string; action?: string };
+export const formsProperties = new Map<string, FormProperties>([]);
+
+type Params = Record<string, string | undefined>;
+export const getRemixParams = ({ ...params }: Params): Params => {
+ return params;
+};
+
+export const projectId = "d845c167-ea07-4875-b08d-83e97c09dcce";
+
+export const contactEmail = "[email protected]";
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.tsx
new file mode 100644
index 0000000000..7cf0971d61
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/[another-page]._index.tsx
@@ -0,0 +1,29 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import { Fragment, useState } from "react";
+import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
+import { useResource } from "@webstudio-is/react-sdk";
+import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import { Heading as Heading } from "@webstudio-is/sdk-components-react";
+
+export const siteName = "";
+
+export const favIconAsset: ImageAsset | undefined = undefined;
+
+// Font assets on current page (can be preloaded)
+export const pageFontAssets: FontAsset[] = [];
+
+export const pageBackgroundImageAssets: ImageAsset[] = [];
+
+const Page = ({}: { system: any }) => {
+ return (
+ <Body data-ws-id="n_VBMr7klpx25buS0NV7R" data-ws-component="Body">
+ <Heading data-ws-id="wthNByqb3RPmheb-56VYI" data-ws-component="Heading">
+ {"Another page"}
+ </Heading>
+ </Body>
+ );
+};
+
+export { Page };
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
index f8d7aae4e1..3ceab9547b 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx
@@ -4,7 +4,10 @@
import { Fragment, useState } from "react";
import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
import { useResource } from "@webstudio-is/react-sdk";
-import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import {
+ Body as Body,
+ Link as Link,
+} from "@webstudio-is/sdk-components-react-remix";
import {
Heading as Heading,
Text as Text,
@@ -33,9 +36,20 @@ const Page = ({}: { system: any }) => {
<Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">
{"Simple Project to test CLI"}
</Heading>
- <Text data-ws-id="BMJfjOzunWs8XkQgvvx1e" data-ws-component="Text">
+ <Text
+ data-ws-id="BMJfjOzunWs8XkQgvvx1e"
+ data-ws-component="Text"
+ className="cn3rfux"
+ >
{"Please don't change directly in the fixture"}
</Text>
+ <Link
+ data-ws-id="pjkZo5EiBqaeUXBcyHf_O"
+ data-ws-component="Link"
+ href={"/another-page"}
+ >
+ {"Test another page link"}
+ </Link>
</Body>
);
};
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css
index b4de25d1b5..2370a7e646 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css
@@ -74,6 +74,16 @@ html {
outline-width: 1px;
min-height: 1em;
}
+ a:where([data-ws-component="Link"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ min-height: 1em;
+ display: inline-block;
+ }
}
@media all {
.c1jaw2zx {
@@ -88,4 +98,7 @@ html {
.ctgx88l {
flex-direction: column;
}
+ .cn3rfux {
+ margin-bottom: 1em;
+ }
}
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx
new file mode 100644
index 0000000000..1f27ce9be8
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx
@@ -0,0 +1,337 @@
+/* eslint-disable camelcase */
+import {
+ type ServerRuntimeMetaFunction as MetaFunction,
+ type LinksFunction,
+ type LinkDescriptor,
+ type ActionFunctionArgs,
+ type LoaderFunctionArgs,
+ type HeadersFunction,
+ json,
+ redirect,
+} from "@remix-run/server-runtime";
+import { useLoaderData } from "@remix-run/react";
+import { ReactSdkContext } from "@webstudio-is/react-sdk";
+import {
+ n8nHandler,
+ formIdFieldName,
+ formBotFieldName,
+} from "@webstudio-is/form-handlers";
+import {
+ Page,
+ siteName,
+ favIconAsset,
+ pageFontAssets,
+ pageBackgroundImageAssets,
+} from "../__generated__/[another-page]._index";
+import {
+ formsProperties,
+ loadResources,
+ getPageMeta,
+ getRemixParams,
+ projectId,
+ contactEmail,
+} from "../__generated__/[another-page]._index.server";
+
+import css from "../__generated__/index.css?url";
+import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
+
+export const loader = async (arg: LoaderFunctionArgs) => {
+ const url = new URL(arg.request.url);
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+ url.host = host;
+ url.protocol = "https";
+
+ const params = getRemixParams(arg.params);
+ const system = {
+ params,
+ search: Object.fromEntries(url.searchParams),
+ origin: url.origin,
+ };
+
+ const resources = await loadResources({ system });
+ const pageMeta = getPageMeta({ system, resources });
+
+ if (pageMeta.redirect) {
+ const status =
+ pageMeta.status === 301 || pageMeta.status === 302
+ ? pageMeta.status
+ : 302;
+ return redirect(pageMeta.redirect, status);
+ }
+
+ // typecheck
+ arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
+
+ if (arg.context.EXCLUDE_FROM_SEARCH) {
+ pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
+ }
+
+ return json(
+ {
+ host,
+ url: url.href,
+ system,
+ resources,
+ pageMeta,
+ },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ {
+ status: pageMeta.status,
+ headers: {
+ "Cache-Control": "public, max-age=600",
+ },
+ }
+ );
+};
+
+export const headers: HeadersFunction = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: MetaFunction<typeof loader> = ({ data }) => {
+ const metas: ReturnType<MetaFunction> = [];
+ if (data === undefined) {
+ return metas;
+ }
+ const { pageMeta } = data;
+
+ if (data.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (pageMeta.title) {
+ metas.push({ title: pageMeta.title });
+
+ metas.push({
+ property: "og:title",
+ content: pageMeta.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data.host}`;
+
+ if (siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: siteName,
+ url: origin,
+ },
+ });
+ }
+
+ if (pageMeta.excludePageFromSearch) {
+ metas.push({
+ name: "robots",
+ content: "noindex, nofollow",
+ });
+ }
+
+ if (pageMeta.description) {
+ metas.push({
+ name: "description",
+ content: pageMeta.description,
+ });
+ metas.push({
+ property: "og:description",
+ content: pageMeta.description,
+ });
+ }
+
+ if (pageMeta.socialImageAssetName) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data.host}${imageLoader({
+ src: pageMeta.socialImageAssetName,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ } else if (pageMeta.socialImageUrl) {
+ metas.push({
+ property: "og:image",
+ content: pageMeta.socialImageUrl,
+ });
+ }
+
+ metas.push(...pageMeta.custom);
+
+ return metas;
+};
+
+export const links: LinksFunction = () => {
+ const result: LinkDescriptor[] = [];
+
+ result.push({
+ rel: "stylesheet",
+ href: css,
+ });
+
+ if (favIconAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: favIconAsset.name,
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
+ width: 144,
+ height: 144,
+ fit: "pad",
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+
+ for (const asset of pageFontAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${asset.name}`,
+ as: "font",
+ crossOrigin: "anonymous",
+ });
+ }
+
+ for (const backgroundImageAsset of pageBackgroundImageAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${backgroundImageAsset.name}`,
+ as: "image",
+ });
+ }
+
+ return result;
+};
+
+const getRequestHost = (request: Request): string =>
+ request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
+
+const getMethod = (value: string | undefined) => {
+ if (value === undefined) {
+ return "post";
+ }
+
+ switch (value.toLowerCase()) {
+ case "get":
+ return "get";
+ default:
+ return "post";
+ }
+};
+
+export const action = async ({
+ request,
+ context,
+}: ActionFunctionArgs): Promise<
+ { success: true } | { success: false; errors: string[] }
+> => {
+ try {
+ const formData = await request.formData();
+
+ const formId = formData.get(formIdFieldName);
+
+ if (formId == null || typeof formId !== "string") {
+ throw new Error("No form id in FormData");
+ }
+
+ const formBotValue = formData.get(formBotFieldName);
+
+ if (formBotValue == null || typeof formBotValue !== "string") {
+ throw new Error("Form bot field not found");
+ }
+
+ const submitTime = parseInt(formBotValue, 16);
+ // Assumes that the difference between the server time and the form submission time,
+ // including any client-server time drift, is within a 5-minute range.
+ // Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
+ // Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
+ if (
+ Number.isNaN(submitTime) ||
+ Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
+ ) {
+ throw new Error(`Form bot value invalid ${formBotValue}`);
+ }
+
+ const formProperties = formsProperties.get(formId);
+
+ // form properties are not defined when defaults are used
+ const { action, method } = formProperties ?? {};
+
+ if (contactEmail === undefined) {
+ throw new Error("Contact email not found");
+ }
+
+ const pageUrl = new URL(request.url);
+ pageUrl.host = getRequestHost(request);
+
+ if (action !== undefined) {
+ try {
+ // Test that action is full URL
+ new URL(action);
+ } catch {
+ throw new Error(
+ "Invalid action URL, must be valid http/https protocol"
+ );
+ }
+ }
+
+ const formInfo = {
+ formData,
+ projectId,
+ action: action ?? null,
+ method: getMethod(method),
+ pageUrl: pageUrl.toString(),
+ toEmail: contactEmail,
+ fromEmail: pageUrl.hostname + "@webstudio.email",
+ } as const;
+
+ const result = await n8nHandler({
+ formInfo,
+ hookUrl: context.N8N_FORM_EMAIL_HOOK,
+ });
+
+ return result;
+ } catch (error) {
+ console.error(error);
+
+ return {
+ success: false,
+ errors: [error instanceof Error ? error.message : "Unknown error"],
+ };
+ }
+};
+
+const Outlet = () => {
+ const { system, resources, url } = useLoaderData<typeof loader>();
+ return (
+ <ReactSdkContext.Provider
+ value={{
+ imageLoader,
+ assetBaseUrl,
+ imageBaseUrl,
+ resources,
+ }}
+ >
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
+ <Page key={url} system={system} />
+ </ReactSdkContext.Provider>
+ );
+};
+
+export default Outlet;
diff --git a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
index bb2309af90..41f94ebc32 100644
--- a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
+++ b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json
@@ -1,35 +1,59 @@
{
"build": {
- "id": "6ee09eba-d953-48c0-8ca7-77b5d8f0dff1",
+ "id": "af283f08-b808-4cf6-9cb3-4a4470065c66",
"projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",
- "version": 21,
- "createdAt": "2024-02-01T08:34:11.957Z",
- "updatedAt": "2024-02-01T08:34:11.957Z",
+ "version": 29,
+ "createdAt": "2024-07-21T11:48:14.097",
+ "updatedAt": "2024-07-21T11:48:14.097",
"pages": {
"meta": {
"siteName": "",
"faviconAssetId": "",
"code": ""
},
- "settings": {
- "atomicStyles": false
- },
"homePage": {
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
- "pages": [],
+ "pages": [
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
+ }
+ ],
"folders": [
{
"id": "root",
"name": "Root",
"slug": "",
- "children": ["9di_L14CzctvSruIoKVvE"]
+ "children": ["9di_L14CzctvSruIoKVvE", "WPPAbLFyJD_02vhjRd8P4"]
}
]
},
@@ -114,6 +138,19 @@
"value": "column"
}
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp:rKj-wYctg3-GnqL3WHN9I:marginBottom:",
+ {
+ "breakpointId": "rKj-wYctg3-GnqL3WHN9I",
+ "styleSourceId": "0KA68BwP9gdTzE1ESO2Zp",
+ "property": "marginBottom",
+ "value": {
+ "type": "unit",
+ "unit": "em",
+ "value": 1
+ }
+ }
]
],
"styleSources": [
@@ -123,6 +160,13 @@
"type": "local",
"id": "7_QL45cpvP-zG8Hkgf4cr"
}
+ ],
+ [
+ "0KA68BwP9gdTzE1ESO2Zp",
+ {
+ "type": "local",
+ "id": "0KA68BwP9gdTzE1ESO2Zp"
+ }
]
],
"styleSourceSelections": [
@@ -132,17 +176,44 @@
"instanceId": "MMimeobf_zi4ZkRGXapju",
"values": ["7_QL45cpvP-zG8Hkgf4cr"]
}
+ ],
+ [
+ "BMJfjOzunWs8XkQgvvx1e",
+ {
+ "instanceId": "BMJfjOzunWs8XkQgvvx1e",
+ "values": ["0KA68BwP9gdTzE1ESO2Zp"]
+ }
+ ]
+ ],
+ "props": [
+ [
+ "1p34InvRgqoKVqeNZ1uBb",
+ {
+ "id": "1p34InvRgqoKVqeNZ1uBb",
+ "instanceId": "pjkZo5EiBqaeUXBcyHf_O",
+ "name": "href",
+ "type": "page",
+ "value": "WPPAbLFyJD_02vhjRd8P4"
+ }
]
],
- "props": [],
"dataSources": [
[
- "HdKSzlJZasGmZlW8b-va0",
+ "2KT4-bRzToj9cAGAN_woK",
{
- "id": "HdKSzlJZasGmZlW8b-va0",
+ "type": "parameter",
+ "id": "2KT4-bRzToj9cAGAN_woK",
"scopeInstanceId": "MMimeobf_zi4ZkRGXapju",
- "name": "system",
- "type": "parameter"
+ "name": "system"
+ }
+ ],
+ [
+ "tdXe9gFf83hSo9BLWU6xl",
+ {
+ "type": "parameter",
+ "id": "tdXe9gFf83hSo9BLWU6xl",
+ "scopeInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "name": "system"
}
]
],
@@ -162,6 +233,10 @@
{
"type": "id",
"value": "BMJfjOzunWs8XkQgvvx1e"
+ },
+ {
+ "type": "id",
+ "value": "pjkZo5EiBqaeUXBcyHf_O"
}
]
}
@@ -193,6 +268,48 @@
}
]
}
+ ],
+ [
+ "pjkZo5EiBqaeUXBcyHf_O",
+ {
+ "type": "instance",
+ "id": "pjkZo5EiBqaeUXBcyHf_O",
+ "component": "Link",
+ "children": [
+ {
+ "type": "text",
+ "value": "Test another page link"
+ }
+ ]
+ }
+ ],
+ [
+ "n_VBMr7klpx25buS0NV7R",
+ {
+ "type": "instance",
+ "id": "n_VBMr7klpx25buS0NV7R",
+ "component": "Body",
+ "children": [
+ {
+ "type": "id",
+ "value": "wthNByqb3RPmheb-56VYI"
+ }
+ ]
+ }
+ ],
+ [
+ "wthNByqb3RPmheb-56VYI",
+ {
+ "type": "instance",
+ "id": "wthNByqb3RPmheb-56VYI",
+ "component": "Heading",
+ "children": [
+ {
+ "type": "text",
+ "value": "Another page"
+ }
+ ]
+ }
]
],
"deployment": {
@@ -205,20 +322,46 @@
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
},
"pages": [
{
"id": "9di_L14CzctvSruIoKVvE",
"name": "Home",
"title": "\"Home\"",
- "meta": {},
"rootInstanceId": "MMimeobf_zi4ZkRGXapju",
- "path": "",
- "systemDataSourceId": "HdKSzlJZasGmZlW8b-va0"
+ "systemDataSourceId": "2KT4-bRzToj9cAGAN_woK",
+ "meta": {},
+ "path": ""
+ },
+ {
+ "id": "WPPAbLFyJD_02vhjRd8P4",
+ "name": "Another page",
+ "title": "\"Another page\"",
+ "rootInstanceId": "n_VBMr7klpx25buS0NV7R",
+ "systemDataSourceId": "tdXe9gFf83hSo9BLWU6xl",
+ "meta": {
+ "description": "\"\"",
+ "excludePageFromSearch": "true",
+ "language": "\"\"",
+ "socialImageUrl": "\"\"",
+ "status": "200",
+ "redirect": "\"\"",
+ "documentType": "html",
+ "custom": [
+ {
+ "property": "",
+ "content": "\"\""
+ }
+ ]
+ },
+ "marketplace": {
+ "include": false
+ },
+ "path": "/another-page"
}
],
"assets": [],
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts
index 80e6d6e474..af4f4e6a39 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/$resources.sitemap.xml.ts
@@ -1,6 +1,6 @@
export const sitemap = [
{
path: "/",
- lastModified: "2024-02-01",
+ lastModified: "2024-07-21",
},
];
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx
new file mode 100644
index 0000000000..134adccf84
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.server.tsx
@@ -0,0 +1,40 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import type { PageMeta } from "@webstudio-is/sdk";
+import { loadResource, isLocalResource, type System } from "@webstudio-is/sdk";
+export const loadResources = async (_props: { system: System }) => {
+ return {} as Record<string, unknown>;
+};
+
+export const getPageMeta = ({
+ system,
+ resources,
+}: {
+ system: System;
+ resources: Record<string, any>;
+}): PageMeta => {
+ return {
+ title: "Another page",
+ description: "",
+ excludePageFromSearch: true,
+ language: "",
+ socialImageAssetName: undefined,
+ socialImageUrl: "",
+ status: 200,
+ redirect: "",
+ custom: [],
+ };
+};
+
+type FormProperties = { method?: string; action?: string };
+export const formsProperties = new Map<string, FormProperties>([]);
+
+type Params = Record<string, string | undefined>;
+export const getRemixParams = ({ ...params }: Params): Params => {
+ return params;
+};
+
+export const projectId = "d845c167-ea07-4875-b08d-83e97c09dcce";
+
+export const contactEmail = "[email protected]";
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.tsx
new file mode 100644
index 0000000000..7cf0971d61
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/[another-page]._index.tsx
@@ -0,0 +1,29 @@
+/* eslint-disable */
+/* This is a auto generated file for building the project */
+
+import { Fragment, useState } from "react";
+import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
+import { useResource } from "@webstudio-is/react-sdk";
+import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import { Heading as Heading } from "@webstudio-is/sdk-components-react";
+
+export const siteName = "";
+
+export const favIconAsset: ImageAsset | undefined = undefined;
+
+// Font assets on current page (can be preloaded)
+export const pageFontAssets: FontAsset[] = [];
+
+export const pageBackgroundImageAssets: ImageAsset[] = [];
+
+const Page = ({}: { system: any }) => {
+ return (
+ <Body data-ws-id="n_VBMr7klpx25buS0NV7R" data-ws-component="Body">
+ <Heading data-ws-id="wthNByqb3RPmheb-56VYI" data-ws-component="Heading">
+ {"Another page"}
+ </Heading>
+ </Body>
+ );
+};
+
+export { Page };
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
index f8d7aae4e1..3ceab9547b 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx
@@ -4,7 +4,10 @@
import { Fragment, useState } from "react";
import type { FontAsset, ImageAsset } from "@webstudio-is/sdk";
import { useResource } from "@webstudio-is/react-sdk";
-import { Body as Body } from "@webstudio-is/sdk-components-react-remix";
+import {
+ Body as Body,
+ Link as Link,
+} from "@webstudio-is/sdk-components-react-remix";
import {
Heading as Heading,
Text as Text,
@@ -33,9 +36,20 @@ const Page = ({}: { system: any }) => {
<Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">
{"Simple Project to test CLI"}
</Heading>
- <Text data-ws-id="BMJfjOzunWs8XkQgvvx1e" data-ws-component="Text">
+ <Text
+ data-ws-id="BMJfjOzunWs8XkQgvvx1e"
+ data-ws-component="Text"
+ className="cn3rfux"
+ >
{"Please don't change directly in the fixture"}
</Text>
+ <Link
+ data-ws-id="pjkZo5EiBqaeUXBcyHf_O"
+ data-ws-component="Link"
+ href={"/another-page"}
+ >
+ {"Test another page link"}
+ </Link>
</Body>
);
};
diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css
index b4de25d1b5..2370a7e646 100644
--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css
+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css
@@ -74,6 +74,16 @@ html {
outline-width: 1px;
min-height: 1em;
}
+ a:where([data-ws-component="Link"]) {
+ box-sizing: border-box;
+ border-top-width: 1px;
+ border-right-width: 1px;
+ border-bottom-width: 1px;
+ border-left-width: 1px;
+ outline-width: 1px;
+ min-height: 1em;
+ display: inline-block;
+ }
}
@media all {
.c1jaw2zx {
@@ -88,4 +98,7 @@ html {
.ctgx88l {
flex-direction: column;
}
+ .cn3rfux {
+ margin-bottom: 1em;
+ }
}
diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx
new file mode 100644
index 0000000000..1f27ce9be8
--- /dev/null
+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx
@@ -0,0 +1,337 @@
+/* eslint-disable camelcase */
+import {
+ type ServerRuntimeMetaFunction as MetaFunction,
+ type LinksFunction,
+ type LinkDescriptor,
+ type ActionFunctionArgs,
+ type LoaderFunctionArgs,
+ type HeadersFunction,
+ json,
+ redirect,
+} from "@remix-run/server-runtime";
+import { useLoaderData } from "@remix-run/react";
+import { ReactSdkContext } from "@webstudio-is/react-sdk";
+import {
+ n8nHandler,
+ formIdFieldName,
+ formBotFieldName,
+} from "@webstudio-is/form-handlers";
+import {
+ Page,
+ siteName,
+ favIconAsset,
+ pageFontAssets,
+ pageBackgroundImageAssets,
+} from "../__generated__/[another-page]._index";
+import {
+ formsProperties,
+ loadResources,
+ getPageMeta,
+ getRemixParams,
+ projectId,
+ contactEmail,
+} from "../__generated__/[another-page]._index.server";
+
+import css from "../__generated__/index.css?url";
+import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
+
+export const loader = async (arg: LoaderFunctionArgs) => {
+ const url = new URL(arg.request.url);
+ const host =
+ arg.request.headers.get("x-forwarded-host") ||
+ arg.request.headers.get("host") ||
+ "";
+ url.host = host;
+ url.protocol = "https";
+
+ const params = getRemixParams(arg.params);
+ const system = {
+ params,
+ search: Object.fromEntries(url.searchParams),
+ origin: url.origin,
+ };
+
+ const resources = await loadResources({ system });
+ const pageMeta = getPageMeta({ system, resources });
+
+ if (pageMeta.redirect) {
+ const status =
+ pageMeta.status === 301 || pageMeta.status === 302
+ ? pageMeta.status
+ : 302;
+ return redirect(pageMeta.redirect, status);
+ }
+
+ // typecheck
+ arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;
+
+ if (arg.context.EXCLUDE_FROM_SEARCH) {
+ pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
+ }
+
+ return json(
+ {
+ host,
+ url: url.href,
+ system,
+ resources,
+ pageMeta,
+ },
+ // No way for current information to change, so add cache for 10 minutes
+ // In case of CRM Data, this should be set to 0
+ {
+ status: pageMeta.status,
+ headers: {
+ "Cache-Control": "public, max-age=600",
+ },
+ }
+ );
+};
+
+export const headers: HeadersFunction = () => {
+ return {
+ "Cache-Control": "public, max-age=0, must-revalidate",
+ };
+};
+
+export const meta: MetaFunction<typeof loader> = ({ data }) => {
+ const metas: ReturnType<MetaFunction> = [];
+ if (data === undefined) {
+ return metas;
+ }
+ const { pageMeta } = data;
+
+ if (data.url) {
+ metas.push({
+ property: "og:url",
+ content: data.url,
+ });
+ }
+
+ if (pageMeta.title) {
+ metas.push({ title: pageMeta.title });
+
+ metas.push({
+ property: "og:title",
+ content: pageMeta.title,
+ });
+ }
+
+ metas.push({ property: "og:type", content: "website" });
+
+ const origin = `https://${data.host}`;
+
+ if (siteName) {
+ metas.push({
+ property: "og:site_name",
+ content: siteName,
+ });
+ metas.push({
+ "script:ld+json": {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ name: siteName,
+ url: origin,
+ },
+ });
+ }
+
+ if (pageMeta.excludePageFromSearch) {
+ metas.push({
+ name: "robots",
+ content: "noindex, nofollow",
+ });
+ }
+
+ if (pageMeta.description) {
+ metas.push({
+ name: "description",
+ content: pageMeta.description,
+ });
+ metas.push({
+ property: "og:description",
+ content: pageMeta.description,
+ });
+ }
+
+ if (pageMeta.socialImageAssetName) {
+ metas.push({
+ property: "og:image",
+ content: `https://${data.host}${imageLoader({
+ src: pageMeta.socialImageAssetName,
+ // Do not transform social image (not enough information do we need to do this)
+ format: "raw",
+ })}`,
+ });
+ } else if (pageMeta.socialImageUrl) {
+ metas.push({
+ property: "og:image",
+ content: pageMeta.socialImageUrl,
+ });
+ }
+
+ metas.push(...pageMeta.custom);
+
+ return metas;
+};
+
+export const links: LinksFunction = () => {
+ const result: LinkDescriptor[] = [];
+
+ result.push({
+ rel: "stylesheet",
+ href: css,
+ });
+
+ if (favIconAsset) {
+ result.push({
+ rel: "icon",
+ href: imageLoader({
+ src: favIconAsset.name,
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
+ width: 144,
+ height: 144,
+ fit: "pad",
+ quality: 100,
+ format: "auto",
+ }),
+ type: undefined,
+ });
+ }
+
+ for (const asset of pageFontAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${asset.name}`,
+ as: "font",
+ crossOrigin: "anonymous",
+ });
+ }
+
+ for (const backgroundImageAsset of pageBackgroundImageAssets) {
+ result.push({
+ rel: "preload",
+ href: `${assetBaseUrl}${backgroundImageAsset.name}`,
+ as: "image",
+ });
+ }
+
+ return result;
+};
+
+const getRequestHost = (request: Request): string =>
+ request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
+
+const getMethod = (value: string | undefined) => {
+ if (value === undefined) {
+ return "post";
+ }
+
+ switch (value.toLowerCase()) {
+ case "get":
+ return "get";
+ default:
+ return "post";
+ }
+};
+
+export const action = async ({
+ request,
+ context,
+}: ActionFunctionArgs): Promise<
+ { success: true } | { success: false; errors: string[] }
+> => {
+ try {
+ const formData = await request.formData();
+
+ const formId = formData.get(formIdFieldName);
+
+ if (formId == null || typeof formId !== "string") {
+ throw new Error("No form id in FormData");
+ }
+
+ const formBotValue = formData.get(formBotFieldName);
+
+ if (formBotValue == null || typeof formBotValue !== "string") {
+ throw new Error("Form bot field not found");
+ }
+
+ const submitTime = parseInt(formBotValue, 16);
+ // Assumes that the difference between the server time and the form submission time,
+ // including any client-server time drift, is within a 5-minute range.
+ // Note: submitTime might be NaN because formBotValue can be any string used for logging purposes.
+ // Example: `formBotValue: jsdom`, or `formBotValue: headless-env`
+ if (
+ Number.isNaN(submitTime) ||
+ Math.abs(Date.now() - submitTime) > 1000 * 60 * 5
+ ) {
+ throw new Error(`Form bot value invalid ${formBotValue}`);
+ }
+
+ const formProperties = formsProperties.get(formId);
+
+ // form properties are not defined when defaults are used
+ const { action, method } = formProperties ?? {};
+
+ if (contactEmail === undefined) {
+ throw new Error("Contact email not found");
+ }
+
+ const pageUrl = new URL(request.url);
+ pageUrl.host = getRequestHost(request);
+
+ if (action !== undefined) {
+ try {
+ // Test that action is full URL
+ new URL(action);
+ } catch {
+ throw new Error(
+ "Invalid action URL, must be valid http/https protocol"
+ );
+ }
+ }
+
+ const formInfo = {
+ formData,
+ projectId,
+ action: action ?? null,
+ method: getMethod(method),
+ pageUrl: pageUrl.toString(),
+ toEmail: contactEmail,
+ fromEmail: pageUrl.hostname + "@webstudio.email",
+ } as const;
+
+ const result = await n8nHandler({
+ formInfo,
+ hookUrl: context.N8N_FORM_EMAIL_HOOK,
+ });
+
+ return result;
+ } catch (error) {
+ console.error(error);
+
+ return {
+ success: false,
+ errors: [error instanceof Error ? error.message : "Unknown error"],
+ };
+ }
+};
+
+const Outlet = () => {
+ const { system, resources, url } = useLoaderData<typeof loader>();
+ return (
+ <ReactSdkContext.Provider
+ value={{
+ imageLoader,
+ assetBaseUrl,
+ imageBaseUrl,
+ resources,
+ }}
+ >
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
+ <Page key={url} system={system} />
+ </ReactSdkContext.Provider>
+ );
+};
+
+export default Outlet;
diff --git a/fixtures/webstudio-remix-vercel/.webstudio/data.json b/fixtures/webstudio-remix-vercel/.webstudio/data.json
index 4c5a2740fb..686130916b 100644
--- a/fixtures/webstudio-remix-vercel/.webstudio/data.json
+++ b/fixtures/webstudio-remix-vercel/.webstudio/data.json
@@ -3,8 +3,8 @@
"id": "3dce3f4f-3c20-46e5-a885-d1b543db6237",
"projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
"version": 257,
- "createdAt": "2024-05-30T16:07:53.141Z",
- "updatedAt": "2024-05-30T16:07:53.141Z",
+ "createdAt": "2024-05-30T16:07:53.141",
+ "updatedAt": "2024-05-30T16:07:53.141",
"pages": {
"meta": {
"siteName": "KittyGuardedZone",