Skip to main content

Posts

Showing posts with the label TypeScript

How to Stream LangChain Responses in Next.js 15 (App Router Guide)

  You have set up your Next.js 15 application, configured your LangChain chains, and everything works perfectly in the console. But when you connect it to your React frontend, the application hangs. The user stares at a loading spinner for five seconds, and then the entire response snaps into existence at once. This destroys the User Experience. The "magic" of LLMs lies in the  token-by-token streaming effect —the typewriter illusion that makes the AI feel alive and responsive. Achieving this in the App Router is surprisingly difficult. You are battling three adversaries: the serialization boundary between React Server Components (RSC) and the client, the mismatch between LangChain’s async iterables and standard Web Streams, and the strict typing of TypeScript. This guide provides a production-grade, rigorous solution to implement real-time streaming using Next.js 15 Route Handlers and LangChain. The Root Cause: Why Streaming Breaks To fix the problem, we must understand the ...

Building Chrome Extensions with React & Vite: Fixing HMR and Content Script Reloading

  If you have attempted to bring the modern React developer experience (DX) to Chrome Extension development, you have likely hit a specific, workflow-killing wall. You set up Vite, get the popup rendering locally, but the moment you touch a Content Script, the abstraction leaks. HMR stops working. Styles don't update. You find yourself manually reloading the extension in  chrome://extensions  and refreshing the target web page just to see a one-line code change. This creates a feedback loop latency that makes modern UI development impossible. This guide details exactly why standard Vite configurations fail in the browser extension context and provides a rigorous, production-ready architecture using React, Vite, TypeScript, and CRXJS to solve it. The Root Cause: Why Standard HMR Fails in Extensions To fix the problem, we must understand the architecture of the browser runtime. Standard Vite HMR relies on a WebSocket connection between the browser client and the local devel...