Skip to content

fix(next): stop the image optimizer hanging after a cancelled request / 修复请求取消后图片优化器卡住的问题 - #1545

Merged
adibarra merged 1 commit into
masterfrom
fix/next-image-optimizer-hang
Oct 29, 2026
Merged

adibarra merged 1 commit into
masterfrom
fix/next-image-optimizer-hang

Conversation

@adibarra

@adibarra adibarra commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 1 of the stack split from #1530. Review and merge in order. CI only runs on PRs that target master, so each layer was verified locally; the combined change passed full CI on #1530.

Stack (merge in order):

  1. fix(next): stop the image optimizer hanging after a cancelled request / 修复请求取消后图片优化器卡住的问题 #1545 Next image optimizer patch ← this PR
  2. feat(api): negotiate compression, add ETag/304 and stale-while-revalidate purges / API 协商压缩,支持 ETag/304 与 stale-while-revalidate 失效 #1546 API response caching
  3. fix(dashboard): load benchmarks in parallel with availability / dashboard 的 benchmarks 与 availability 并行加载 #1547 Dashboard data waterfall
  4. fix(seo): social images, canonicals, titles, intros, structured data and sitemap / SEO:社交图片、canonical、标题、简介、结构化数据与 sitemap #1548 SEO metadata
  5. feat(seo): render compare, run, rankings, overview and blog index with ISR / compare、run、rankings、overview 与博客索引改用 ISR #1549 ISR for programmatic pages
  6. fix(perf): cut client bundle, image and prefetch weight / 减少客户端代码、图片与预取体积 #1550 Client bundle, image and prefetch weight
  7. fix(ux): remove layout shifts and explain blocked legend toggles / 消除布局偏移并说明被禁用的图例切换 #1551 Layout shift and UX
  8. fix(analytics): correct pageviews, proxy PostHog and stop sending search text / 统计:修正 pageview、代理 PostHog 并不再发送搜索文本 #1552 Analytics pageviews and privacy
  9. feat(analytics): cover untracked interactions, add event context and standardize keys / 统计:覆盖未追踪的交互,补充事件上下文并统一键名 #1555 Analytics coverage

Next 16.3.3's self-hosted image optimizer reads local source images through a mocked request that reuses the browser socket. If the browser cancels that request within a few milliseconds, the file read is dropped. The mock never finishes, and every later request for the same image variant waits on it until the server restarts.

This PR patches fetchInternalImage through root patchedDependencies (patches/[email protected]). next-image-optimizer-patch.test.ts fails if a Next upgrade drops the patch, and patches/** is added to the unit and E2E workflow path filters.

Later PRs in this stack route blog figures through next/image, which made Firefox E2E hit this bug. Production on Vercel uses Vercel's image service and should be unaffected, though that is not verified.

Validation details

Full CI runs on this PR (it targets master). Lint, format, typecheck and the full unit suite pass on this layer.

AI model disclosure
  • Model/version: anthropic/claude-opus-5-5 (runtime-exposed identifier for the coordinating agent).
  • Role: audited the site, planned and integrated the change set, split it into this stack, and wrote commit and PR text.
  • Delegated agents (scout, worker and critic subagents) implemented slices, built the stack and ran verification under the same harness. Their exact model identifier was not exposed to the coordinating agent, so it could not be verified.
PR checklist
  • I have completed the AI model disclosure and kept it current
  • Added, changed, or removed filters, views, or pages include the matching API and inferencex-skills changes (no filters or views change)
  • New or changed indexable pages ship their /zh sibling
  • Changed Chinese copy follows the PR review checklist in docs/chinese-copy.md (Chinese maintainer review pending)
中文

本 PR 为从 #1530 拆分的 stack 中的第 1 部分,请按顺序审核与合并。CI 只在以 master 为目标的 PR 上运行,因此每一层都在本地验证;整体改动已在 #1530 上通过完整 CI。

Next 16.3.3 的自托管图片优化器通过复用浏览器 socket 的模拟请求读取本地源图片。浏览器若在数毫秒内取消请求,文件读取会被丢弃,模拟请求永远不会完成,之后对同一图片变体的请求都会等待它,直到服务器重启。

本 PR 通过根目录 patchedDependencies(patches/[email protected])修补 fetchInternalImage。若 Next 升级后补丁丢失,next-image-optimizer-patch.test.ts 会失败;patches/** 已加入单元测试与 E2E workflow 的路径过滤。

本 stack 后续 PR 让博客配图经过 next/image,Firefox E2E 因此触发了该缺陷。Vercel 生产环境使用其自身的图片服务,预计不受影响(尚未验证)。

验证:本 PR 以 master 为目标,会运行完整 CI。本层的 lint、格式、类型检查与完整单元测试均通过。

AI 模型使用说明:协调 agent 使用 anthropic/claude-opus-5-5(运行环境提供的标识),负责审计、规划与整合改动、拆分 stack 以及撰写提交与 PR 文本;委派的子 agent 在同一环境中实现各部分、构建 stack 并运行验证,其确切模型标识无法获取,因此无法确认。


Note

Medium Risk
It changes Next’s server-side image optimization path used by self-hosted next start and CI; the regression test mitigates accidental patch loss on upgrades, but Vercel’s hosted optimizer is a separate code path.

Overview
Adds a Bun patchedDependencies patch for [email protected] so fetchInternalImage no longer passes the browser’s socket into the mocked internal read. When a client cancels early, the old behavior could abort the source stream, leave one optimization stuck in the shared cache, and block later requests for the same variant (including page load) until restart.

patches/[email protected] applies that change in Next’s compiled image-optimizer bundles; package.json / bun.lock wire it up. A new Vitest in next-image-optimizer-patch.test.ts simulates a destroyed socket and asserts the optimizer still returns the image, so a Next upgrade that drops the patch fails CI. Unit and E2E workflows now watch patches/**, and docs/deployment-configuration.md documents the self-hosted / next start rationale and how to refresh the patch after upgrades.

Reviewed by Cursor Bugbot for commit d78bbd5. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
inferencemax-app Ready Ready Preview Oct 29, 2026 2:08am UTC

Request Review

Patch [email protected] through root patchedDependencies. Unpatched, the
self-hosted optimizer reads a local source image through a mocked request
that reuses the browser socket. When the browser cancels the image, the
read is dropped and every later request for that variant hangs until the
server restarts. A unit test fails if a Next upgrade loses the patch, and
the unit and E2E workflows now run when patches/ changes.

中文:通过根目录 patchedDependencies 为 [email protected] 打补丁。未打补丁时,
自托管图片优化器复用浏览器 socket 读取本地源图,浏览器取消请求后读取被丢弃,
同一尺寸的后续请求会一直挂起,直到服务重启。新增单元测试在升级 Next 丢失补丁
时失败,patches/ 变更也会触发单元测试与 E2E 工作流。
@adibarra
adibarra force-pushed the fix/next-image-optimizer-hang branch from 153ffcf to d78bbd5 Compare October 29, 2026 02:06
@adibarra
adibarra merged commit 6fe3441 into master Oct 29, 2026
34 checks passed
@adibarra
adibarra deleted the fix/next-image-optimizer-hang branch October 29, 2026 02:11

This branch was successfully deployed

1 active deployment
Preview — d78bbd57 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant