diff --git a/fixtures/webstudio-remix-vercel/.webstudio/data.json b/fixtures/webstudio-remix-vercel/.webstudio/data.json index 9cd945532a29..c589c57cfe81 100644 --- a/fixtures/webstudio-remix-vercel/.webstudio/data.json +++ b/fixtures/webstudio-remix-vercel/.webstudio/data.json @@ -1,10 +1,10 @@ { "build": { - "id": "6876de3a-942a-466b-9761-ad7cb2fa2c21", + "id": "1710e6a3-6f3b-44c9-8e4f-4176be77673e", "projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d", - "version": 321, - "createdAt": "2024-10-08T17:47:04.557+00:00", - "updatedAt": "2024-10-08T17:47:04.557+00:00", + "version": 341, + "createdAt": "2024-10-28T17:19:04.754+00:00", + "updatedAt": "2024-10-28T17:19:04.754+00:00", "pages": { "meta": { "siteName": "KittyGuardedZone", @@ -155,6 +155,32 @@ "include": false }, "path": "/class-names" + }, + { + "id": "FsnS9ui6btzM4W3YELE3Q", + "name": "sitemap.xml", + "title": "\"Untitled\"", + "rootInstanceId": "z4Gp8noJpB4NS3JmdXh1Y", + "systemDataSourceId": "NB_R8mrrGxFXCCsAtL8QK", + "meta": { + "description": "\"\"", + "excludePageFromSearch": "true", + "language": "\"\"", + "socialImageUrl": "\"\"", + "status": "200", + "redirect": "\"\"", + "documentType": "xml", + "custom": [ + { + "property": "", + "content": "\"\"" + } + ] + }, + "marketplace": { + "include": false + }, + "path": "/sitemap.xml" } ], "folders": [ @@ -171,7 +197,8 @@ "TS39WeBd0Qr3QgbSlzdf2", "42cWhASQ3tTtKDnsvzhUF", "9xlwLSHxuk8HmS3-EEGcf", - "lTS5DKrDEC_mXSAc5ZDDA" + "lTS5DKrDEC_mXSAc5ZDDA", + "FsnS9ui6btzM4W3YELE3Q" ] }, { @@ -1553,6 +1580,32 @@ "unit": "px" } } + ], + [ + "LnOCG1kkSViZaAVoz4GXw:UoTkWyaFuTYJihS3MFYK5:marginTop:", + { + "styleSourceId": "LnOCG1kkSViZaAVoz4GXw", + "breakpointId": "UoTkWyaFuTYJihS3MFYK5", + "property": "marginTop", + "value": { + "type": "unit", + "unit": "em", + "value": 1 + } + } + ], + [ + "LnOCG1kkSViZaAVoz4GXw:UoTkWyaFuTYJihS3MFYK5:marginBottom:", + { + "styleSourceId": "LnOCG1kkSViZaAVoz4GXw", + "breakpointId": "UoTkWyaFuTYJihS3MFYK5", + "property": "marginBottom", + "value": { + "type": "unit", + "unit": "em", + "value": 0 + } + } ] ], "styleSources": [ @@ -1737,6 +1790,13 @@ "type": "local", "id": "g6Z7dAxi6LYB-XtI6SaRR" } + ], + [ + "LnOCG1kkSViZaAVoz4GXw", + { + "type": "local", + "id": "LnOCG1kkSViZaAVoz4GXw" + } ] ], "styleSourceSelections": [ @@ -1921,6 +1981,13 @@ "instanceId": "T-rqx2b12pRrWcafRRoIG", "values": ["g6Z7dAxi6LYB-XtI6SaRR"] } + ], + [ + "LYBzzBvHLrfSOmPLs52dP", + { + "instanceId": "LYBzzBvHLrfSOmPLs52dP", + "values": ["LnOCG1kkSViZaAVoz4GXw"] + } ] ], "props": [ @@ -2334,6 +2401,206 @@ "type": "expression", "value": "`${$ws$dataSource$FG6camSaR89vSBREAV9PT} class_3`" } + ], + [ + "flD2WGZT36p4CEaZOVFl6", + { + "id": "flD2WGZT36p4CEaZOVFl6", + "instanceId": "zJkrskDJhaEk-nOSRWrGg", + "name": "data", + "type": "expression", + "value": "[\n {\n \"path\": \"/\",\n \"lastModified\": \"2024-05-07\"\n },\n {\n \"path\": \"/olegs-test\",\n \"lastModified\": \"2024-05-07\"\n }\n]" + } + ], + [ + "4TLznPGh--A7PjsBOBxka", + { + "id": "4TLznPGh--A7PjsBOBxka", + "instanceId": "zJkrskDJhaEk-nOSRWrGg", + "name": "item", + "type": "parameter", + "value": "2pjBK-2keQ15QSbnjLOk1" + } + ], + [ + "NHtEMEG0kS-0V_RVLYG-S", + { + "id": "NHtEMEG0kS-0V_RVLYG-S", + "instanceId": "USgd2tJcA7pt-9xq4H4XP", + "name": "tag", + "type": "string", + "value": "url" + } + ], + [ + "xnnMp6L60pLHmdUgyanrg", + { + "id": "xnnMp6L60pLHmdUgyanrg", + "instanceId": "vw4jVDxlyJhw77jdG3lpd", + "name": "tag", + "type": "string", + "value": "loc" + } + ], + [ + "KnGNfGmPtiKrV2FNVkpaW", + { + "id": "KnGNfGmPtiKrV2FNVkpaW", + "instanceId": "zgwCRmVObvwI6a7zmD9OD", + "name": "tag", + "type": "string", + "value": "lastmod" + } + ], + [ + "2ec8PdWkJoKEehFI6knpl", + { + "id": "2ec8PdWkJoKEehFI6knpl", + "instanceId": "SVI6fI342JAxCvwsg4Oc6", + "name": "tag", + "type": "string", + "value": "urlset" + } + ], + [ + "z9yQBVKOIKgPCiMWHFNkx", + { + "id": "z9yQBVKOIKgPCiMWHFNkx", + "instanceId": "SVI6fI342JAxCvwsg4Oc6", + "name": "xmlns", + "type": "string", + "value": "http://www.sitemaps.org/schemas/sitemap/0.9" + } + ], + [ + "StcDsvZEgDu_30Lyl2F3G", + { + "id": "StcDsvZEgDu_30Lyl2F3G", + "instanceId": "8rjJjZTvM-WXjU8dVktBZ", + "name": "tag", + "type": "string", + "value": "url" + } + ], + [ + "PlgU3AVcOnqXiNtqNAqky", + { + "id": "PlgU3AVcOnqXiNtqNAqky", + "instanceId": "sDGB6PDQ9YABCdk9DKBmz", + "name": "tag", + "type": "string", + "value": "loc" + } + ], + [ + "r-V5MpdY0q8n-aSYi8RtT", + { + "id": "r-V5MpdY0q8n-aSYi8RtT", + "instanceId": "7Xcdw3QXZnp_Ehel6A6bI", + "name": "tag", + "type": "string", + "value": "lastmod" + } + ], + [ + "A8Wu7uH9OlQedZwv5-P7X", + { + "id": "A8Wu7uH9OlQedZwv5-P7X", + "instanceId": "LYBzzBvHLrfSOmPLs52dP", + "name": "tag", + "type": "string", + "value": "h3" + } + ], + [ + "K8Q0cGdTrOHzJ0WXutMae", + { + "id": "K8Q0cGdTrOHzJ0WXutMae", + "instanceId": "bBAE2vpcCLzlcin29wQYA", + "name": "tag", + "type": "string", + "value": "xhtml:link" + } + ], + [ + "HOGRU7ZXYeL11n6TtpKJo", + { + "id": "HOGRU7ZXYeL11n6TtpKJo", + "instanceId": "bBAE2vpcCLzlcin29wQYA", + "name": "rel", + "type": "string", + "value": "alternate" + } + ], + [ + "G-QTw79T_Q1w2oGjRWO0c", + { + "id": "G-QTw79T_Q1w2oGjRWO0c", + "instanceId": "bBAE2vpcCLzlcin29wQYA", + "name": "hreflang", + "type": "string", + "value": "en" + } + ], + [ + "Fpb7wkI2VjRdc03wTTNfo", + { + "id": "Fpb7wkI2VjRdc03wTTNfo", + "instanceId": "bBAE2vpcCLzlcin29wQYA", + "name": "href", + "type": "string", + "value": "custom-en-location" + } + ], + [ + "0AvNbmtwI9MjjfowIxYYh", + { + "id": "0AvNbmtwI9MjjfowIxYYh", + "instanceId": "yDQOMG0BUdvM5g5hDV7JP", + "name": "tag", + "type": "string", + "value": "xhtml:link" + } + ], + [ + "bIQ9oPI1NqjcPRnNELKdB", + { + "id": "bIQ9oPI1NqjcPRnNELKdB", + "instanceId": "yDQOMG0BUdvM5g5hDV7JP", + "name": "rel", + "type": "string", + "value": "alternate" + } + ], + [ + "sdbARDMZjIiaN1socbZbD", + { + "id": "sdbARDMZjIiaN1socbZbD", + "instanceId": "yDQOMG0BUdvM5g5hDV7JP", + "name": "hreflang", + "type": "string", + "value": "en" + } + ], + [ + "erBMakiSxs-TaKCWuCoiD", + { + "id": "erBMakiSxs-TaKCWuCoiD", + "instanceId": "yDQOMG0BUdvM5g5hDV7JP", + "name": "href", + "type": "expression", + "value": "`${$ws$dataSource$NB_R8mrrGxFXCCsAtL8QK.origin ?? '${ORIGIN}'}${$ws$dataSource$2pjBK__DASH__2keQ15QSbnjLOk1.path}en`" + } + ], + [ + "Pf6idCc5mNEGBLrdL_1yN", + { + "id": "Pf6idCc5mNEGBLrdL_1yN", + "instanceId": "SVI6fI342JAxCvwsg4Oc6", + "name": "xmlns:xhtml", + "type": "string", + "value": "http://www.w3.org/1999/xhtml" + } ] ], "dataSources": [ @@ -2513,6 +2780,24 @@ "value": "varClass" } } + ], + [ + "NB_R8mrrGxFXCCsAtL8QK", + { + "type": "parameter", + "id": "NB_R8mrrGxFXCCsAtL8QK", + "scopeInstanceId": "z4Gp8noJpB4NS3JmdXh1Y", + "name": "system" + } + ], + [ + "2pjBK-2keQ15QSbnjLOk1", + { + "type": "parameter", + "id": "2pjBK-2keQ15QSbnjLOk1", + "scopeInstanceId": "zJkrskDJhaEk-nOSRWrGg", + "name": "url" + } ] ], "resources": [ @@ -3656,6 +3941,189 @@ "component": "Box", "children": [] } + ], + [ + "z4Gp8noJpB4NS3JmdXh1Y", + { + "type": "instance", + "id": "z4Gp8noJpB4NS3JmdXh1Y", + "component": "Body", + "children": [ + { + "type": "id", + "value": "SVI6fI342JAxCvwsg4Oc6" + } + ] + } + ], + [ + "SVI6fI342JAxCvwsg4Oc6", + { + "type": "instance", + "id": "SVI6fI342JAxCvwsg4Oc6", + "component": "XmlNode", + "children": [ + { + "type": "id", + "value": "zJkrskDJhaEk-nOSRWrGg" + }, + { + "type": "id", + "value": "LYBzzBvHLrfSOmPLs52dP" + }, + { + "type": "id", + "value": "8rjJjZTvM-WXjU8dVktBZ" + } + ] + } + ], + [ + "zJkrskDJhaEk-nOSRWrGg", + { + "type": "instance", + "id": "zJkrskDJhaEk-nOSRWrGg", + "component": "ws:collection", + "label": "urls", + "children": [ + { + "type": "id", + "value": "USgd2tJcA7pt-9xq4H4XP" + } + ] + } + ], + [ + "USgd2tJcA7pt-9xq4H4XP", + { + "type": "instance", + "id": "USgd2tJcA7pt-9xq4H4XP", + "component": "XmlNode", + "children": [ + { + "type": "id", + "value": "vw4jVDxlyJhw77jdG3lpd" + }, + { + "type": "id", + "value": "zgwCRmVObvwI6a7zmD9OD" + }, + { + "type": "id", + "value": "yDQOMG0BUdvM5g5hDV7JP" + } + ] + } + ], + [ + "vw4jVDxlyJhw77jdG3lpd", + { + "type": "instance", + "id": "vw4jVDxlyJhw77jdG3lpd", + "component": "XmlNode", + "children": [ + { + "type": "expression", + "value": "`${$ws$dataSource$NB_R8mrrGxFXCCsAtL8QK.origin ?? '${ORIGIN}'}${$ws$dataSource$2pjBK__DASH__2keQ15QSbnjLOk1.path}`" + } + ] + } + ], + [ + "zgwCRmVObvwI6a7zmD9OD", + { + "type": "instance", + "id": "zgwCRmVObvwI6a7zmD9OD", + "component": "XmlNode", + "children": [ + { + "type": "expression", + "value": "$ws$dataSource$2pjBK__DASH__2keQ15QSbnjLOk1.lastModified" + } + ] + } + ], + [ + "LYBzzBvHLrfSOmPLs52dP", + { + "type": "instance", + "id": "LYBzzBvHLrfSOmPLs52dP", + "component": "Heading", + "children": [ + { + "type": "text", + "value": "Below is custom section" + } + ] + } + ], + [ + "8rjJjZTvM-WXjU8dVktBZ", + { + "type": "instance", + "id": "8rjJjZTvM-WXjU8dVktBZ", + "component": "XmlNode", + "children": [ + { + "type": "id", + "value": "sDGB6PDQ9YABCdk9DKBmz" + }, + { + "type": "id", + "value": "7Xcdw3QXZnp_Ehel6A6bI" + }, + { + "type": "id", + "value": "bBAE2vpcCLzlcin29wQYA" + } + ] + } + ], + [ + "sDGB6PDQ9YABCdk9DKBmz", + { + "type": "instance", + "id": "sDGB6PDQ9YABCdk9DKBmz", + "component": "XmlNode", + "children": [ + { + "type": "text", + "value": "custom-hand-made-location" + } + ] + } + ], + [ + "7Xcdw3QXZnp_Ehel6A6bI", + { + "type": "instance", + "id": "7Xcdw3QXZnp_Ehel6A6bI", + "component": "XmlNode", + "children": [ + { + "type": "text", + "value": "2020-10-10" + } + ] + } + ], + [ + "bBAE2vpcCLzlcin29wQYA", + { + "type": "instance", + "id": "bBAE2vpcCLzlcin29wQYA", + "component": "XmlNode", + "children": [] + } + ], + [ + "yDQOMG0BUdvM5g5hDV7JP", + { + "type": "instance", + "id": "yDQOMG0BUdvM5g5hDV7JP", + "component": "XmlNode", + "children": [] + } ] ], "deployment": { @@ -3827,6 +4295,32 @@ "include": false }, "path": "/class-names" + }, + { + "id": "FsnS9ui6btzM4W3YELE3Q", + "name": "sitemap.xml", + "title": "\"Untitled\"", + "rootInstanceId": "z4Gp8noJpB4NS3JmdXh1Y", + "systemDataSourceId": "NB_R8mrrGxFXCCsAtL8QK", + "meta": { + "description": "\"\"", + "excludePageFromSearch": "true", + "language": "\"\"", + "socialImageUrl": "\"\"", + "status": "200", + "redirect": "\"\"", + "documentType": "xml", + "custom": [ + { + "property": "", + "content": "\"\"" + } + ] + }, + "marketplace": { + "include": false + }, + "path": "/sitemap.xml" } ], "assets": [ diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/$resources.sitemap.xml.ts b/fixtures/webstudio-remix-vercel/app/__generated__/$resources.sitemap.xml.ts index 069d453c16e5..ee0f83296c51 100644 --- a/fixtures/webstudio-remix-vercel/app/__generated__/$resources.sitemap.xml.ts +++ b/fixtures/webstudio-remix-vercel/app/__generated__/$resources.sitemap.xml.ts @@ -1,26 +1,26 @@ export const sitemap = [ { path: "/", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, { path: "/_route_with_symbols_", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, { path: "/form", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, { path: "/heading-with-id", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, { path: "/resources", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, { path: "/nested/nested-page", - lastModified: "2024-10-08", + lastModified: "2024-10-28", }, ]; diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.server.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.server.tsx new file mode 100644 index 000000000000..6c968b385baa --- /dev/null +++ b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.server.tsx @@ -0,0 +1,39 @@ +/* eslint-disable */ +/* This is a auto generated file for building the project */ + +import type { PageMeta } from "@webstudio-is/sdk"; +import type { System, ResourceRequest } from "@webstudio-is/sdk"; +export const getResources = (_props: { system: System }) => { + const _data = new Map([]); + const _action = new Map([]); + return { data: _data, action: _action }; +}; + +export const getPageMeta = ({ + system, + resources, +}: { + system: System; + resources: Record; +}): PageMeta => { + return { + title: "Untitled", + description: "", + excludePageFromSearch: true, + language: "", + socialImageAssetName: undefined, + socialImageUrl: "", + status: 200, + redirect: "", + custom: [], + }; +}; + +type Params = Record; +export const getRemixParams = ({ ...params }: Params): Params => { + return params; +}; + +export const projectId = "cddc1d44-af37-4cb6-a430-d300cf6f932d"; + +export const contactEmail = "hello@webstudio.is"; diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.tsx new file mode 100644 index 000000000000..810befd78c35 --- /dev/null +++ b/fixtures/webstudio-remix-vercel/app/__generated__/[sitemap.xml]._index.tsx @@ -0,0 +1,82 @@ +/* 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, useVariableState } from "@webstudio-is/react-sdk/runtime"; +import { XmlNode } from "@webstudio-is/sdk-components-react"; + +export const siteName = "KittyGuardedZone"; + +export const favIconAsset: ImageAsset | undefined = { + id: "88d5e2ff-b8f2-4899-aaf8-dde4ade6da10", + name: "DALL_E_2023-10-30_12.39.46_-_Photo_logo_with_a_bold_cat_silhouette_centered_on_a_contrasting_background_designed_for_clarity_at_small_32x32_favicon_resolution_00h6cEA8u2pJRvVJv7hRe.png", + description: null, + projectId: "cddc1d44-af37-4cb6-a430-d300cf6f932d", + size: 268326, + type: "image", + format: "png", + createdAt: "2023-10-30T13:51:08.416+00:00", + meta: { width: 790, height: 786 }, +}; + +// Font assets on current page (can be preloaded) +export const pageFontAssets: FontAsset[] = []; + +export const pageBackgroundImageAssets: ImageAsset[] = []; + +const Body = (props: any) => props.children; +const Heading = (props: any) => null; + +const Page = ({ system: system }: { system: any }) => { + return ( + + + {[ + { + path: "/", + lastModified: "2024-05-07", + }, + { + path: "/olegs-test", + lastModified: "2024-05-07", + }, + ]?.map((url: any, index: number) => ( + + + + {`${system?.origin ?? "${ORIGIN}"}${url?.path}`} + + {url?.lastModified} + + + + ))} + + {"Below is custom section"} + + + {"custom-hand-made-location"} + {"2020-10-10"} + + + + + ); +}; + +export { Page }; diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/index.css b/fixtures/webstudio-remix-vercel/app/__generated__/index.css index 7550b2fda306..82f1e61b4cc1 100644 --- a/fixtures/webstudio-remix-vercel/app/__generated__/index.css +++ b/fixtures/webstudio-remix-vercel/app/__generated__/index.css @@ -392,4 +392,10 @@ .ctm310 { margin-top: 12px; } + .c1jumvji { + margin-top: 1em; + } + .cvdtpev { + margin-bottom: 0em; + } } diff --git a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx index 2a57cb37211a..78ace187c30d 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx @@ -1,34 +1,79 @@ -import type { LoaderFunctionArgs } from "@remix-run/server-runtime"; +import { renderToString } from "react-dom/server"; +import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime"; +import { isLocalResource, loadResources } from "@webstudio-is/sdk"; +import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; +import { Page } from "../__generated__/[sitemap.xml]._index"; +import { + getPageMeta, + getRemixParams, + getResources, +} from "../__generated__/[sitemap.xml]._index.server"; +import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs"; import { sitemap } from "../__generated__/$resources.sitemap.xml"; -export const loader = (arg: LoaderFunctionArgs) => { +const customFetch: typeof fetch = (input, init) => { + if (typeof input !== "string") { + return fetch(input, init); + } + + if (isLocalResource(input, "sitemap.xml")) { + // @todo: dynamic import sitemap ??? + const response = new Response(JSON.stringify(sitemap)); + response.headers.set("content-type", "application/json; charset=utf-8"); + return Promise.resolve(response); + } + + return fetch(input, init); +}; + +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 urls = sitemap.map((page) => { - const url = new URL(`https://${host}${page.path}`); + const params = getRemixParams(arg.params); - return ` - - ${url.href} - ${page.lastModified.split("T")[0]} - - `; - }); + const system = { + params, + search: Object.fromEntries(url.searchParams), + origin: url.origin, + }; - return new Response( - ` - -${urls.join("")} - - `, - { - headers: { - "Content-Type": "application/xml", - }, - status: 200, - } + const resources = await loadResources( + customFetch, + getResources({ system }).data ); + 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; + + const text = renderToString( + + + + ); + + return new Response(`\n${text}`, { + headers: { "Content-Type": "application/xml" }, + }); }; diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.json index 0c09f0366628..5c2590858c96 100644 --- a/fixtures/webstudio-remix-vercel/package.json +++ b/fixtures/webstudio-remix-vercel/package.json @@ -6,7 +6,7 @@ "typecheck": "tsc", "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-cddc1d44-af37-4cb6-a430-d300cf6f932d-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'", - "fixtures:sync": "pnpm cli sync --buildId 6876de3a-942a-466b-9761-ad7cb2fa2c21 && pnpm prettier --write ./.webstudio/", + "fixtures:sync": "pnpm cli sync --buildId 1710e6a3-6f3b-44c9-8e4f-4176be77673e && pnpm prettier --write ./.webstudio/", "fixtures:build": "pnpm cli build --template vercel --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" }, "private": true, diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts index aebc93827ea4..d05ed914d19e 100644 --- a/packages/cli/src/prebuild.ts +++ b/packages/cli/src/prebuild.ts @@ -559,7 +559,7 @@ export const prebuild = async (options: { .map((scopedName) => scopedName === "Body" ? `const ${scopedName} = (props: any) => props.children;` - : `const ${scopedName} = () => null;` + : `const ${scopedName} = (props: any) => null;` ) .join("\n"); } diff --git a/packages/sdk-components-react/src/xml-node.tsx b/packages/sdk-components-react/src/xml-node.tsx index e29a9e80d24d..0c0d2a6fa14e 100644 --- a/packages/sdk-components-react/src/xml-node.tsx +++ b/packages/sdk-components-react/src/xml-node.tsx @@ -14,7 +14,11 @@ export const defaultTag = "div"; type Props = { tag: string; xmlns?: string; - children: ReactNode; + children?: ReactNode; + rel?: string; + hreflang?: string; + href?: string; + "xmlns:xhtml"?: string; }; export const XmlNode = forwardRef, Props>( @@ -34,29 +38,40 @@ export const XmlNode = forwardRef, Props>( return createElement(tag, attrProps, children); } - const isTextChild = Children.toArray(children).every( - (child) => typeof child === "string" - ); + const childrenArray = Children.toArray(children); + const isTextChild = + childrenArray.length > 0 && + childrenArray.every((child) => typeof child === "string"); const elementName = tag // Must start from letter or underscore .replace(/^[^\p{L}_]+/u, "") // Clear all non letter, number, underscore, dot, and dash - .replaceAll(/[^\p{L}\p{N}\-._]+/gu, ""); + .replaceAll(/[^\p{L}\p{N}\-._:]+/gu, ""); const attributes = attributeEntries.map( ([key, value]) => `${key}=${JSON.stringify(value)}` ); return ( -
-
+
+ <{[elementName, ...attributes].join(" ")}> -
-
- {children} -
-
</{elementName}>
+ + {childrenArray.length > 0 && ( +
+ {children} +
+ )} + + </{elementName}> +
); }