Repository navigation
Conversation
A callback that threw inside the flush left the shared scheduler marked as flushing, so nothing was flushed again: every GraphProvider on the page stopped receiving graph changes. Each callback's error is now rethrown on a later task, and the rest of the pass still runs.
A callback that kept re-scheduling itself and throwing would otherwise hold the flush microtask forever.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the scheduler callback-error handling fix.
No open issues 🎉
What changed in this PR
Prevents a throwing callback from permanently blocking the shared @joint/react scheduler and freezing diagrams across the page.
Changes:
- Continues processing the current batch after a callback throws, while reporting the error asynchronously.
- Defers callbacks queued during a failing pass to a later task to prevent microtask starvation.
- Adds regression tests and a patch changeset.
| File | Description |
|---|---|
packages/joint-react/src/utils/scheduler.ts |
Isolates callback failures and defers queued work after a failing pass. |
packages/joint-react/src/utils/__tests__/scheduler.test.ts |
Tests continued scheduling, deferred errors, and yielding after self-rescheduling failures. |
.changeset/react-scheduler-throw.md |
Documents the scheduler fix for an @joint/react patch release. |
Review effort: Balanced
A recovery microtask queued before the callbacks run finishes the flush whether or not one of them throws.
This branch has not been deployed
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.
Summary
simpleScheduleris shared by every graph store on the page. If a queued callback threw, the error escapedflush()withflushingstilltrue. Every laterschedule()call then returned early, so all diagrams on the page stopped updating and the rest of that pass was lost.try/catchand no timer.flush()queues afinishFlushmicrotask before running any callback, so that microtask still runs if one of them throws. It flushes whatever is still queued, or marks the scheduler idle.Set, and each is deleted just before it runs. A thrown error leaves the rest queued, and because iterating aSetalso visits entries added while it runs, cascading callbacks stay in the same microtask, so they still land in one React batch.window.onerrorand the console).Behavior notes
devwithout a throw. This PR doesn't change that.Test plan
yarn jest --testPathPatterns="utils/__tests__/scheduler": 10/10. "reports the error and keeps flushing, without a timer" and "runs a callback queued by the failing callback" fail on thedevscheduler.yarn testinpackages/joint-react(typecheck, knip, jscpd, Jest on React 19 and React 18): passes, 1173 and 1132 tests.yarn linton the changed files: 0 errors.