Run React Refresh at vite:afterUpdate instead of after a fixed 16 ms

Đang mở
#1,565 2 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
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript, vite
Lĩnh vực
build-system, frontend

Hướng nghiên cứu

Start in packages/common/refresh-runtime.js, where enqueueUpdate is a debounce with a 16 ms delay that runs the hooks and then performReactRefresh. Look at how the client emits vite:afterUpdate and where validateRefreshBoundaryAndEnqueueUpdate is called. Done means flushing the pending refresh on vite:afterUpdate while the timer still covers enqueues outside an update. Check the timing in the existing refresh tests.

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

Mô tả

Drafted with an AI assistant (Claude), reviewed by me.

Related plugins
  • plugin-react
Description

React Refresh runs 16 ms after the last accepted module (packages/common/refresh-runtime.js, 6.3.0):

const enqueueUpdate = debounce(async () => {
  if (hooks.length) await Promise.all(hooks.map((cb) => cb()))
  performReactRefresh()
}, 16)

So every Fast Refresh edit waits at least 16 ms after its modules have run.

We see it in TanStack Router, which waits for the pass through __registerBeforePerformReactRefresh before applying a route edit: an edit of only a route's loader went from 16.9 to 36.8 ms save-to-DOM when we started waiting (1,485-route app).

Suggested solution

By the time the client emits vite:afterUpdate, every module of the payload has run its accept callback, so every validateRefreshBoundaryAndEnqueueUpdate call of that update has been made. Flush there, and keep the timer for enqueues outside an update:

import.meta.hot.on('vite:afterUpdate', () => flushPendingRefresh())
Alternative

Keep the debounce but expose a way to flush it.

Validations
  • Follow our Code of Conduct
  • Read the Contributing Guidelines
  • Read the docs
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate
Ngôn ngữ chính
TypeScript
Star
1.2k
Fork
287
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
19

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

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 vitejs/vite-plugin-react

Tất cả issue của vitejs/vite-plugin-react

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.