Sync: Defer poll scheduling to requestIdleCallback#78515
Conversation
`pollingManager`'s first poll on `registerRoom` fired synchronously, putting the initial `POST /wp-sync/v1/updates` on the editor boot path. Subsequent polls used `setTimeout(poll, pollInterval)`, ignoring browser idle state and competing with active typing frames. Route both schedule points through a `schedulePoll` helper that prefers `requestIdleCallback`: - `initial: true` (first poll) has no deadline — yields to whatever boot work is in progress so wp-sync doesn't compete with editor mount. - default (subsequent polls) caps the wait at `pollInterval`, matching the cadence consumers expect today. Falls back to `setTimeout` when `requestIdleCallback` isn't available. The jest-preset-default `requestIdleCallback` polyfill now honors `options.timeout` so sync's poll-loop tests run the right scheduler behaviour under fake timers. Side-effect of deferring the first poll: when several rooms register synchronously at boot (post + collection rooms), they all land in the first poll instead of the first room flying solo. Two overflow-rotation tests were updated to reflect the new (and more bandwidth-efficient) batching. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +86 B (0%) Total Size: 7.98 MB 📦 View Changed
ℹ️ View Unchanged
|
What?
Route the HTTP-polling sync manager's poll scheduler through
requestIdleCallbackso the wp-syncPOST /wp-sync/v1/updatesround trip no longer sits on the editor boot critical path, and so subsequent polls cooperate with active typing/scrolling frames.Why?
registerRoompreviously calledpoll()synchronously, so the initial wp-sync POST raced with the rest of editor mount — adding RTTs to the perceived load time even though the response usually carries nothing actionable for a solo session.setTimeout(poll, pollInterval)fires on a fixed cadence regardless of whether the browser is busy with React commits, scroll handling, or typing. WithrequestIdleCallbackplus apollIntervaltimeout cap, polls move to idle windows when available and never wait longer than they would have under the old timer.How?
schedulePoll({ initial })helper picks the scheduler —requestIdleCallback(withcancelIdleCallbackfor cleanup) when available, elsesetTimeout— and tracks a singlecancelPendingPollcallable that the visibility/retry paths use to cancel.initial: true(only used for the first poll after a room registers) has no fixed delay; it just yields.initial: false(default) caps the idle wait atpollInterval.jest-preset-defaultrequestIdleCallbackpolyfill now honorsoptions.timeoutso the sync poll-loop tests exercise the right behaviour under fake timers.Testing Instructions
POST /wp-sync/v1/updatesin DevTools network panel — it should fire after editor mount completes rather than during.npm run test:unit -- packages/sync— 210 tests pass.npm run test:e2e -- test/e2e/specs/editor/collaboration/— collaboration flows unaffected.History:
🤖 Generated with Claude Code