Skip to content

Commit 4ee4963

Browse files
committed
Fix for the run inspector now opening when linked from another run/replay
1 parent 7932a05 commit 4ee4963

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed

apps/webapp/app/hooks/useReplaceLocation.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useSearchParams } from "@remix-run/react";
2+
import { useCallback } from "react";
3+
4+
export function useReplaceSearchParams() {
5+
const [searchParams, setSearchParams] = useSearchParams();
6+
7+
const replaceSearchParam = useCallback(
8+
(key: string, value?: string) => {
9+
setSearchParams((s) => {
10+
if (value) {
11+
s.set(key, value);
12+
} else {
13+
s.delete(key);
14+
}
15+
return s;
16+
});
17+
},
18+
[searchParams]
19+
);
20+
21+
return { searchParams, setSearchParams, replaceSearchParam };
22+
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { useEventSource } from "~/hooks/useEventSource";
6262
import { useInitialDimensions } from "~/hooks/useInitialDimensions";
6363
import { useOrganization } from "~/hooks/useOrganizations";
6464
import { useProject } from "~/hooks/useProject";
65-
import { useReplaceLocation } from "~/hooks/useReplaceLocation";
65+
import { useReplaceSearchParams } from "~/hooks/useReplaceSearchParams";
6666
import { Shortcut, useShortcutKeys } from "~/hooks/useShortcutKeys";
6767
import { useUser } from "~/hooks/useUser";
6868
import { Run, RunPresenter } from "~/presenters/v3/RunPresenter.server";
@@ -142,11 +142,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
142142

143143
type LoaderData = SerializeFrom<typeof loader>;
144144

145-
function getSpanId(location: Location<any>): string | undefined {
146-
const search = new URLSearchParams(location.search);
147-
return search.get("span") ?? undefined;
148-
}
149-
150145
export default function Page() {
151146
const { run, trace, resizable, maximumLiveReloadingSetting } = useLoaderData<typeof loader>();
152147
const user = useUser();
@@ -259,8 +254,8 @@ export default function Page() {
259254
function TraceView({ run, trace, maximumLiveReloadingSetting, resizable }: LoaderData) {
260255
const organization = useOrganization();
261256
const project = useProject();
262-
const { location, replaceSearchParam } = useReplaceLocation();
263-
const selectedSpanId = getSpanId(location);
257+
const { searchParams, replaceSearchParam } = useReplaceSearchParams();
258+
const selectedSpanId = searchParams.get("span") ?? undefined;
264259

265260
if (!trace) {
266261
return <></>;

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.electric.$runParam/route.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { useDebounce } from "~/hooks/useDebounce";
6464
import { useInitialDimensions } from "~/hooks/useInitialDimensions";
6565
import { useOrganization } from "~/hooks/useOrganizations";
6666
import { useProject } from "~/hooks/useProject";
67-
import { useReplaceLocation } from "~/hooks/useReplaceLocation";
67+
import { useReplaceSearchParams } from "~/hooks/useReplaceSearchParams";
6868
import { Shortcut, useShortcutKeys } from "~/hooks/useShortcutKeys";
6969
import { useSyncRunPage } from "~/hooks/useSyncRunPage";
7070
import { Trace, TraceEvent } from "~/hooks/useSyncTrace";
@@ -147,11 +147,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
147147

148148
type LoaderData = UseDataFunctionReturn<typeof loader>;
149149

150-
function getSpanId(location: Location<any>): string | undefined {
151-
const search = new URLSearchParams(location.search);
152-
return search.get("span") ?? undefined;
153-
}
154-
155150
export default function Page() {
156151
const { run, resizable } = useTypedLoaderData<typeof loader>();
157152

@@ -265,8 +260,8 @@ type InspectorState =
265260
| undefined;
266261

267262
function Panels({ resizable, run: originalRun }: LoaderData) {
268-
const { location, replaceSearchParam } = useReplaceLocation();
269-
const selectedSpanId = getSpanId(location);
263+
const { searchParams, replaceSearchParam } = useReplaceSearchParams();
264+
const selectedSpanId = searchParams.get("span") ?? undefined;
270265

271266
const appOrigin = useAppOrigin();
272267
const { isUpToDate, events, runs } = useSyncRunPage({

0 commit comments

Comments
 (0)