Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(dashboard): stop double-encoding entity ids in links

Carl-Gerhard Lindesvärdbf439746a787
diff --git a/apps/start/src/components/events/table/columns.tsx b/apps/start/src/components/events/table/columns.tsx
index 27478b332..fd560bff6 100644
--- a/apps/start/src/components/events/table/columns.tsx
+++ b/apps/start/src/components/events/table/columns.tsx
@@ -102,7 +102,8 @@ export function useColumns() {
return (
<ProjectLink
className="group row items-center gap-2 whitespace-nowrap font-medium hover:underline"
- href={`/profiles/${encodeURIComponent(profile.id)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: profile.id }}
>
<ProfileAvatar size="sm" {...profile} />
{getProfileName(profile)}
@@ -114,7 +115,8 @@ export function useColumns() {
return (
<ProjectLink
className="whitespace-nowrap font-medium hover:underline"
- href={`/profiles/${encodeURIComponent(profileId)}`}
+ to="/profiles/$profileId"
+ params={{ profileId }}
>
Unknown
</ProjectLink>
@@ -125,7 +127,8 @@ export function useColumns() {
return (
<ProjectLink
className="whitespace-nowrap font-medium hover:underline"
- href={`/profiles/${encodeURIComponent(deviceId)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: deviceId }}
>
Anonymous
</ProjectLink>
@@ -147,7 +150,8 @@ export function useColumns() {
return (
<ProjectLink
className="whitespace-nowrap font-medium hover:underline"
- href={`/sessions/${encodeURIComponent(sessionId)}`}
+ to="/sessions/$sessionId"
+ params={{ sessionId }}
>
{sessionId.slice(0, 6)}
</ProjectLink>
diff --git a/apps/start/src/components/links.tsx b/apps/start/src/components/links.tsx
index 7636d0a03..1437879a6 100644
--- a/apps/start/src/components/links.tsx
+++ b/apps/start/src/components/links.tsx
@@ -1,36 +1,57 @@
import { useAppParams } from '@/hooks/use-app-params';
import { Link, type LinkComponentProps } from '@tanstack/react-router';
-import { omit } from 'ramda';
-export function ProjectLink({
- children,
- ...props
-}: LinkComponentProps & {
+type ProjectLinkBaseProps = Omit<
+ LinkComponentProps,
+ 'to' | 'href' | 'params'
+> & {
children: React.ReactNode;
className?: string;
title?: string;
exact?: boolean;
-}) {
+};
+
+/**
+ * `href` is a project-relative pathname whose segments are already final
+ * (`/profiles`, `/settings`). Use it for static links only — an id
+ * interpolated here becomes a literal path segment, so it breaks on any id
+ * containing `/`, `#` or `?`.
+ *
+ * `to` is a project-relative route template whose dynamic segments are filled
+ * from `params` (`to="/profiles/$profileId"`). The router encodes each param
+ * exactly once, so this is the safe form for anything id-shaped. Never hand a
+ * pre-encoded value to `params` — that is what produced `%2540` in the URL for
+ * email-identified profiles.
+ */
+type ProjectLinkProps = ProjectLinkBaseProps &
+ (
+ | { href: string; to?: never; params?: never }
+ | { to: string; params?: Record<string, string>; href?: never }
+ );
+
+export function ProjectLink({
+ children,
+ exact,
+ to,
+ href,
+ params,
+ ...rest
+}: ProjectLinkProps) {
const { organizationId, projectId } = useAppParams();
- if (typeof props.href === 'string') {
- return (
- <Link
- to={
- `/$organizationId/$projectId/${props.href.replace(/^\//, '')}` as any
- }
- activeOptions={{ exact: props.exact ?? true }}
- params={
- {
- organizationId,
- projectId,
- } as any
- }
- {...omit(['href'], props)}
- >
- {children}
- </Link>
- );
+ const path = to ?? href;
+
+ if (typeof path !== 'string') {
+ return <p>ProjectLink</p>;
}
- return <p>ProjectLink</p>;
+ return (
+ <Link
+ {...rest}
+ to={`/$organizationId/$projectId/${path.replace(/^\//, '')}` as any}
+ params={{ organizationId, projectId, ...params } as any}
+ activeOptions={{ exact: exact ?? true }}
+ >
+ {children}
+ </Link>
+ );
}
diff --git a/apps/start/src/components/notifications/table/columns.tsx b/apps/start/src/components/notifications/table/columns.tsx
index ae1f3e21d..4831c5b75 100644
--- a/apps/start/src/components/notifications/table/columns.tsx
+++ b/apps/start/src/components/notifications/table/columns.tsx
@@ -149,7 +149,8 @@ export function useColumns() {
}
return (
<ProjectLink
- href={`/profiles/${encodeURIComponent(event.profileId)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: event.profileId }}
className="inline-flex min-w-full flex-none items-center gap-2"
>
{event.profileId}
diff --git a/apps/start/src/components/profiles/profile-groups.tsx b/apps/start/src/components/profiles/profile-groups.tsx
index b15f9ccfa..c99f37a37 100644
--- a/apps/start/src/components/profiles/profile-groups.tsx
+++ b/apps/start/src/components/profiles/profile-groups.tsx
@@ -31,7 +31,8 @@ export const ProfileGroups = ({ projectId, groups }: Props) => {
{query.data.map((group) => (
<ProjectLink
key={group.id}
- href={`/groups/${encodeURIComponent(group.id)}`}
+ to="/groups/$groupId"
+ params={{ groupId: group.id }}
className="inline-flex items-center gap-1.5 rounded-full border bg-muted/50 px-2.5 py-1 text-xs transition-colors hover:bg-muted"
>
<span className="font-medium">{group.name}</span>
diff --git a/apps/start/src/components/profiles/table/columns.tsx b/apps/start/src/components/profiles/table/columns.tsx
index 63c741e0f..b37b0671c 100644
--- a/apps/start/src/components/profiles/table/columns.tsx
+++ b/apps/start/src/components/profiles/table/columns.tsx
@@ -16,7 +16,8 @@ export function useColumns(type: 'profiles' | 'power-users') {
return (
<ProjectLink
className="flex items-center gap-2 font-medium"
- href={`/profiles/${encodeURIComponent(profile.id)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: profile.id }}
title={getProfileName(profile, false)}
>
<ProfileAvatar size="sm" {...profile} />
@@ -128,7 +129,8 @@ export function useColumns(type: 'profiles' | 'power-users') {
{groups.map((g) => (
<ProjectLink
className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs hover:underline"
- href={`/groups/${encodeURIComponent(g)}`}
+ to="/groups/$groupId"
+ params={{ groupId: g }}
key={g}
>
{g}
diff --git a/apps/start/src/components/profiles/table/index.tsx b/apps/start/src/components/profiles/table/index.tsx
index 38f2d05c3..de1623e7a 100644
--- a/apps/start/src/components/profiles/table/index.tsx
+++ b/apps/start/src/components/profiles/table/index.tsx
@@ -45,7 +45,7 @@ export const ProfilesTable = memo(
params: {
organizationId,
projectId,
- profileId: encodeURIComponent(row.original.id),
+ profileId: row.original.id,
},
});
},
diff --git a/apps/start/src/components/realtime/map/map-badge-detail-card.tsx b/apps/start/src/components/realtime/map/map-badge-detail-card.tsx
index 937ac38c9..4b74e3509 100644
--- a/apps/start/src/components/realtime/map/map-badge-detail-card.tsx
+++ b/apps/start/src/components/realtime/map/map-badge-detail-card.tsx
@@ -200,13 +200,22 @@ export function MapBadgeDetailCard({
<div className="space-y-3">
{query.data.recentProfiles.length > 0 ? (
query.data.recentProfiles.map((profile) => {
- const href = profile.profileId
- ? `/profiles/${encodeURIComponent(profile.profileId)}`
- : `/sessions/${encodeURIComponent(profile.sessionId)}`;
+ const link: {
+ to: string;
+ params: Record<string, string>;
+ } = profile.profileId
+ ? {
+ to: '/profiles/$profileId',
+ params: { profileId: profile.profileId },
+ }
+ : {
+ to: '/sessions/$sessionId',
+ params: { sessionId: profile.sessionId },
+ };
return (
<ProjectLink
className="-mx-1 flex items-center gap-3 rounded-lg px-1 py-0.5 transition-colors hover:bg-def-200"
- href={href}
+ {...link}
key={
profile.profileId
? `p:${profile.profileId}`
diff --git a/apps/start/src/components/realtime/realtime-active-sessions.tsx b/apps/start/src/components/realtime/realtime-active-sessions.tsx
index 3ac518954..e83522331 100644
--- a/apps/start/src/components/realtime/realtime-active-sessions.tsx
+++ b/apps/start/src/components/realtime/realtime-active-sessions.tsx
@@ -40,7 +40,8 @@ export function RealtimeActiveSessions({
>
<ProjectLink
className="relative block p-4 py-3 pr-14"
- href={`/sessions/${session.sessionId}`}
+ to="/sessions/$sessionId"
+ params={{ sessionId: session.sessionId }}
>
<div className="col flex-1 gap-1">
{session.name === 'screen_view' && (
diff --git a/apps/start/src/components/sessions/table/columns.tsx b/apps/start/src/components/sessions/table/columns.tsx
index dedf3ddbf..c65aac9b6 100644
--- a/apps/start/src/components/sessions/table/columns.tsx
+++ b/apps/start/src/components/sessions/table/columns.tsx
@@ -46,7 +46,8 @@ export function useColumns() {
<div className="row items-center gap-2">
<ProjectLink
className="font-medium"
- href={`/sessions/${session.id}`}
+ to="/sessions/$sessionId"
+ params={{ sessionId: session.id }}
title={session.id}
>
{session.id.slice(0, 8)}...
@@ -55,7 +56,9 @@ export function useColumns() {
<ProjectLink
aria-label="View replay"
className="text-muted-foreground hover:text-foreground"
- href={`/sessions/${session.id}#replay`}
+ to="/sessions/$sessionId"
+ params={{ sessionId: session.id }}
+ hash="replay"
title="View replay"
>
<Video className="size-4" />
@@ -75,7 +78,8 @@ export function useColumns() {
return (
<ProjectLink
className="row items-center gap-2 font-medium hover:underline"
- href={`/profiles/${encodeURIComponent(session.profile.id)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: session.profile.id }}
>
<ProfileAvatar size="sm" {...session.profile} />
{getProfileName(session.profile)}
@@ -85,7 +89,8 @@ export function useColumns() {
return (
<ProjectLink
className="font-medium font-mono"
- href={`/profiles/${encodeURIComponent(session.profileId)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: session.profileId }}
>
{session.profileId}
</ProjectLink>
diff --git a/apps/start/src/modals/event-details.tsx b/apps/start/src/modals/event-details.tsx
index 5b0833096..83aa5c5c6 100644
--- a/apps/start/src/modals/event-details.tsx
+++ b/apps/start/src/modals/event-details.tsx
@@ -233,7 +233,8 @@ function EventDetailsContent({ id, createdAt, projectId }: Props) {
{profile && (
<ProjectLink
className="card col gap-2 p-4 py-2 hover:bg-def-100"
- href={`/profiles/${encodeURIComponent(profile.id)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: profile.id }}
onClick={() => popModal()}
>
<div className="row items-center justify-between gap-2">
diff --git a/apps/start/src/modals/view-chart-users.tsx b/apps/start/src/modals/view-chart-users.tsx
index f6b03be0d..9d117ce9a 100644
--- a/apps/start/src/modals/view-chart-users.tsx
+++ b/apps/start/src/modals/view-chart-users.tsx
@@ -25,7 +25,8 @@ const ProfileItem = ({ profile }: { profile: any }) => {
return (
<ProjectLink
preload={false}
- href={`/profiles/${encodeURIComponent(profile.id)}`}
+ to="/profiles/$profileId"
+ params={{ profileId: profile.id }}
title={getProfileName(profile, false)}
className="col gap-2 rounded-lg border p-2 bg-card"
onClick={(e) => {
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.cohorts.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.cohorts.tsx
index 8b891e948..25e4d9ebb 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.cohorts.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.cohorts.tsx
@@ -122,7 +122,8 @@ function Component() {
return (
<Card key={cohort.id} hover>
<ProjectLink
- href={`/cohorts/${cohort.id}`}
+ to="/cohorts/$cohortId"
+ params={{ cohortId: cohort.id }}
className="flex flex-col p-4 outline-none"
>
<div className="col gap-2">