skater235
skater235
TTCTheo's Typesafe Cult
Created by skater235 on 2/1/2025 in #questions
In nextj15, router.refresh after router.back doesnt update the server component data
Server Component -> '/projects' Child Client Component -> '/projects/edit' '/projects' route should ideally be updated with latest data after succesful edit api request and closing of modal - if router.back (closing edit modal) and router.refresh are called one after the other, the server component doesnt update. using router.refresh after a setTimeout works - is there a better way to go about it this without setTimeout?? and without modifying history with push or replace? '/projects' route -> Server Component - fetches projects and lists them as cards 'projects/edit' Edit Modal (Client Component) - renders a modal to edit the project details const onSubmit = async (data: { name: string; description: string }) => { try { if (type === 'add') { await handleCreate(data); } else if (type === 'edit' && projectId) { await handleUpdate({ projectId, ...data }); } // router.refresh without setTimeout doesnt work setTimeout(() => { router.refresh(); }, 100); } catch (error) { console.log(error); } }; Hook export function useUpdateProject() { const { setLoading } = useLoading(); const router = useRouter(); const handleUpdate = async ({ projectId, name, description }: { projectId: string; name: string; description: string }) => { setLoading(true); try { await updateProject({ projectId, name, description }); // closes modal router.back(); } catch (err: any) { console.log(err) } finally { setLoading(false); } }; return { handleUpdate }; } Service fetchProjects -> cache:no-store is passed as header updateProject -> cache:no-store is passed as header
5 replies
TTCTheo's Typesafe Cult
Created by skater235 on 1/28/2025 in #questions
T3.chat why is the chat api POST response after a prompt not in JSON?
Hi, I have been using t3.chat frequently - theo and his team's wonderful AI chat interface after seeing the video on it. I spend some time dissecting it and while looking over the network requests, I realized that the response from this endpoint https://t3.chat/api/chat is not in JSON. What it looks like
0:"Hello"
0:"!"
0:" I'm"
0:" doing"
0:" well"
0:","
0:" thank"
0:" you"
0:" for"
0:" asking"
0:"."
0:" How"
0:" about"
0:" you"
0:"?"
0:" How"
0:" can"
0:" I"
0:" assist"
0:" you"
0:" today"
0:"?"
0:"Hello"
0:"!"
0:" I'm"
0:" doing"
0:" well"
0:","
0:" thank"
0:" you"
0:" for"
0:" asking"
0:"."
0:" How"
0:" about"
0:" you"
0:"?"
0:" How"
0:" can"
0:" I"
0:" assist"
0:" you"
0:" today"
0:"?"
What are the pros of doing it in this format over typical JSON ? Is it for assistance in parsing?
2 replies