Skip to content

An AI-powered search engine with a generative UI

Fix search path condition

Yoshiki Miura4f1dfd299986
diff --git a/components/chat.tsx b/components/chat.tsx
index 64c28567..54a07512 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -1,7 +1,7 @@
'use client'
import { useEffect } from 'react'
-import { usePathname, useSearchParams } from 'next/navigation'
+import { usePathname } from 'next/navigation'
import { ChatPanel } from './chat-panel'
import { ChatMessages } from './chat-messages'
import { useUIState } from 'ai/rsc'
@@ -13,17 +13,13 @@ type ChatProps = {
export function Chat({ id, query }: ChatProps) {
const path = usePathname()
- const searchParams = useSearchParams()
const [messages] = useUIState()
useEffect(() => {
- if (
- (!path.includes('search') && messages.length === 1) ||
- (searchParams.get('q') && messages.length === 1)
- ) {
+ if (!path.includes('search') && messages.length === 1) {
window.history.replaceState({}, '', `/search/${id}`)
}
- }, [id, path, messages, query, searchParams])
+ }, [id, path, messages, query])
return (
<div className="px-8 sm:px-12 pt-12 md:pt-14 pb-14 md:pb-24 max-w-3xl mx-auto flex flex-col space-y-3 md:space-y-4">