Skip to content

Rest API/Gutenberg: Alert when an admin screen goes stale due to another user's save - #77

Merged
josephfusco merged 10 commits into
WordPress:mainfrom
Intenzi:feature/stale-screens-detection-api
Jul 24, 2026
Merged

josephfusco merged 10 commits into
WordPress:mainfrom
Intenzi:feature/stale-screens-detection-api

Conversation

@Intenzi

@Intenzi Intenzi commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #28
Follow-up to: #22

How?

This PR implements the stale-screen detection enhancements by introducing a new client-side API and a supporting REST route to handle non-redirecting, JS-driven saves:

Server-Side Changes

  • Refactored the screen access gating logic from wp_presence_screen_heartbeat_received() into a new shared helper function: wp_presence_current_user_can_access_screen().
  • Added a new POST endpoint /wp-presence/v1/presence/screen-revisions/stale to WP_REST_Presence_Controller.
    • It verifies permissions using the extracted helper and calls wp_presence_bump_screen_revision() to increment the revision.
  • Extended the script configuration in wp_presence_enqueue_stale_screen_banner() to pass down the restUrl and the nonce to the client.

Client-Side Changes

  • wp.presence.markScreenStale(): Added this new global method on the window.wp.presence namespace.
    • It performs a POST request to the new REST endpoint.

Additionally added unit tests for the bump wrapper methods success, failure and updated README with info on Stale Screen Detection.

Demo Video

8mb.video-Stale.Screen.Detection.API.mp4

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity IDE
Model(s): Gemini 3.1 Pro (Low)
Used for: Identifying relevant code files, deciding on implementation and architecture for enhancement. Unit tests were implemented via it. Final implementation and tests were reviewed and edited by me.

@Intenzi
Intenzi requested a review from josephfusco as a code owner July 17, 2026 14:11
@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 intenzi, 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 Jul 17, 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 e6481389b0832d58975571f761705d4bd0afcd81. Auto-updates when you push.

@josephfusco josephfusco added [Type] Feature A new feature within an existing module [Area] REST API Issues for the REST API subsystem [Area] Admin UI Issues for the admin UI integrations labels Jul 21, 2026

@josephfusco josephfusco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Intenzi thank you for your contributions, these are really solid changes!

The permission refactor into wp_presence_current_user_can_access_screen() is the right move and the demo video made it easy to understand the issue. Nice work!

Left a few inline suggestions, the main one is around actor_id as client input. Happy to clarify anything!

Comment thread includes/class-wp-rest-presence-controller.php
Comment thread includes/class-wp-rest-presence-controller.php Outdated
Comment thread assets/js/stale-screen.js
Comment thread tests/test-rest-controller.php Outdated
Comment thread tests/test-rest-controller.php Outdated
Comment thread tests/test-rest-controller.php Outdated

@josephfusco josephfusco left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thank you for your work on this @Intenzi

@josephfusco
josephfusco merged commit 6bc6971 into WordPress:main Jul 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Admin UI Issues for the admin UI integrations [Area] REST API Issues for the REST API subsystem [Type] Feature A new feature within an existing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale-screen detection for JS-driven save flows (REST/Gutenberg)

2 participants