Skip to content

Commit 26a8646

Browse files
fix: wrap useSearchParams in Suspense boundaries"
1 parent c0d1cb1 commit 26a8646

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

app/components/AuthWrapper.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect, useState } from "react";
3+
import { useEffect, useState, Suspense } from "react";
44
import { useSolidAuth } from "@ldo/solid-react";
55
import { useSearchParams, useRouter, usePathname } from "next/navigation";
66
import LoadingSpinner from "./shared/LoadingSpinner";
@@ -27,7 +27,7 @@ function hasSessionInStorage(): boolean {
2727
}
2828
}
2929

30-
export default function AuthWrapper({ children }: AuthWrapperProps) {
30+
function AuthWrapperContent({ children }: AuthWrapperProps) {
3131
const { session } = useSolidAuth();
3232
const searchParams = useSearchParams();
3333
const router = useRouter();
@@ -138,3 +138,18 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
138138
// User is authenticated and on correct page, show the app
139139
return <>{children}</>;
140140
}
141+
142+
143+
export default function AuthWrapper({ children }: AuthWrapperProps) {
144+
return (
145+
<Suspense
146+
fallback={
147+
<div className="flex min-h-screen items-center justify-center bg-white">
148+
<LoadingSpinner size="md" text="Loading..." />
149+
</div>
150+
}
151+
>
152+
<AuthWrapperContent>{children}</AuthWrapperContent>
153+
</Suspense>
154+
);
155+
}

app/page.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ import AuthWrapper from "./components/AuthWrapper";
55
import LoadingSpinner from "./components/shared/LoadingSpinner";
66
import FileManager from "./components/FileManager";
77

8+
// FileManagerContent uses useSearchParams, so it needs to be wrapped in Suspense
9+
function FileManagerContent() {
10+
return <FileManager />;
11+
}
12+
813
export default function Home() {
914
return (
10-
<Suspense
11-
fallback={
12-
<AuthWrapper>
15+
<AuthWrapper>
16+
<Suspense
17+
fallback={
1318
<div className="flex min-h-screen items-center justify-center bg-white">
1419
<LoadingSpinner size="md" text="Loading..." />
1520
</div>
16-
</AuthWrapper>
17-
}
18-
>
19-
<FileManager />
20-
</Suspense>
21+
}
22+
>
23+
<FileManagerContent />
24+
</Suspense>
25+
</AuthWrapper>
2126
);
2227
}

0 commit comments

Comments
 (0)