Skip to content

Commit 69b61e5

Browse files
committed
fix: ssr origin
1 parent 4b2dcf2 commit 69b61e5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

apps/web/app/export/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '~/components/u
1010
import { Progress } from '~/components/ui/progress'
1111
import { DbManager } from '~/lib/db'
1212
import { countFiles, listFiles } from '~/lib/files'
13+
import { useOrigin } from '~/lib/hooks'
1314
import {
1415
fileFromStream,
1516
fileToTarStreamFile,
@@ -22,6 +23,7 @@ import { downloadFile } from '~/lib/util'
2223
export default function Page() {
2324
const { dbManager } = useApp()
2425
const [progress, setProgress] = useState<number>()
26+
const origin = useOrigin()
2527

2628
return (
2729
<>
@@ -104,7 +106,7 @@ export default function Page() {
104106
along with any files that you imported or exported in your chats.
105107
</li>
106108
<li>
107-
Navigate to <Link href="/import">{window.location.origin}/import</Link> and click{' '}
109+
Navigate to <Link href="/import">{origin ?? ''}/import</Link> and click{' '}
108110
<strong>Import</strong>.
109111
</li>
110112
</ol>

apps/web/app/import/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useRouter } from 'next/navigation'
1414
import { getDatabasesQueryKey } from '~/data/databases/databases-query'
1515
import { DbManager } from '~/lib/db'
1616
import { hasFile, saveFile } from '~/lib/files'
17+
import { useOrigin } from '~/lib/hooks'
1718
import { tarStreamEntryToFile, waitForChunk } from '~/lib/streams'
1819
import { requestFileUpload, stripSuffix } from '~/lib/util'
1920

@@ -22,6 +23,7 @@ export default function Page() {
2223
const router = useRouter()
2324
const queryClient = useQueryClient()
2425
const [progress, setProgress] = useState<number>()
26+
const origin = useOrigin()
2527

2628
return (
2729
<>
@@ -45,7 +47,7 @@ export default function Page() {
4547
<h4 className="mb-4">How to export and import your databases</h4>
4648
<ol>
4749
<li>
48-
Navigate to <Link href={'/export'}>{window.location.origin}/export</Link> and click{' '}
50+
Navigate to <Link href="/export">{origin ?? ''}/export</Link> and click{' '}
4951
<strong>Export</strong> to download all of your databases into a single tarball.
5052
</li>
5153
<li>

apps/web/lib/hooks.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,17 @@ export function useQueryEvent(event: string, callback: (params: URLSearchParams)
611611
// eslint-disable-next-line react-hooks/exhaustive-deps
612612
}, [router, params])
613613
}
614+
615+
/**
616+
* Get the origin of the current window in a
617+
* SSR/hydration safe way.
618+
*/
619+
export function useOrigin() {
620+
const [origin, setOrigin] = useState<string>()
621+
622+
useEffect(() => {
623+
setOrigin(window.location.origin)
624+
}, [])
625+
626+
return origin
627+
}

0 commit comments

Comments
 (0)