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

Abierto
#1,565 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
react, typescript, vite

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
TypeScript
Estrellas
1.2k
Forks
287
Merge medio
1 d 17 h
PR fusionados (30 d)
19

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de vitejs/vite-plugin-react

Todos los issues de vitejs/vite-plugin-react

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.