`nuxt dev` reload never finishes when a Nuxt `close` hook doesn't settle

Đang mở
#1,659 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, nuxt, typescript
Lĩnh vực
backend, cli

Hướng nghiên cứu

Start in packages/nuxt-cli/src/dev/utils.ts at #load() and close(), then read the shutdown budget in packages/nuxt-cli/src/dev/pool.ts and its closeFork logic. Check existing dev reload tests and add coverage for a Nuxt close hook that never settles. Done means reload proceeds after the shutdown deadline, reports the unfinished hooks, and the test passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Environment
  • @nuxt/cli 4.0.3 (same code on main, 7d4dec6)
  • nuxt 4.6.4, nitropack 2.13.6, vite 8.3.6
  • Node 24.22.2, Linux x64
Reproduction

https://github.com/mttzzz/nuxt-reload-close-hook-hang

The app has one local module:

// modules/hang-on-close.ts
import { defineNuxtModule } from 'nuxt/kit'

export default defineNuxtModule({
  meta: { name: 'hang-on-close' },
  setup(_options, nuxt) {
    nuxt.hook('close', () => new Promise<void>(() => {}))
  },
})
  1. npm i && npx nuxt dev, the page shows marker: one
  2. change marker: 'one' to 'two' in nuxt.config.ts
Describe the bug

After step 2 the page switches to the loading screen (503) and stays there (I waited 80 s), the reload is never reported as done. Saving nuxt.config.ts again does nothing, since the config watcher is closed before the reload and only re-armed after it. Ctrl-C still exits right away, so restarting nuxt dev is the only way out.

Without the module the same edit reloads in about 1 s. The same kind of hook in a Nitro plugin (nitroApp.hooks.hook('close', () => new Promise(() => {}))) only delays the reload by about 5 s: nitropack terminates the dev worker after NITRO_SHUTDOWN_TIMEOUT, and the reload goes on.

This came up in #1328, where @danielroe asked for a separate issue.

Cause

An in-place reload (a nuxt.config change, removed build output, nuxt.callHook('restart') from a module) goes through #load(), which awaits close(), and close() awaits this.#currentNuxt.close() with no deadline:

https://github.com/nuxt/cli/blob/7d4dec65b188e549faad7c219d3766c988e5cdcb/packages/nuxt-cli/src/dev/utils.ts#L1277-L1282

nuxt.close() calls the close hooks one after another, so the hooks registered after the module (Nitro's, Vite's, the builder watchers) are never called either.

Shutting the fork down already has a budget: closeFork waits DEV_SHUTDOWN_TIMEOUT_MS (10 s), then sends SIGTERM and SIGKILL:

https://github.com/nuxt/cli/blob/7d4dec65b188e549faad7c219d3766c988e5cdcb/packages/nuxt-cli/src/dev/pool.ts#L194-L212

The reload could get the same budget: race currentNuxt.close() against DEV_SHUTDOWN_TIMEOUT_MS, warn that the close hooks didn't finish, and go on with the reload. I can send a PR for that.

Ngôn ngữ chính
TypeScript
Star
402
Fork
125
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
37

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nuxt/cli

Tất cả issue của nuxt/cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.