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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: fix redirects failing in SSG export (#5556)
Bogdan Chadkin883ac1eddc2c
diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json b/fixtures/ssg-netlify-by-project-id/.webstudio/data.jsonindex 142375b5a0..5ced8e1bff 100644--- a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json+++ b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json@@ -1,10 +1,10 @@{"build": {- "id": "1e6d93b8-3faa-4155-8628-dd31cafaf00e",+ "id": "8f0fdff2-e76b-4f86-9203-ea7df5f1143c","projectId": "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e",- "version": 2,- "createdAt": "2024-09-03T04:32:12.506+00:00",- "updatedAt": "2024-09-03T04:32:12.506+00:00",+ "version": 7,+ "createdAt": "2026-01-04T10:46:48.415+00:00",+ "updatedAt": "2026-01-04T10:46:48.415+00:00","pages": {"meta": {},"homePage": {@@ -16,13 +16,39 @@"meta": {},"path": ""},- "pages": [],+ "pages": [+ {+ "id": "fOBamlMdmM461hLaITmV7",+ "name": "Untitled",+ "title": "\"Untitled\"",+ "rootInstanceId": "6dkXcbi85BtasJdJdkV9L",+ "meta": {+ "description": "\"\"",+ "excludePageFromSearch": "true",+ "language": "\"\"",+ "socialImageUrl": "\"\"",+ "status": "302",+ "redirect": "\"/\"",+ "documentType": "html",+ "custom": [+ {+ "property": "",+ "content": "\"\""+ }+ ]+ },+ "marketplace": {+ "include": false+ },+ "path": "/redirect"+ }+ ],"folders": [{"id": "root","name": "Root","slug": "",- "children": ["Y60VJnVZMU_ifI0GnAR1N"]+ "children": ["Y60VJnVZMU_ifI0GnAR1N", "fOBamlMdmM461hLaITmV7"]}]},@@ -103,12 +129,23 @@}]}+ ],+ [+ "6dkXcbi85BtasJdJdkV9L",+ {+ "type": "instance",+ "id": "6dkXcbi85BtasJdJdkV9L",+ "component": "ws:element",+ "tag": "body",+ "children": []+ }]],"deployment": {"destination": "saas",- "domains": [],- "projectDomain": "fixture-client-do-not-touch-wsmel"+ "domains": ["fixture-client-do-not-touch-wsmel"],+ "assetsDomain": "fixture-client-do-not-touch-wsmel",+ "excludeWstdDomainFromSearch": false}},"page": {@@ -129,6 +166,31 @@"systemDataSourceId": "XE93KQdVwfiA3TCf8hQAQ","meta": {},"path": ""+ },+ {+ "id": "fOBamlMdmM461hLaITmV7",+ "name": "Untitled",+ "title": "\"Untitled\"",+ "rootInstanceId": "6dkXcbi85BtasJdJdkV9L",+ "meta": {+ "description": "\"\"",+ "excludePageFromSearch": "true",+ "language": "\"\"",+ "socialImageUrl": "\"\"",+ "status": "302",+ "redirect": "\"/\"",+ "documentType": "html",+ "custom": [+ {+ "property": "",+ "content": "\"\""+ }+ ]+ },+ "marketplace": {+ "include": false+ },+ "path": "/redirect"}],"assets": [],diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.tsindex 3385a96eab..e54947f47b 100644--- a/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/$resources.sitemap.xml.ts@@ -1,6 +1,6 @@export const sitemap = [{path: "/",- lastModified: "2024-09-03",+ lastModified: "2026-01-04",},];diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.server.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.server.tsxnew file mode 100644index 0000000000..fcd33e9a76--- /dev/null+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.server.tsx@@ -0,0 +1,37 @@+/* 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<string, ResourceRequest>([]);+ const _action = new Map<string, ResourceRequest>([]);+ return { data: _data, action: _action };+};++export const getPageMeta = ({+ system,+ resources,+}: {+ system: System;+ resources: Record<string, any>;+}): PageMeta => {+ return {+ title: "Untitled",+ description: "",+ excludePageFromSearch: true,+ language: "",+ socialImageAssetName: undefined,+ socialImageUrl: "",+ status: 302,+ redirect: "/",+ custom: [],+ };+};++type Params = Record<string, string | undefined>;+export const getRemixParams = ({ ...params }: Params): Params => {+ return params;+};++export const contactEmail = "[email protected]";diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsxnew file mode 100644index 0000000000..933161117c--- /dev/null+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/[redirect]._index.tsx@@ -0,0 +1,31 @@+/* eslint-disable */+/* This is a auto generated file for building the project */++import { Fragment, useState } from "react";+import { useResource, useVariableState } from "@webstudio-is/react-sdk/runtime";++export const projectId = "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e";++export const lastPublished = "2026-01-04T10:46:48.415Z";++export const siteName = undefined;++export const breakpoints = [+ { id: "pTyOZEX5PG52onfyt3-Vg" },+ { id: "GzBytedsc258Pp7rh1hiD", maxWidth: 991 },+ { id: "ugRM71O_Lm78kMKjkrtyz", maxWidth: 767 },+ { id: "NKdYAYw-oxmW8laNbpiwK", maxWidth: 479 },+];++export const favIconAsset: string | undefined = undefined;++// Font assets on current page (can be preloaded)+export const pageFontAssets: string[] = [];++export const pageBackgroundImageAssets: string[] = [];++const Page = (_props: { system: any }) => {+ return <body className={`w-element`} />;+};++export { Page };diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsxindex 149dd43da0..2954d2e601 100644--- a/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/_index.tsx@@ -10,7 +10,7 @@ import {export const projectId = "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e";-export const lastPublished = "2024-09-03T04:32:12.506Z";+export const lastPublished = "2026-01-04T10:46:48.415Z";export const siteName = undefined;diff --git a/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css b/fixtures/ssg-netlify-by-project-id/app/__generated__/index.cssindex c5de6a0d51..4ee35065c1 100644--- a/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css+++ b/fixtures/ssg-netlify-by-project-id/app/__generated__/index.css@@ -8,6 +8,12 @@white-space: pre-wrap;white-space-collapse: preserve;}+ body.w-element {+ box-sizing: border-box;+ -webkit-font-smoothing: antialiased;+ -moz-osx-font-smoothing: grayscale;+ margin: 0;+ }body.w-body {box-sizing: border-box;-webkit-font-smoothing: antialiased;diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/index/+data.tsindex 4afdd988d3..b4ee43ad55 100644--- a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts+++ b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts@@ -1,5 +1,4 @@import type { PageContextServer } from "vike/types";-import { redirect } from "vike/abort";import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";import {getPageMeta,@@ -53,14 +52,6 @@ export const data = async (pageContext: PageContextServer) => {);const pageMeta = getPageMeta({ system, resources });- if (pageMeta.redirect) {- const status =- pageMeta.status === 301 || pageMeta.status === 302- ? pageMeta.status- : 302;- throw redirect(pageMeta.redirect, status);- }-return {url: url.href,system,diff --git a/fixtures/ssg-netlify-by-project-id/pages/redirect/+Head.tsx b/fixtures/ssg-netlify-by-project-id/pages/redirect/+Head.tsxnew file mode 100644index 0000000000..ed0be799ae--- /dev/null+++ b/fixtures/ssg-netlify-by-project-id/pages/redirect/+Head.tsx@@ -0,0 +1,60 @@+import type { PageContext } from "vike/types";+import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";+import {+ favIconAsset,+ pageBackgroundImageAssets,+ pageFontAssets,+ siteName,+} from "../../app/__generated__/[redirect]._index";+import "../../app/__generated__/index.css";++export const Head = ({}: { data: PageContext["data"] }) => {+ const ldJson = {+ "@context": "https://schema.org",+ "@type": "WebSite",+ name: siteName,+ };+ return (+ <>+ {siteName && (+ <script+ type="application/ld+json"+ dangerouslySetInnerHTML={{+ __html: JSON.stringify(ldJson, null, 2),+ }}+ ></script>+ )}+ {favIconAsset && (+ <link+ rel="icon"+ href={imageLoader({+ src: `${assetBaseUrl}${favIconAsset}`,+ // 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",+ })}+ />+ )}+ {pageFontAssets.map((asset) => (+ <link+ key={asset}+ rel="preload"+ href={`${assetBaseUrl}${asset}`}+ as="font"+ crossOrigin="anonymous"+ />+ ))}+ {pageBackgroundImageAssets.map((asset) => (+ <link+ key={asset}+ rel="preload"+ href={`${assetBaseUrl}${asset}`}+ as="image"+ />+ ))}+ </>+ );+};diff --git a/fixtures/ssg-netlify-by-project-id/pages/redirect/+Page.tsx b/fixtures/ssg-netlify-by-project-id/pages/redirect/+Page.tsxnew file mode 100644index 0000000000..260560b8ef--- /dev/null+++ b/fixtures/ssg-netlify-by-project-id/pages/redirect/+Page.tsx@@ -0,0 +1,39 @@+import type { PageContext } from "vike/types";+import {+ PageSettingsMeta,+ PageSettingsTitle,+ ReactSdkContext,+} from "@webstudio-is/react-sdk/runtime";+import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";+import {+ Page,+ breakpoints,+ siteName,+} from "../../app/__generated__/[redirect]._index";++const PageComponent = ({ data }: { data: PageContext["data"] }) => {+ const { system, resources, url, pageMeta } = data;+ return (+ <ReactSdkContext.Provider+ value={{+ imageLoader,+ assetBaseUrl,+ resources,+ breakpoints,+ onError: console.error,+ }}+ >+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}+ <Page key={url} system={system} />+ <PageSettingsMeta+ url={url}+ pageMeta={pageMeta}+ siteName={siteName}+ imageLoader={imageLoader}+ assetBaseUrl={assetBaseUrl}+ />+ <PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>+ </ReactSdkContext.Provider>+ );+};+export default PageComponent;diff --git a/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.tsnew file mode 100644index 0000000000..5412467320--- /dev/null+++ b/fixtures/ssg-netlify-by-project-id/pages/redirect/+data.ts@@ -0,0 +1,61 @@+import type { PageContextServer } from "vike/types";+import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";+import {+ getPageMeta,+ getResources,+} from "../../app/__generated__/[redirect]._index.server";++const customFetch: typeof fetch = (input, init) => {+ if (typeof input !== "string") {+ return fetch(input, init);+ }++ if (isLocalResource(input, "current-date")) {+ const now = new Date();+ // Normalize to midnight UTC to prevent hydration mismatches+ const startOfDay = new Date(+ Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())+ );+ const data = {+ iso: startOfDay.toISOString(),+ year: startOfDay.getUTCFullYear(),+ month: startOfDay.getUTCMonth() + 1, // 1-12 instead of 0-11+ day: startOfDay.getUTCDate(),+ timestamp: startOfDay.getTime(),+ };+ const response = new Response(JSON.stringify(data));+ response.headers.set("content-type", "application/json; charset=utf-8");+ return Promise.resolve(response);+ }++ return fetch(input, init);+};++export const data = async (pageContext: PageContextServer) => {+ const url = new URL(pageContext.urlOriginal, "http://url");+ const headers = new Headers(pageContext.headers ?? {});+ const host = headers.get("x-forwarded-host") || headers.get("host") || "";+ url.host = host;+ url.protocol = "https";++ const params = pageContext.routeParams;+ const system = {+ params,+ search: Object.fromEntries(url.searchParams),+ origin: url.origin,+ pathname: url.pathname,+ };++ const resources = await loadResources(+ customFetch,+ getResources({ system }).data+ );+ const pageMeta = getPageMeta({ system, resources });++ return {+ url: url.href,+ system,+ resources,+ pageMeta,+ } satisfies PageContextServer["data"];+};diff --git a/fixtures/ssg/pages/another-page/+data.ts b/fixtures/ssg/pages/another-page/+data.tsindex 482b02a31b..b839c30933 100644--- a/fixtures/ssg/pages/another-page/+data.ts+++ b/fixtures/ssg/pages/another-page/+data.ts@@ -1,5 +1,4 @@import type { PageContextServer } from "vike/types";-import { redirect } from "vike/abort";import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";import {getPageMeta,@@ -53,14 +52,6 @@ export const data = async (pageContext: PageContextServer) => {);const pageMeta = getPageMeta({ system, resources });- if (pageMeta.redirect) {- const status =- pageMeta.status === 301 || pageMeta.status === 302- ? pageMeta.status- : 302;- throw redirect(pageMeta.redirect, status);- }-return {url: url.href,system,diff --git a/fixtures/ssg/pages/index/+data.ts b/fixtures/ssg/pages/index/+data.tsindex 4afdd988d3..b4ee43ad55 100644--- a/fixtures/ssg/pages/index/+data.ts+++ b/fixtures/ssg/pages/index/+data.ts@@ -1,5 +1,4 @@import type { PageContextServer } from "vike/types";-import { redirect } from "vike/abort";import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";import {getPageMeta,@@ -53,14 +52,6 @@ export const data = async (pageContext: PageContextServer) => {);const pageMeta = getPageMeta({ system, resources });- if (pageMeta.redirect) {- const status =- pageMeta.status === 301 || pageMeta.status === 302- ? pageMeta.status- : 302;- throw redirect(pageMeta.redirect, status);- }-return {url: url.href,system,diff --git a/packages/cli/templates/ssg/app/route-templates/html/+data.ts b/packages/cli/templates/ssg/app/route-templates/html/+data.tsindex bcd1ef6eda..13e0e4ff61 100644--- a/packages/cli/templates/ssg/app/route-templates/html/+data.ts+++ b/packages/cli/templates/ssg/app/route-templates/html/+data.ts@@ -1,5 +1,4 @@import type { PageContextServer } from "vike/types";-import { redirect } from "vike/abort";import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime";import { getPageMeta, getResources } from "__SERVER__";@@ -50,14 +49,6 @@ export const data = async (pageContext: PageContextServer) => {);const pageMeta = getPageMeta({ system, resources });- if (pageMeta.redirect) {- const status =- pageMeta.status === 301 || pageMeta.status === 302- ? pageMeta.status- : 302;- throw redirect(pageMeta.redirect, status);- }-return {url: url.href,system,