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.

fix: treat link urls without pathname as self reference (#3484)

Bogdan Chadkin076437541093
diff --git a/apps/builder/app/canvas/interceptor.ts b/apps/builder/app/canvas/interceptor.ts
index e46ffe3567..eecb9694d3 100644
--- a/apps/builder/app/canvas/interceptor.ts
+++ b/apps/builder/app/canvas/interceptor.ts
@@ -39,10 +39,11 @@ const switchPageAndUpdateSystem = (href: string, formData?: FormData) => {
if (pages === undefined) {
return;
}
- if (href === "") {
+ // preserve pathname when not specified in href/action
+ if (href === "" || href.startsWith("?") || href.startsWith("#")) {
const pathname = getSelectedPagePathname();
if (pathname) {
- href = pathname;
+ href = pathname + href;
}
}
const pageHref = new URL(href, "https://any-valid.url");
diff --git a/packages/sdk-components-react-remix/src/shared/remix-link.tsx b/packages/sdk-components-react-remix/src/shared/remix-link.tsx
index c323bc0b98..51e077c04b 100644
--- a/packages/sdk-components-react-remix/src/shared/remix-link.tsx
+++ b/packages/sdk-components-react-remix/src/shared/remix-link.tsx
@@ -20,10 +20,13 @@ export const wrapLinkComponent = (BaseLink: typeof Link) => {
// cast to string when invalid value type is provided with binding
const href = String(props.href ?? "");
- // use remix link for home page and all relative urls
+ // use remix link for self reference and all relative urls
// ignore asset paths which can be relative too
if (
+ // remix appends ?index in runtime but not in ssr
href === "" ||
+ href.startsWith("?") ||
+ href.startsWith("#") ||
(href.startsWith("/") && href.startsWith(assetBaseUrl) === false)
) {
// remix links behave in unexpected way when delete in content editable