Run React Refresh at vite:afterUpdate instead of after a fixed 16 ms
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript, vite
- Domain
- build-system, frontend
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 287
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Possibly taken @wozhenbang2004 claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
vitejs/vite-plugin-react#1570 ·
Maintainers usually reply within 1 day
-
pending triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vitejs/vite-plugin-react#1581 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildPossibly taken @NeilPant claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vitejs/vite-plugin-react#1578 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
vitejs/vite-plugin-react#1577 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorPossibly taken @draarivpatel-ui claimed this 2 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
vitejs/vite-plugin-react#1566 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vitejs/vite-plugin-react
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
earendil-works/pi#12615 ·
Maintainers usually reply within 1 day
-
My Caps shows "Shared" on private Caps that were never sharedPossibly taken @AksharP5 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CapSoftware/Cap#4569 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainers usually reply within 2 days