Skip to content

Commit 11c79d8

Browse files
Fix issue with share links not including domain sub paths
1 parent af85596 commit 11c79d8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/web/src/app/api/(client)/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { NEXT_PUBLIC_DOMAIN_SUB_PATH } from "@/lib/environment.client";
44
import { fileSourceResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
55
import { FileSourceRequest, FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
6+
import assert from "assert";
67

78
export const search = async (body: SearchRequest): Promise<SearchResponse> => {
89
const path = resolveServerPath("/api/search");
@@ -48,5 +49,6 @@ export const getRepos = async (): Promise<ListRepositoriesResponse> => {
4849
* the base path (if any).
4950
*/
5051
export const resolveServerPath = (path: string) => {
52+
assert(path.startsWith("/"));
5153
return `${NEXT_PUBLIC_DOMAIN_SUB_PATH}${path}`;
5254
}

packages/web/src/app/components/editorContextMenu.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { autoPlacement, computePosition, offset, shift, VirtualElement } from "@
88
import { Link2Icon } from "@radix-ui/react-icons";
99
import { EditorView, SelectionRange } from "@uiw/react-codemirror";
1010
import { useCallback, useEffect, useRef } from "react";
11+
import { resolveServerPath } from "../api/(client)/client";
1112

1213
interface ContextMenuProps {
1314
view: EditorView;
@@ -103,7 +104,10 @@ export const EditorContextMenu = ({
103104
const from = toLineAndColumn(selection.from);
104105
const to = toLineAndColumn(selection.to);
105106

106-
const url = createPathWithQueryParams(`${window.location.origin}/browse/${repoName}@${revisionName}/-/blob/${path}`,
107+
// @note: we need to resolve the server path for /browse since
108+
// we aren't using <Link /> (which normally does this for us).
109+
const basePath = `${window.location.origin}${resolveServerPath('/browse')}`;
110+
const url = createPathWithQueryParams(`${basePath}/${repoName}@${revisionName}/-/blob/${path}`,
107111
['highlightRange', `${from?.line}:${from?.column},${to?.line}:${to?.column}`],
108112
);
109113

0 commit comments

Comments
 (0)