Skip to content

Commit 3e7bc4e

Browse files
committed
fix: resolve lint errors in QR pick flow
- Move ref updates into effects to satisfy react-hooks/refs rule - Remove synchronous setState in effects (set-state-in-effect rule) - Compute non-localhost URL eagerly in usePickUrl initializer
1 parent cf6780b commit 3e7bc4e

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

apps/app/src/app/page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export default function HomePage() {
2424
// Ref to always have the latest agent/copilotkit for async callbacks
2525
const agentRef = useRef(agent);
2626
const copilotkitRef = useRef(copilotkit);
27-
agentRef.current = agent;
28-
copilotkitRef.current = copilotkit;
27+
useEffect(() => { agentRef.current = agent; }, [agent]);
28+
useEffect(() => { copilotkitRef.current = copilotkit; }, [copilotkit]);
2929

3030
const sendPrompt = useCallback((prompt: string) => {
3131
const a = agentRef.current;
@@ -39,10 +39,10 @@ export default function HomePage() {
3939
sendPrompt(demo.prompt);
4040
};
4141

42-
// Reset scan status when QR modal opens
43-
useEffect(() => {
44-
if (qrOpen) setScanStatus("waiting");
45-
}, [qrOpen]);
42+
const openQrModal = () => {
43+
setScanStatus("waiting");
44+
setQrOpen(true);
45+
};
4646

4747
// Poll for QR pick status
4848
useEffect(() => {
@@ -116,7 +116,7 @@ export default function HomePage() {
116116
</p>
117117
</div>
118118
<div className="flex items-center gap-1.5 sm:gap-2">
119-
<QrButton onClick={() => setQrOpen(true)} />
119+
<QrButton onClick={openQrModal} />
120120
<button
121121
onClick={() => setDemoDrawerOpen(true)}
122122
className="inline-flex items-center gap-1.5 px-2.5 sm:px-3 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-medium no-underline whitespace-nowrap transition-all duration-150 hover:-translate-y-px cursor-pointer"

apps/app/src/components/qr-modal/index.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,30 @@ import { QRCodeSVG } from "qrcode.react";
77
/* Hook: resolves the pick URL (uses LAN IP on localhost for phones) */
88
/* ------------------------------------------------------------------ */
99
function usePickUrl(sessionId: string) {
10-
const [url, setUrl] = useState("");
10+
const isLocalhost =
11+
typeof window !== "undefined" &&
12+
(window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1");
13+
14+
const fallbackUrl =
15+
typeof window !== "undefined"
16+
? `${window.location.origin}/pick?session=${sessionId}`
17+
: "";
18+
19+
const [url, setUrl] = useState(() => (isLocalhost ? "" : fallbackUrl));
1120

1221
useEffect(() => {
13-
const origin = window.location.origin;
14-
if (
15-
window.location.hostname === "localhost" ||
16-
window.location.hostname === "127.0.0.1"
17-
) {
18-
fetch("/api/pick/ip")
19-
.then((r) => r.json())
20-
.then((data) => {
21-
if (data.ip) {
22-
setUrl(`http://${data.ip}:${window.location.port}/pick?session=${sessionId}`);
23-
} else {
24-
setUrl(`${origin}/pick?session=${sessionId}`);
25-
}
26-
})
27-
.catch(() => setUrl(`${origin}/pick?session=${sessionId}`));
28-
} else {
29-
setUrl(`${origin}/pick?session=${sessionId}`);
30-
}
31-
}, [sessionId]);
22+
if (!isLocalhost) return;
23+
fetch("/api/pick/ip")
24+
.then((r) => r.json())
25+
.then((data) => {
26+
if (data.ip) {
27+
setUrl(`http://${data.ip}:${window.location.port}/pick?session=${sessionId}`);
28+
} else {
29+
setUrl(fallbackUrl);
30+
}
31+
})
32+
.catch(() => setUrl(fallbackUrl));
33+
}, [sessionId, isLocalhost, fallbackUrl]);
3234

3335
return url;
3436
}

0 commit comments

Comments
 (0)