Repository navigation
fix: honor process.nextTick ordering before microtasks - #21
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10.
vite-node ran
process.nextTickcallbacks after Promise/queueMicrotaskcallbacks, violating Node's documented event-loop guarantee. Repro:nodeprintsS N P Q T I, vite-node printedS P Q N I T.Root cause:
ViteNodeRunner.runModuleexecutes the transformed module body inside an async IIFE that is awaited from within a deep promise chain, so the module's top-level synchronous code runs inside V8's microtask checkpoint — Promise/queueMicrotask callbacks it registers drain before itsnextTickcallbacks.Fix (in
src/client.tsonly): execute the module body on asetImmediatemacrotask instead of awaiting it synchronously, mirroring how native CommonJS entry modules run. The error path is safe: the module body is wrapped in an async IIFE, sofn()never throws synchronously andresolve()adopts rejections correctly; thefinallycleanup still runs.Tests: new
test/src/event-loop-order.tsfixture (the exact repro) andtest/test/event-loop.test.ts(1 regression test). The test asserts the deterministic part only — output starts withSNPQ, N before P and N before Q. It deliberately does not assert T-vs-I ordering (timer vs check phase is flaky under load; documented in the test comment). Full suite: 7 files / 35 tests passed, 0 failed. Build clean (tsc --noEmit, tsdown, eslint).Note: unrelated to #8 (which has its own repro-test PR #9) and to #18 (filed separately as #20).