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.

feat: add Current Date resource, system.pathname, and Time component custom formatting (#5434)

zehjotkah1f2e7a25ee27
diff --git a/apps/builder/app/builder/features/pages/page-utils.test.ts b/apps/builder/app/builder/features/pages/page-utils.test.ts
index 188f5e6807..cfa0cf541b 100644
--- a/apps/builder/app/builder/features/pages/page-utils.test.ts
+++ b/apps/builder/app/builder/features/pages/page-utils.test.ts
@@ -37,6 +37,7 @@ registerContainers();
const initialSystem = {
origin: "https://undefined.wstd.work",
params: {},
+ pathname: "/",
search: {},
};
@@ -586,6 +587,7 @@ test("page root scope should provide page system variable value", () => {
$ws$dataSource$systemId: {
origin: "https://undefined.wstd.work",
params: {},
+ pathname: "/",
search: {},
},
},
@@ -594,6 +596,7 @@ test("page root scope should provide page system variable value", () => {
"systemId",
{
params: {},
+ pathname: "/",
search: {},
origin: "https://undefined.wstd.work",
},
@@ -608,6 +611,7 @@ test("page root scope should provide page system variable value", () => {
scope: {
$ws$dataSource$systemId: {
params: { slug: "my-post" },
+ pathname: "/",
search: {},
origin: "https://undefined.wstd.work",
},
@@ -617,6 +621,7 @@ test("page root scope should provide page system variable value", () => {
"systemId",
{
params: { slug: "my-post" },
+ pathname: "/",
search: {},
origin: "https://undefined.wstd.work",
},
diff --git a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
index fa70518756..0e8bd10261 100644
--- a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
+++ b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
@@ -25,7 +25,11 @@ import {
SYSTEM_VARIABLE_ID,
systemParameter,
} from "@webstudio-is/sdk";
-import { serializeValue, sitemapResourceUrl } from "@webstudio-is/sdk/runtime";
+import {
+ serializeValue,
+ sitemapResourceUrl,
+ currentDateResourceUrl,
+} from "@webstudio-is/sdk/runtime";
import {
Box,
Flex,
@@ -989,6 +993,12 @@ export const SystemResourceForm = forwardRef<
value: JSON.stringify(sitemapResourceUrl),
description: "Resource that loads the sitemap data of the current site.",
},
+ {
+ label: "Current Date",
+ value: JSON.stringify(currentDateResourceUrl),
+ description:
+ "Provides current date information (year, month, day) normalized to midnight UTC. Time components are set to 00:00:00 to prevent React hydration errors.",
+ },
];
const [localResource, setLocalResource] = useState(() => {
diff --git a/apps/builder/app/routes/rest.resources-loader.ts b/apps/builder/app/routes/rest.resources-loader.ts
index 94c239a89b..f59248d308 100644
--- a/apps/builder/app/routes/rest.resources-loader.ts
+++ b/apps/builder/app/routes/rest.resources-loader.ts
@@ -3,6 +3,7 @@ import { type ActionFunctionArgs, data } from "@remix-run/server-runtime";
import { ResourceRequest } from "@webstudio-is/sdk";
import { isLocalResource, loadResource } from "@webstudio-is/sdk/runtime";
import { loader as siteMapLoader } from "../shared/$resources/sitemap.xml.server";
+import { loader as currentDateLoader } from "../shared/$resources/current-date.server";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
import { checkCsrf } from "~/services/csrf-session.server";
import { getResourceKey } from "~/shared/resources";
@@ -21,6 +22,10 @@ export const action = async ({ request }: ActionFunctionArgs) => {
return siteMapLoader({ request });
}
+ if (isLocalResource(input, "current-date")) {
+ return currentDateLoader({ request });
+ }
+
return fetch(input, init);
};
diff --git a/apps/builder/app/shared/$resources/current-date.server.ts b/apps/builder/app/shared/$resources/current-date.server.ts
new file mode 100644
index 0000000000..505579579a
--- /dev/null
+++ b/apps/builder/app/shared/$resources/current-date.server.ts
@@ -0,0 +1,39 @@
+import { json } from "@remix-run/server-runtime";
+import { parseBuilderUrl } from "@webstudio-is/http-client";
+import { isBuilder } from "../router-utils";
+
+/**
+ * System Resource that provides current date information.
+ * This prevents React hydration errors when displaying dynamic dates
+ * (e.g., copyright years in footers) by ensuring server and client
+ * render the same date.
+ *
+ * All values are normalized to midnight UTC (00:00:00.000Z) to ensure
+ * consistency throughout the entire day, preventing hydration mismatches.
+ */
+export const loader = async ({ request }: { request: Request }) => {
+ if (isBuilder(request) === false) {
+ throw new Error("Only builder requests are allowed");
+ }
+
+ const { projectId } = parseBuilderUrl(request.url);
+
+ if (projectId === undefined) {
+ throw new Error("projectId is required");
+ }
+
+ const now = new Date();
+
+ // Normalize to midnight UTC to prevent hydration mismatches
+ const startOfDay = new Date(
+ Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
+ );
+
+ return json({
+ iso: startOfDay.toISOString(),
+ year: startOfDay.getUTCFullYear(),
+ month: startOfDay.getUTCMonth() + 1, // 1-12 instead of 0-11
+ day: startOfDay.getUTCDate(),
+ timestamp: startOfDay.getTime(),
+ });
+};
diff --git a/apps/builder/app/shared/nano-states/props.test.tsx b/apps/builder/app/shared/nano-states/props.test.tsx
index 507ddafc73..10546418dc 100644
--- a/apps/builder/app/shared/nano-states/props.test.tsx
+++ b/apps/builder/app/shared/nano-states/props.test.tsx
@@ -36,6 +36,7 @@ import { $resourcesCache, getResourceKey } from "../resources";
const initialSystem = {
origin: "https://undefined.wstd.work",
params: {},
+ pathname: "/",
search: {},
};
@@ -917,6 +918,7 @@ test("provide page system variable value", () => {
?.get(systemId)
).toEqual({
params: { slug: "my-post" },
+ pathname: "/",
search: {},
origin: "https://undefined.wstd.work",
});
@@ -948,6 +950,7 @@ test("provide global system variable value", () => {
});
const updatedSystem = {
params: { slug: "my-post" },
+ pathname: "/",
search: {},
origin: "https://undefined.wstd.work",
};
diff --git a/apps/builder/app/shared/system.ts b/apps/builder/app/shared/system.ts
index aa36f99984..b42231507b 100644
--- a/apps/builder/app/shared/system.ts
+++ b/apps/builder/app/shared/system.ts
@@ -34,6 +34,7 @@ export const $currentSystem = computed(
const system: System = {
search: {},
params: {},
+ pathname: "/",
origin,
};
if (page === undefined) {
@@ -41,9 +42,12 @@ export const $currentSystem = computed(
}
const systemData = systemByPage.get(page.id);
const extractedParams = extractParams(page.path, page.history?.[0]);
+ const params = { ...extractedParams, ...systemData?.params };
+ const pathname = compilePath(page.path, params) || "/";
return {
search: { ...system.search, ...systemData?.search },
- params: { ...extractedParams, ...systemData?.params },
+ params,
+ pathname,
origin,
};
}
diff --git a/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx b/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
index 13f5ce08b0..850db6a72a 100644
--- a/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-cloudflare/app/routes/[another-page]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-cloudflare/app/routes/_index.tsx b/fixtures/react-router-cloudflare/app/routes/_index.tsx
index 23ce05241b..a0f0da7ba6 100644
--- a/fixtures/react-router-cloudflare/app/routes/_index.tsx
+++ b/fixtures/react-router-cloudflare/app/routes/_index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-docker/app/routes/[another-page]._index.tsx b/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
index 13f5ce08b0..850db6a72a 100644
--- a/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-docker/app/routes/[another-page]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-docker/app/routes/_index.tsx b/fixtures/react-router-docker/app/routes/_index.tsx
index 23ce05241b..a0f0da7ba6 100644
--- a/fixtures/react-router-docker/app/routes/_index.tsx
+++ b/fixtures/react-router-docker/app/routes/_index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx b/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
index 13f5ce08b0..850db6a72a 100644
--- a/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-netlify/app/routes/[another-page]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-netlify/app/routes/_index.tsx b/fixtures/react-router-netlify/app/routes/_index.tsx
index 23ce05241b..a0f0da7ba6 100644
--- a/fixtures/react-router-netlify/app/routes/_index.tsx
+++ b/fixtures/react-router-netlify/app/routes/_index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx b/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
index 13f5ce08b0..850db6a72a 100644
--- a/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
+++ b/fixtures/react-router-vercel/app/routes/[another-page]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/react-router-vercel/app/routes/_index.tsx b/fixtures/react-router-vercel/app/routes/_index.tsx
index 23ce05241b..a0f0da7ba6 100644
--- a/fixtures/react-router-vercel/app/routes/_index.tsx
+++ b/fixtures/react-router-vercel/app/routes/_index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
index 29c99c4068..57293c637e 100644
--- a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts
@@ -18,6 +18,7 @@ export const data = async (pageContext: PageContextServer) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(fetch, getResources({ system }).data);
diff --git a/fixtures/ssg/pages/another-page/+data.ts b/fixtures/ssg/pages/another-page/+data.ts
index 6b4534197b..3b424fa264 100644
--- a/fixtures/ssg/pages/another-page/+data.ts
+++ b/fixtures/ssg/pages/another-page/+data.ts
@@ -18,6 +18,7 @@ export const data = async (pageContext: PageContextServer) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(fetch, getResources({ system }).data);
diff --git a/fixtures/ssg/pages/index/+data.ts b/fixtures/ssg/pages/index/+data.ts
index 29c99c4068..57293c637e 100644
--- a/fixtures/ssg/pages/index/+data.ts
+++ b/fixtures/ssg/pages/index/+data.ts
@@ -18,6 +18,7 @@ export const data = async (pageContext: PageContextServer) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(fetch, getResources({ system }).data);
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
index 6c357a9e8d..b2559fed1d 100644
--- a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx
@@ -71,6 +71,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -204,6 +205,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
index 1baf468dce..9993c144f1 100644
--- a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
+++ b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
@@ -71,6 +71,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -204,6 +205,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
index 77fb67185a..a128a99cb1 100644
--- a/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[_route_with_symbols_]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[animations]._index.tsx b/fixtures/webstudio-features/app/routes/[animations]._index.tsx
index f240fdfef0..59d4dcd8b5 100644
--- a/fixtures/webstudio-features/app/routes/[animations]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[animations]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[class-names]._index.tsx b/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
index d8791547f4..c870d7b2fe 100644
--- a/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[class-names]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[content-block]._index.tsx b/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
index 939509cbed..143d660b39 100644
--- a/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[content-block]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[duration]._index.tsx b/fixtures/webstudio-features/app/routes/[duration]._index.tsx
index 31ee645445..e6305aa6f3 100644
--- a/fixtures/webstudio-features/app/routes/[duration]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[duration]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[expressions]._index.tsx b/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
index b2a0f977ef..33df4e59e2 100644
--- a/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[expressions]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[form]._index.tsx b/fixtures/webstudio-features/app/routes/[form]._index.tsx
index c331a23705..ca398fb216 100644
--- a/fixtures/webstudio-features/app/routes/[form]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[form]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx b/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
index 85071d61b2..ef659d7fa2 100644
--- a/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[head-tag]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
index d5566ad117..100a05c4d4 100644
--- a/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[heading-with-id]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx b/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
index dfca5b9247..1c26997475 100644
--- a/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[nested].[nested-page]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[radix]._index.tsx b/fixtures/webstudio-features/app/routes/[radix]._index.tsx
index dc0c7ceef6..ab9d807901 100644
--- a/fixtures/webstudio-features/app/routes/[radix]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[radix]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[resources]._index.tsx b/fixtures/webstudio-features/app/routes/[resources]._index.tsx
index f2d19bd039..9442e39b91 100644
--- a/fixtures/webstudio-features/app/routes/[resources]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[resources]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
index ff394e97f7..f79dd39e93 100644
--- a/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[sitemap.xml]._index.tsx
@@ -44,6 +44,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
diff --git a/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx b/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
index 4cda7f1b4c..ad38da0eac 100644
--- a/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
+++ b/fixtures/webstudio-features/app/routes/[text-duration]._index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/fixtures/webstudio-features/app/routes/_index.tsx b/fixtures/webstudio-features/app/routes/_index.tsx
index 23ce05241b..a0f0da7ba6 100644
--- a/fixtures/webstudio-features/app/routes/_index.tsx
+++ b/fixtures/webstudio-features/app/routes/_index.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/packages/cli/templates/defaults/app/route-templates/html.tsx b/packages/cli/templates/defaults/app/route-templates/html.tsx
index fb3c6295e4..ba33de0fae 100644
--- a/packages/cli/templates/defaults/app/route-templates/html.tsx
+++ b/packages/cli/templates/defaults/app/route-templates/html.tsx
@@ -71,6 +71,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -204,6 +205,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/packages/cli/templates/defaults/app/route-templates/xml.tsx b/packages/cli/templates/defaults/app/route-templates/xml.tsx
index 354b7d9ab1..779d3fb0c8 100644
--- a/packages/cli/templates/defaults/app/route-templates/xml.tsx
+++ b/packages/cli/templates/defaults/app/route-templates/xml.tsx
@@ -40,6 +40,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
diff --git a/packages/cli/templates/react-router/app/route-templates/html.tsx b/packages/cli/templates/react-router/app/route-templates/html.tsx
index 894af05a9c..b4b47d0cfd 100644
--- a/packages/cli/templates/react-router/app/route-templates/html.tsx
+++ b/packages/cli/templates/react-router/app/route-templates/html.tsx
@@ -70,6 +70,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
@@ -203,6 +204,7 @@ export const action = async ({
params: {},
search: {},
origin: url.origin,
+ pathname: url.pathname,
};
const resourceName = formData.get(formIdFieldName);
diff --git a/packages/cli/templates/react-router/app/route-templates/xml.tsx b/packages/cli/templates/react-router/app/route-templates/xml.tsx
index edf9e3e1f4..7cc6623097 100644
--- a/packages/cli/templates/react-router/app/route-templates/xml.tsx
+++ b/packages/cli/templates/react-router/app/route-templates/xml.tsx
@@ -40,6 +40,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(
diff --git a/packages/cli/templates/ssg/app/route-templates/html/+data.ts b/packages/cli/templates/ssg/app/route-templates/html/+data.ts
index 90d61539b4..a4dd7565ea 100644
--- a/packages/cli/templates/ssg/app/route-templates/html/+data.ts
+++ b/packages/cli/templates/ssg/app/route-templates/html/+data.ts
@@ -15,6 +15,7 @@ export const data = async (pageContext: PageContextServer) => {
params,
search: Object.fromEntries(url.searchParams),
origin: url.origin,
+ pathname: url.pathname,
};
const resources = await loadResources(fetch, getResources({ system }).data);
diff --git a/packages/sdk-components-react/src/__generated__/html-embed.props.ts b/packages/sdk-components-react/src/__generated__/html-embed.props.ts
index 08ad345b3d..719d2a840f 100644
--- a/packages/sdk-components-react/src/__generated__/html-embed.props.ts
+++ b/packages/sdk-components-react/src/__generated__/html-embed.props.ts
@@ -5,7 +5,7 @@ export const props: Record<string, PropMeta> = {
required: false,
control: "text",
type: "string",
- description: "Classes to which the element belongs",
+ description: "",
},
clientOnly: { required: false, control: "boolean", type: "boolean" },
code: { required: true, control: "text", type: "string" },
diff --git a/packages/sdk-components-react/src/__generated__/time.props.ts b/packages/sdk-components-react/src/__generated__/time.props.ts
index 852f06d4a7..b37ef21bf0 100644
--- a/packages/sdk-components-react/src/__generated__/time.props.ts
+++ b/packages/sdk-components-react/src/__generated__/time.props.ts
@@ -215,6 +215,13 @@ export const props: Record<string, PropMeta> = {
defaultValue: "medium",
options: ["full", "long", "medium", "short", "none"],
},
+ format: {
+ description:
+ 'Custom format template string. When provided, overrides Date Style and Time Style.\nSupports tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s.\nExample: "YYYY-MM-DD HH:mm:ss" displays as "2025-11-03 18:47:25"',
+ required: false,
+ control: "text",
+ type: "string",
+ },
language: {
required: false,
control: "select",
diff --git a/packages/sdk-components-react/src/__generated__/xml-node.props.ts b/packages/sdk-components-react/src/__generated__/xml-node.props.ts
index 430d4bfc29..296ecba187 100644
--- a/packages/sdk-components-react/src/__generated__/xml-node.props.ts
+++ b/packages/sdk-components-react/src/__generated__/xml-node.props.ts
@@ -5,7 +5,7 @@ export const props: Record<string, PropMeta> = {
required: false,
control: "text",
type: "string",
- description: "Document base URL",
+ description: "Address of the hyperlink",
},
hreflang: {
required: false,
diff --git a/packages/sdk-components-react/src/time.test.ts b/packages/sdk-components-react/src/time.test.ts
index edaad1fd4a..6ccb3b5d02 100644
--- a/packages/sdk-components-react/src/time.test.ts
+++ b/packages/sdk-components-react/src/time.test.ts
@@ -1,7 +1,7 @@
import { expect, test } from "vitest";
import { __testing__ } from "./time";
-const { parseDate } = __testing__;
+const { parseDate, formatDate } = __testing__;
test("13-digit Unix timestamp", () => {
expect(parseDate("1724938577059")).toEqual(
@@ -43,3 +43,38 @@ test("empty string", () => {
test("invalid date string", () => {
expect(parseDate("whatever that is")).toEqual(undefined);
});
+
+test("formatDate with full template", () => {
+ const date = new Date("2025-10-31T14:05:09");
+ expect(formatDate(date, "YYYY-MM-DD HH:mm:ss")).toBe("2025-10-31 14:05:09");
+});
+
+test("formatDate with short date", () => {
+ const date = new Date("2025-10-31T14:05:09");
+ expect(formatDate(date, "DD/MM/YY")).toBe("31/10/25");
+});
+
+test("formatDate with time only", () => {
+ const date = new Date("2025-10-31T14:05:09");
+ expect(formatDate(date, "H:m:s")).toBe("14:5:9");
+});
+
+test("formatDate with padded values", () => {
+ const date = new Date("2025-01-05T08:03:07");
+ expect(formatDate(date, "YYYY-MM-DD HH:mm:ss")).toBe("2025-01-05 08:03:07");
+});
+
+test("formatDate with unpadded values", () => {
+ const date = new Date("2025-01-05T08:03:07");
+ expect(formatDate(date, "YYYY-M-D H:m:s")).toBe("2025-1-5 8:3:7");
+});
+
+test("formatDate with year only", () => {
+ const date = new Date("2025-10-31T14:05:09");
+ expect(formatDate(date, "YYYY")).toBe("2025");
+});
+
+test("formatDate with custom separator", () => {
+ const date = new Date("2025-10-31T14:05:09");
+ expect(formatDate(date, "DD.MM.YYYY")).toBe("31.10.2025");
+});
diff --git a/packages/sdk-components-react/src/time.tsx b/packages/sdk-components-react/src/time.tsx
index 44df0070c8..9cd9f8f9e9 100644
--- a/packages/sdk-components-react/src/time.tsx
+++ b/packages/sdk-components-react/src/time.tsx
@@ -345,11 +345,45 @@ const parseDate = (datetimeString: string) => {
}
};
+/**
+ * Format a date using a template string.
+ * Supports tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s
+ * Example: formatDate(new Date(), "YYYY-MM-DD HH:mm:ss") => "2025-11-03 18:47:25"
+ */
+const formatDate = (date: Date, template: string): string => {
+ const pad = (n: number, length = 2) => String(n).padStart(length, "0");
+
+ const tokens: Record<string, string | number> = {
+ YYYY: date.getFullYear(),
+ YY: String(date.getFullYear()).slice(-2),
+ MM: pad(date.getMonth() + 1),
+ M: date.getMonth() + 1,
+ DD: pad(date.getDate()),
+ D: date.getDate(),
+ HH: pad(date.getHours()),
+ H: date.getHours(),
+ mm: pad(date.getMinutes()),
+ m: date.getMinutes(),
+ ss: pad(date.getSeconds()),
+ s: date.getSeconds(),
+ };
+
+ return template.replace(/\b(YYYY|YY|MM|M|DD|D|HH|H|mm|m|ss|s)\b/g, (match) =>
+ String(tokens[match])
+ );
+};
+
type TimeProps = Pick<ComponentProps<"time">, "dateTime"> & {
language?: Language;
country?: Country;
dateStyle?: DateStyle;
timeStyle?: TimeStyle;
+ /**
+ * Custom format template string. When provided, overrides Date Style and Time Style.
+ * Supports tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s.
+ * Example: "YYYY-MM-DD HH:mm:ss" displays as "2025-11-03 18:47:25"
+ */
+ format?: string;
};
export const Time = forwardRef<ElementRef<"time">, TimeProps>(
@@ -359,6 +393,7 @@ export const Time = forwardRef<ElementRef<"time">, TimeProps>(
country = DEFAULT_COUNTRY,
dateStyle = DEFAULT_DATE_STYLE,
timeStyle = DEFAULT_TIME_STYLE,
+ format,
// native html attribute in react style
dateTime = INITIAL_DATE_STRING,
...props
@@ -381,10 +416,20 @@ export const Time = forwardRef<ElementRef<"time">, TimeProps>(
let formattedDate = datetimeString;
if (date) {
- try {
- formattedDate = new Intl.DateTimeFormat(locale, options).format(date);
- } catch {
- /* Do Nothing */
+ // Use custom format template if provided
+ if (format) {
+ try {
+ formattedDate = formatDate(date, format);
+ } catch {
+ /* Do Nothing */
+ }
+ } else {
+ // Otherwise use Intl.DateTimeFormat
+ try {
+ formattedDate = new Intl.DateTimeFormat(locale, options).format(date);
+ } catch {
+ /* Do Nothing */
+ }
}
}
@@ -398,4 +443,5 @@ export const Time = forwardRef<ElementRef<"time">, TimeProps>(
export const __testing__ = {
parseDate,
+ formatDate,
};
diff --git a/packages/sdk-components-react/src/time.ws.ts b/packages/sdk-components-react/src/time.ws.ts
index 081b6ad514..dbfec6c67d 100644
--- a/packages/sdk-components-react/src/time.ws.ts
+++ b/packages/sdk-components-react/src/time.ws.ts
@@ -13,6 +13,13 @@ export const meta: WsComponentMeta = {
presetStyle: {
time,
},
- initialProps: ["datetime", "language", "country", "dateStyle", "timeStyle"],
+ initialProps: [
+ "datetime",
+ "language",
+ "country",
+ "dateStyle",
+ "timeStyle",
+ "format",
+ ],
props,
};
diff --git a/packages/sdk/src/resource-loader.ts b/packages/sdk/src/resource-loader.ts
index b49d0606eb..6a522d34a1 100644
--- a/packages/sdk/src/resource-loader.ts
+++ b/packages/sdk/src/resource-loader.ts
@@ -18,6 +18,7 @@ export const isLocalResource = (pathname: string, resourceName?: string) => {
};
export const sitemapResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/sitemap.xml`;
+export const currentDateResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/current-date`;
export const loadResource = async (
customFetch: typeof fetch,
diff --git a/packages/sdk/src/schema/pages.ts b/packages/sdk/src/schema/pages.ts
index 9462d03081..521ed21cf2 100644
--- a/packages/sdk/src/schema/pages.ts
+++ b/packages/sdk/src/schema/pages.ts
@@ -3,6 +3,7 @@ import { z } from "zod";
export type System = {
params: Record<string, string | undefined>;
search: Record<string, string | undefined>;
+ pathname: string;
origin: string;
};