RTC: Disable custom autosave controller when RTC is disabled - #80769
RTC: Disable custom autosave controller when RTC is disabled#80769ingeniumed wants to merge 3 commits into
Conversation
|
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. |
|
Since RTC is not shipping in 7.1, and the existing changes in the controller were removed in core as part of the 7.0 release these changes do not need to be backported. These changes isolate the existing changes to only run when RTC is enabled, and those would be ported into core when RTC ships in core. |
|
Any reason we don't avoid whole class override if RTC isn't enabled in |
I had essentially the same question here. Linking for visibility. |
No reason for this to not be the case. My initial proposal limited the scope of changes to just the guard. This has now been changed in f538be1. I updated the autosaves controller registration so Gutenberg’s custom controller is selected only when RTC is enabled. When RTC is disabled, the post type keeps WordPress Core’s autosaves controller and follows Core’s existing autosave and preview behaviour. The guard in Gutenberg’s controller remains as a defensive fallback in case the class is instantiated directly or explicitly registered while RTC is disabled. In that situation, it delegates to Core’s create_item() implementation. Tests cover controller selection with RTC enabled and disabled, preservation of an explicitly configured controller, and the defensive fallback to Core behaviour. If adding the guard in is overtly defensive, happy to take it out but figured it couldn't hurt. |
| // We need to check post lock to ensure the original author didn't leave their browser tab open. | ||
| if ( ! function_exists( 'wp_check_post_lock' ) ) { | ||
| // create_post_autosave() may fire this callback for revisioned post meta. | ||
| if ( ! function_exists( 'wp_autosave_post_revisioned_meta_fields' ) ) { |
There was a problem hiding this comment.
@chriszarate / @alecgeatches - since RTC will be enabled for this section of the code, I simplified it down. In case I've missed some important logic, let me know.
| * implementation for the test state. Invoke the Gutenberg controller | ||
| * directly and normalize its response as the REST server would. | ||
| */ | ||
| $controller = new Gutenberg_REST_Autosaves_Controller( 'post' ); |
There was a problem hiding this comment.
This is necessary due to the change made to how the controller is registered based on if RTC is enabled or not
What?
Closes #80662
Makes
Gutenberg_REST_Autosaves_Controllerdelegate toWP_REST_Autosaves_Controller::create_item()when real-time collaboration is disabled.Adds regression coverage confirming that collaboration-disabled autosaves use Core’s behaviour.
Why?
Gutenberg registers its collaboration autosaves controller for normal post types regardless of whether collaboration is enabled.
Although the RTC-specific draft behaviour was disabled through conditional branches, the controller’s custom redundant-autosave comparison still ran. When an edited title was reverted to the published value, this comparison returned the parent post without updating or removing the previous autosave.
Core Data consequently retained the previous autosave and its preview link, causing Preview to display stale content.
The collaboration controller should only alter autosave behaviour when collaboration is enabled. When collaboration is disabled, WordPress Core should remain responsible for handling the request.
How?
Adds an early return to
Gutenberg_REST_Autosaves_Controller::create_item():The existing RTC implementation remains unchanged.
The PHP regression test creates an existing autosave, disables collaboration, submits content matching the parent, and verifies that the response follows Core’s autosave behaviour rather than Gutenberg’s RTC-specific no-op handling.
Testing Instructions
Sample Pageand publish it.Sample Page 2.Sample Page 2.Sample Page.Sample Page, rather than the staleSample Page 2autosave.Run the automated tests if you'd prefer that instead.
There are two specific tests:
Testing Instructions for Keyboard
Not applicable. This PR does not change the user interface.
Screenshots or screencast
Check out the issue for the bug video
Use of AI Tools
Codex was used for this PR.