SShortSingh.
Back to feed

Aborting Mid-Token Streams: Handling Chat Disconnects with Vercel AI SDK and React 19

0
·3 views

A developer describes a failure where a dropped SSE connection left a browser tab stuck and a half-rendered assistant message frozen in a React chat thread. The problem arises because a stream's underlying fetch keeps draining into state updates unless an AbortSignal is passed to stop it on disconnect or a user Stop action. The author's approach keeps React 19 UI code separate from transport, using a thin fetch wrapper and an unbuffered SSE proxy so timeouts fail fast and aborts reach the browser. The sample hook adds optimistic message inserts to avoid a blank transcript, wires an AbortController to a Stop action, and shows a connection-error message when a stream fails. The article argues that generic streaming snippets often omit these abort and error-handling boundaries.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Tencent LoopForge 0.4.0 installation guide for Linux with agent workflows

A guide explains how to install Tencent's open-source LoopForge 0.4.0 on Ubuntu 26.04, a tool that organizes coding-agent workflows into script, agent and human-approval steps. The setup uses a script that deploys the platform and MySQL in Docker containers, requiring a 64-bit Linux server with Git, sudo and at least 15 GB of free disk space. HTTPS configuration needs a domain pointed at the server and ports 80 and 443 open, while port 8090 should stay closed to the internet. The guide also recommends verifying the downloaded image's digest against the release page before granting access to repositories. Initially the service accepts open sign-ups, so the guide advises accessing it through an SSH tunnel first, creating a strong admin account, then disabling registration and restricting access.

0
ProgrammingDEV Community ·

Node's vm module and Python's exec are not sandboxes, and in-process isolation fails

A DEV Community post argues that common agent-tool approaches to running model-written code, Node's vm module, vm2, and Python's exec with stripped builtins, do not provide real isolation. Both the Node.js and Python documentation explicitly warn against using these mechanisms for untrusted code. The author demonstrates a Node escape in which code inside a vm context reaches the host's process object through constructor chains, reproduced on Node 24. The post also cites CVE-2023-37466, a vm2 sandbox escape, after which vm2 was discontinued in favor of isolated-vm. It further notes that Python's exec sandboxing can be bypassed by walking object subclasses to recover dangerous functionality.

0
ProgrammingDEV Community ·

Free Browser-Based Tool Suite Handles Image and PDF Tasks Without File Uploads

A developer has released UmarFilekit, a free set of nine web utilities for converting, compressing, and merging images and PDFs, plus generating QR codes. All processing runs locally in the user's browser, so files are never sent to a server. The tools require no sign-up, impose no daily limits, and add no watermarks. The developer argues that local processing protects privacy and removes upload and download delays, and the site is designed mobile-first for common tasks like converting iPhone HEIC photos.

0
ProgrammingDEV Community ·

Researchers Say AI Works Best as a Lab Assistant, Not a Replacement for Judgment

A PhD student's Reddit post about worrying that AI is doing her learning for her drew many similar responses from researchers. Across discussions they describe using AI tools for plotting, coding, and reviewing literature, while generally keeping the scientific conclusions in human hands. Commentators compare the tools to talented but inexperienced students whose work must be checked. Concerns also extend to trust in AI-written papers and to pressures in peer review. The article presents four practical guidelines for using AI in research while still building genuine understanding.