Skip to content

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

Open

Description

@Sheraff

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

Activity

  1. ArnaudBarre commented on Nov 15, 2026

    @ArnaudBarre
    Member

    So I looked into this, and we could do something about this like this.

    But the issue is that it as been so stable that some of it's code is actually hardcoded into rolldown. We are trying to remove React specific things from rolldown/oxc (with oxc-transform-react) but that's an ongoing process and could lead to perf regression for dev startup time for big apps.

    cc @sapphi-red FYI

  2. sapphi-red commented on Nov 16, 2026

    @sapphi-red
    Member

    I think we can add a flag to the plugin in rolldown to generate the new code. Then, plugin-react can enable that option while making the refresh-runtime expose both validateRefreshBoundaryAndEnqueueUpdate and validateRefreshBoundary+flushPendingRefresh. That should work with old Vite/Rolldown versions and new versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions