Repository navigation
Conversation
Signed-off-by: zjuncal <[email protected]>
🦋 Changeset detectedLatest commit: 135b0cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@zjuncal is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
Member
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.
What does this PR solve?
Fixes a bug in createBatchScheduler where a premature batch flush (triggered by shouldSplitBatch) does not cancel the pending setTimeout. The stale timer later fires and reads the global schedulerCache, which by then contains items from a new batch, causing that batch to be flushed prematurely — effectively bypassing the wait parameter.
Root cause
schedule() calls setTimeout(exec, wait) but does not store the timer handle. When shouldSplitBatch triggers exec() → flush(), the scheduler cache is cleared but the timer is not cancelled. The timer's callback (exec) re-reads the global scheduler at fire time, so it operates on whatever batch happens to be current.
Fix
Test
Added a regression test that creates a time gap between the stale timer (T1) and the new batch's timer (T2) by using wait=30 with an await wait(10) between the second and third schedule() calls. A fourth item is scheduled after T1's deadline but before T2's. Without the fix, item 3 is flushed alone by the stale T1; with the fix, items 3 and 4 are correctly batched together by T2.
Verified: test fails without the source fix (expected [3, [3]] to deeply equal [3, [3, 4]]), passes with it.
Alternatives considered
Considered moving the timer into the SchedulerItem array, but that would change the data structure shape and affect every read path. The timerCache Map mirrors the existing schedulerCache pattern and keeps the change minimal.