Skip to content

[WIP] RTC: Disconnect providers for single editor#76960

Draft
shekharnwagh wants to merge 7 commits intoWordPress:trunkfrom
shekharnwagh:rtc/lazy-sync-connection
Draft

[WIP] RTC: Disconnect providers for single editor#76960
shekharnwagh wants to merge 7 commits intoWordPress:trunkfrom
shekharnwagh:rtc/lazy-sync-connection

Conversation

@shekharnwagh
Copy link
Copy Markdown
Contributor

What?

Closes

Why?

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

Use of AI Tools

@shekharnwagh shekharnwagh self-assigned this Apr 1, 2026
@github-actions github-actions Bot added [Package] Core data /packages/core-data [Package] Editor /packages/editor [Package] Sync labels Apr 1, 2026
@shekharnwagh shekharnwagh force-pushed the rtc/lazy-sync-connection branch from 8c9eff8 to 7a7ff78 Compare April 2, 2026 05:57
shekharnwagh and others added 7 commits April 6, 2026 18:21
Optimize resource usage for the common single-user editing case by
deferring full sync provider connections until another editor is
detected. This avoids unnecessary HTTP polling (or WebSocket connections
for third-party providers) when only one user is editing.
The server-side Heartbeat handler (gutenberg_sync_heartbeat_presence)
was added as scaffolding for provider-independent presence detection,
but the client-side consumer (heartbeat-presence.ts) was removed during
cleanup. The actual presence detection uses the sync endpoint with
presence_only flag instead. Remove the dead code.
The awareness change handler fires on every awareness update including
frequent cursor movements during active editing. Filter to only
re-evaluate the downgrade timer when clients are actually added or
removed, not on state updates. This avoids unnecessary iteration of
all awareness states on every cursor move.
Fix a race condition where a collaborator leaving during async provider
creation would never trigger a downgrade. startAwarenessMonitor now
evaluates awareness.getStates() immediately after subscribing, catching
collaborators that departed before the handler was registered.
Presence detection was coupled to the HTTP polling sync endpoint
(/wp-sync/v1/updates), creating stale awareness entries that caused
false collaborator detection after page refresh. This triggered
unnecessary provider connections and the sync error modal for solo
users.
Replace scattered cleanup logic with explicit state transition
functions (enterStandby, enterConnected) and shared helpers
(createProviders, clearEntityRuntime, destroyEntityProviders,
destroyCollectionProviders). This makes it harder to miss cleanup
steps when transitioning between standby and connected modes.

Also fix the presence endpoint permission check — the old inline
check only handled post types. Extract gutenberg_can_user_access_sync_room()
to cover taxonomies, comments, and collections, matching the full
sync endpoint's permission model.
@shekharnwagh shekharnwagh force-pushed the rtc/lazy-sync-connection branch from 7a7ff78 to 3cf5b99 Compare April 6, 2026 12:51
@ingeniumed
Copy link
Copy Markdown
Contributor

My worry about using a rest endpoint for this kind of presence detection is that it'll run into the same issues as the polling provider. I don't think it should be introduced for something like the websocket provider that can already scale pretty well using websockets, for instance.

What do you think about making the checkPresence provider specific? I'm envisioning that each provider will have their own server and client implementations just like we do for the http provider and the websocket provider. So they would implement their own way of doing this. We can offer an example within the two providers to show the best practice of doing this, and take advantage of the underlying transport mechanism of each provider. This feels similar to the collaborator limits in that it can be all client side and provider specific imo.

This would mean that the code would reside within the websocket provider in VIP RTC plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants