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.

Reverting the decision to make nicer looking link targets (#1211)

Oleg Isonene6c5217e7a4b
diff --git a/apps/builder/app/canvas/custom-components/link.tsx b/apps/builder/app/canvas/custom-components/link.tsx
index 49192437b5..dd66fcd3c3 100644
--- a/apps/builder/app/canvas/custom-components/link.tsx
+++ b/apps/builder/app/canvas/custom-components/link.tsx
@@ -47,9 +47,10 @@ export const preserveBuildParams = (href: string, sourceSearch: string) => {
};
// @todo this copy-paste has to go away, along with this wrapper component
+// changing this requires an update in react-sdk/components/link
type Props = Omit<ComponentProps<"a">, "href" | "target"> & {
href?: string;
- target?: "self" | "blank" | "parent" | "top";
+ target?: "_self" | "_blank" | "_parent" | "_top";
prefetch?: "none" | "intent" | "render";
};
diff --git a/packages/prisma-client/prisma/migrations/20230309142820_link-target/migration.ts b/packages/prisma-client/prisma/migrations/20230309142820_link-target/migration.ts
new file mode 100644
index 0000000000..9b4c4d106f
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20230309142820_link-target/migration.ts
@@ -0,0 +1,73 @@
+import { PrismaClient } from "./client";
+
+export default () => {
+ const client = new PrismaClient({
+ // Uncomment to see the queries in console as the migration runs
+ // log: ["query", "info", "warn", "error"],
+ });
+ return client.$transaction(
+ async (prisma) => {
+ let cursor: undefined | { id: string; projectId: string } = undefined;
+ let hasNext = true;
+ const chunkSize = 1000;
+
+ hasNext = true;
+ while (hasNext) {
+ const builds = await prisma.build.findMany({
+ take: chunkSize,
+ where: {
+ OR: [{ isDev: true }, { isProd: true }],
+ },
+ orderBy: {
+ id: "asc",
+ },
+ ...(cursor
+ ? {
+ skip: 1, // Skip the cursor
+ cursor: { id_projectId: cursor },
+ }
+ : null),
+ });
+ const lastBuild = builds.at(-1);
+ if (lastBuild) {
+ cursor = { id: lastBuild.id, projectId: lastBuild.projectId };
+ }
+ hasNext = builds.length === chunkSize;
+
+ const buildsToUpdate = [];
+
+ for (const build of builds) {
+ const props = JSON.parse(build.props);
+ let hasConversion = false;
+
+ // prop.value === 'self' > prop.value === '_self'
+ for (const prop of props) {
+ if (
+ prop.name === "target" &&
+ typeof prop.value === "string" &&
+ prop.value[0] !== "_"
+ ) {
+ prop.value = `_${prop.value}`;
+ hasConversion = true;
+ }
+ }
+
+ if (hasConversion) {
+ build.props = JSON.stringify(props);
+ buildsToUpdate.push(build as never);
+ }
+ }
+
+ await Promise.all(
+ buildsToUpdate.map(({ id, projectId, props }) =>
+ prisma.build.update({
+ where: { id_projectId: { id, projectId } },
+ data: { props },
+ })
+ )
+ );
+ }
+ },
+ { timeout: 1000 * 60 * 8 }
+ );
+};
diff --git a/packages/prisma-client/prisma/migrations/20230309142820_link-target/schema.prisma b/packages/prisma-client/prisma/migrations/20230309142820_link-target/schema.prisma
new file mode 100644
index 0000000000..0097aef08e
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20230309142820_link-target/schema.prisma
@@ -0,0 +1,128 @@
+// DO NOT EDIT THIS FILE!
+// This is a copy of your schema.prisma that corresponds to the state of the database
+// when all migrations up until this one are applied.
+// It's used to generate a Prisma Client for the migration.
+
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+generator client {
+ provider = "prisma-client-js"
+ previewFeatures = ["views", "clientExtensions"]
+ output = "client"
+}
+
+datasource db {
+ provider = "postgres"
+ url = env("DATABASE_URL")
+}
+
+model Team {
+ id String @id @default(uuid())
+ users User[]
+}
+
+enum Location {
+ FS
+ REMOTE
+}
+
+enum UploadStatus {
+ UPLOADING
+ UPLOADED
+}
+
+model Asset {
+ id String @default(uuid()) // not unique!
+ projectId String
+ format String
+ size Int
+ name String
+ description String?
+ location Location
+ createdAt DateTime @default(now())
+ meta String @default("{}")
+ status UploadStatus @default(UPLOADED)
+
+ @@id([id, projectId])
+}
+
+model User {
+ id String @id @default(uuid())
+ email String? @unique
+ provider String?
+ image String?
+ username String?
+ createdAt DateTime @default(now())
+ team Team? @relation(fields: [teamId], references: [id])
+ teamId String?
+ projects Project[]
+}
+
+model Project {
+ id String @id @default(uuid())
+ createdAt DateTime @default(now())
+ title String
+ domain String @unique
+ user User? @relation(fields: [userId], references: [id])
+ userId String?
+ build Build[]
+ isDeleted Boolean @default(false)
+
+ @@unique([id, isDeleted])
+ @@unique([domain, isDeleted])
+}
+
+model Build {
+ id String @default(uuid())
+ createdAt DateTime @default(now())
+ pages String
+
+ project Project @relation(fields: [projectId], references: [id])
+ projectId String
+
+ isDev Boolean // exctly one is true per project
+ isProd Boolean // at most one is true per project (none if not published)
+
+ breakpoints String @default("[]")
+ styles String @default("[]")
+ styleSources String @default("[]")
+ styleSourceSelections String @default("[]")
+ props String @default("[]")
+ instances String @default("[]")
+
+ @@id([id, projectId])
+}
+
+model Breakpoints {
+ buildId String @id
+ values String @default("[]")
+}
+
+enum AuthorizationRelation {
+ viewers
+ editors
+ builders
+}
+
+model AuthorizationToken {
+ token String @default(uuid())
+ // No relation to Project, as the Authorization system is not tied to a project
+ projectId String
+ name String @default("")
+ relation AuthorizationRelation @default(viewers)
+ createdAt DateTime @default(now())
+
+ @@id([token, projectId])
+}
+
+// Dashboard
+view DashboardProject {
+ id String @id @default(uuid())
+ createdAt DateTime @default(now())
+ title String
+ domain String
+ userId String?
+ isDeleted Boolean @default(false)
+ isPublished Boolean
+}
diff --git a/packages/react-sdk/src/components/__generated__/link-block.props.ts b/packages/react-sdk/src/components/__generated__/link-block.props.ts
index 62f777e08d..52ca7c56be 100644
--- a/packages/react-sdk/src/components/__generated__/link-block.props.ts
+++ b/packages/react-sdk/src/components/__generated__/link-block.props.ts
@@ -14,7 +14,7 @@ export const props: Record<string, PropMeta> = {
required: false,
control: "select",
type: "string",
- options: ["self", "blank", "parent", "top"],
+ options: ["_self", "_blank", "_parent", "_top"],
},
type: { required: false, control: "text", type: "string" },
referrerPolicy: {
diff --git a/packages/react-sdk/src/components/__generated__/link.props.ts b/packages/react-sdk/src/components/__generated__/link.props.ts
index 77eb1f20ce..cdb81d3111 100644
--- a/packages/react-sdk/src/components/__generated__/link.props.ts
+++ b/packages/react-sdk/src/components/__generated__/link.props.ts
@@ -14,8 +14,7 @@ export const props: Record<string, PropMeta> = {
required: false,
control: "select",
type: "string",
- defaultValue: "self",
- options: ["self", "blank", "parent", "top"],
+ options: ["_self", "_blank", "_parent", "_top"],
},
type: { required: false, control: "text", type: "string" },
referrerPolicy: {
diff --git a/packages/react-sdk/src/components/__generated__/rich-text-link.props.ts b/packages/react-sdk/src/components/__generated__/rich-text-link.props.ts
index 62f777e08d..52ca7c56be 100644
--- a/packages/react-sdk/src/components/__generated__/rich-text-link.props.ts
+++ b/packages/react-sdk/src/components/__generated__/rich-text-link.props.ts
@@ -14,7 +14,7 @@ export const props: Record<string, PropMeta> = {
required: false,
control: "select",
type: "string",
- options: ["self", "blank", "parent", "top"],
+ options: ["_self", "_blank", "_parent", "_top"],
},
type: { required: false, control: "text", type: "string" },
referrerPolicy: {
diff --git a/packages/react-sdk/src/components/link.tsx b/packages/react-sdk/src/components/link.tsx
index b1ca365f5a..33923f1b36 100644
--- a/packages/react-sdk/src/components/link.tsx
+++ b/packages/react-sdk/src/components/link.tsx
@@ -3,15 +3,16 @@ import { forwardRef, type ElementRef, type ComponentProps } from "react";
// @todo props that come from remix link, shouldn't be here at all
// - prefetch should be only on remix component and it already is
// - props meta should be generated from Remix link
+// - changing this requires update in app/canvas/custom-components/link.tsx
type Props = Omit<ComponentProps<"a">, "href" | "target"> & {
href?: string;
- target?: "self" | "blank" | "parent" | "top";
+ target?: "_self" | "_blank" | "_parent" | "_top";
prefetch?: "none" | "intent" | "render";
};
export const Link = forwardRef<ElementRef<"a">, Props>(
- ({ href = "", target = "self", ...props }, ref) => {
- return <a {...props} target={`_${target}`} href={href} ref={ref} />;
+ ({ href = "", ...props }, ref) => {
+ return <a {...props} href={href} ref={ref} />;
}
);