Skip to content

feat: add RTC collaboration hooks and server authority - #290

Merged
josephfusco merged 6 commits into
mainfrom
feat/rtc-collaboration-hooks
Aug 16, 2026
Merged

josephfusco merged 6 commits into
mainfrom
feat/rtc-collaboration-hooks

Conversation

@josephfusco

@josephfusco josephfusco commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds collaboration lifecycle hooks for RTC server authority.

Changes

  • wp_presence_editor_state filter - Allows plugins to enrich editor state before saving (e.g., cursor position, selected blocks)
  • wp_presence_check_collaboration_threshold() - Detects when editor count crosses collaboration threshold (1→2+ or 2+→1)
  • wp_presence_collaboration_started action - Fires when collaboration begins (1→2+ editors)
  • wp_presence_collaboration_ended action - Fires when collaboration ends (2+→1 editor)

Use Case

These hooks enable the realtime-collaboration plugin to implement server authority for Gutenberg RTC. The server determines when collaboration should activate based on active editor count.

What Was Removed

Earlier commits included:

  • wp_presence_editor_active action - Removed (unused, high frequency)
  • X-WP-Collaboration-Active header - Removed (unused)
  • X-WP-Editor-Count header - Removed (unused)

These were dropped to keep the surface area minimal and avoid overhead.

Related

Assisting with: Implementation and testing.

- Add wp_presence_editor_state filter for state enrichment
- Add wp_presence_editor_active action on heartbeat ticks
- Add wp_presence_check_collaboration_threshold() function
- Fire wp_presence_collaboration_started when 1→2+ editors
- Fire wp_presence_collaboration_ended when 2+→1 editor
- Add X-WP-Collaboration-Active header to REST responses
- Add X-WP-Editor-Count header to REST responses
@github-actions

Copy link
Copy Markdown
Contributor

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props joefusco.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

▶ Preview in WordPress Playground

Open in WordPress Playground

Boots a fresh WordPress with this PR's presence-api build, seeds 5 demo users, and drops you on the dashboard.

Stress-test variant: 40 demo users · Built from 9bcf82caece5fdabc3326ce2843fa5c81465dd50. Auto-updates when you push.

@codecov

codecov Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.01%. Comparing base (555a383) to head (9bcf82c).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #290      +/-   ##
============================================
+ Coverage     77.82%   78.01%   +0.18%     
  Complexity      190      190              
============================================
  Files            14       14              
  Lines          1998     2015      +17     
============================================
+ Hits           1555     1572      +17     
  Misses          443      443              
Flag Coverage Δ
multisite 78.01% <100.00%> (+0.18%) ⬆️
phpunit 76.82% <100.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Test wp_presence_editor_state filter
- Test wp_presence_editor_active action
- Test wp_presence_collaboration_started action (1→2+ editors)
- Test wp_presence_collaboration_ended action (2+→1 editor)
- Test X-WP-Collaboration-Active header in REST responses
- Test X-WP-Editor-Count header in REST responses
- Test headers only present for postType/ rooms
Fixes division by zero error when per_page defaults to 0 in direct controller calls.
Fixes negative OFFSET in SQL queries when calling controller directly without the page parameter set.
Removed:
- wp_presence_editor_active action (unused by realtime-collaboration)
- X-WP-Collaboration-Active and X-WP-Editor-Count headers (unused)
- Tests for removed functionality

Kept:
- wp_presence_editor_state filter (extensibility for cursor positions)
- wp_presence_check_collaboration_threshold() function
- wp_presence_collaboration_started/ended actions (used by realtime-collaboration)
The test was comparing the response timestamp against gmdate() called
after tick(), which could cross a second boundary and fail. Now captures
before/after timestamps around tick() and verifies the response falls
within that window.
@josephfusco
josephfusco merged commit 97ff370 into main Aug 16, 2026
17 checks passed
@josephfusco
josephfusco deleted the feat/rtc-collaboration-hooks branch August 16, 2026 16:54
@josephfusco josephfusco added the [Area] Heartbeat 💓 Issues for the heartbeat subsystem label Sep 4, 2026
@josephfusco josephfusco mentioned this pull request Sep 24, 2026
24 of 36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Heartbeat 💓 Issues for the heartbeat subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant