-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor: Persist user's 'Show Template' preference #69286
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Size Change: +243 B (+0.01%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
614e9d1
to
05813a9
Compare
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. |
I think this is ready for initial testing, but I'll need to follow up on CI failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works exactly as advertised and is the missing link that really ties this whole "Show Template" feature together.
I also tested for any regressions of unwanted flashes of incorrect rendering mode in the rendering of the editor and it looks exactly as expected :)
Really cool to see this come together in this way :) 🚀
// There are two separate settings OPTIONS requests. We should fix | ||
// so the one for canUser and getEntityRecord are reused. | ||
'/wp/v2/settings', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -38,7 +38,7 @@ export async function initializeEditor( props, { component } = {} ) { | |||
resolutionSpy.mockImplementation( ( selectorName, args ) => { | |||
// The mobile editor only supports the `post-only` rendering mode, so we | |||
// presume a resolved `getPostType` selector to unblock editor rendering. | |||
if ( 'getPostType' === selectorName ) { | |||
if ( [ 'getPostType', 'getCurrentTheme' ].includes( selectorName ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was annoying to track down 😄
// Wait for the post type and theme resolution. | ||
if ( | ||
! hasFinishedResolution( 'getPostType', [ postType ] ) || | ||
! hasFinishedResolution( 'getCurrentTheme' ) | ||
) { | ||
return undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for a resolution seems like a better approach. In rare cases when selectors resolve but return undefined, this allows using a post-only
fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand the need to store the preference as a theme specific setting, but I'm happy with how this is working currently. I can confirm that the editor seems to load much faster with this approach, which is terrific.
Thanks for the reminder. I'll expand on this. Update: @joemcgill, I expanded a little bit on this in the "How" section. |
@t-hamano and @stokesman, since you both recently worked to improve or fix the What I have for now
Screeenshot |
I haven't tested it thoroughly yet, but it might be because the metabox initialization relies solely on I've pushed 65714de. Locally, the metabox test passes. |
Thank you, @t-hamano! I think that was it. I totally forgot that the metaboxes are initialized outside the It got me thinking that maybe in the future, we should move it into a component that's called inside the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work fine to me.
I was concerned that the meta box would be reinitialized every time I toggled "Show template", but after __unstableIsEditorReady
changes to true once, the meta box initialization should not be executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave it another run through with the latest changes and it all still works as expected. The setting persists individually per post type and no unstyled flash of content is visibe :) 🚀
Thanks, everyone, for testing! |
What?
Closes #68250.
Alternative to #68257.
PR introduces user preference persistence for the new default rendering mode (Show Template), while keeping the editor's rendering mode state separate.
Why an alternative
I'm hesitant about handling user preferences logic inside the
getRenderingMode
andsetRenderingMode
. Why?useNavigateToEntityRecord
for example use cases.EditorProvider
makes it easier to control how fast the component can mark the editor as "ready". When user preference isn'ttemplate-locked
the component doesn't have to wait for the template to be resolved.setBockEditingMode
. While it's early to judge here, I can see some similarities. You can read more about the subject here - https://make.wordpress.org/core/2024/09/12/gutenberg-development-practices-and-common-pitfalls/#:~:text=Be%20declarative%20as%20much%20as%20possible.getDefaultRenderingMode
selector helps derive the state. It was getting too complex to keep inside themapSelect
callback.How?
getDefaultRenderingMode
selector andsetDefaultRenderingMode
action. They help keep logic simple inside the components.The user preferences are retained when switching themes. If the user selects
template-locked
mode for a post type in a block theme and switches to classic, the editor will try to render that post type withtemplate-locked
and fail. Block editor can only render block templates; it cannot render PHP.To prevent users from accidentally breaking editor rendering when switching between themes, rendering mode preferences are stored using the theme stylesheet as a top-level key.
Testing Instructions
template-locked
state.post-only
as the default rendering mode.post-only
.Testing Instructions for Keyboard
Same.