-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Site Editor: Make current theme and editor settings available to route area resolvers #69299
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
Conversation
Size Change: +87 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
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 haven't tested this, but can we resolve the wrapper issue by returning I don't have a strong opinion on Router package changes, but I'll vote for the simplest solution for this particular case. |
I have tried the code below: function HomePreview() {
return undefined;
}
export const homeRoute = {
name: 'home',
path: '/',
areas: {
sidebar: <SidebarNavigationScreenMain />,
preview: <HomePreview />,
mobile: <SidebarNavigationScreenMain />,
},
}; I was hoping that the preview area wouldn't be rendered, but at this point |
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'm not 100% certain that this couldn’t some day be made unnecessary but it seems a sensible extensibility feature to add to the router and it’s a simple enough change. The router is also entirely private so I think we should go with it for now.
I have a few opinions on it though. I happened to explore this same concept recently when thinking about a solution for #69108.
Flaky tests detected in 9bcca28. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13544266093
|
Thanks for the feedback!
Although the route registration API is private and therefore they can remove this parameter in the future if they wish, I am also concerned about this. If we proceed more cautiously without making changes to the router package, I would like to suggest a consistent UI like the following:
I don't have a strong opinion on which approach to take, but I just want to avoid UI like this (e.g. unnatural resize handles) 😅 |
I am less concerned about empty screens or resize handles, than about the user accessing functionality that is broken for classic theme users. |
In time, isn't the plan that all of the Site Editor will work for all theme types? There will be only one theme type. So yes it should eventually be unnecessary, it will take time though. |
This is true, but the site editor will likely eventually be required to be made available to more than just administrators. In that case, we may want to control which screens are accessible based on user roles. This PR is also necessary to control access to stylebook based on theme support. Either way, I think a mechanism for controlling areas based on some conditions will be necessary in the future. |
If I remember correctly, the router is still private/internal API; if we find a better alternative to |
Yes.
|
Should we freeze this PR and try the alternative approach suggested in this comment? In other words, we try a similar approach to #69005:
If navigation within the site editor is properly controlled, users should never see this screen unless they access it directly via a URL. I think this approach can be worked on even after the beta release, because it's a "bug fix" that doesn't add any new APIs. What do you think? |
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.
LGTM. Maybe the title should be updated before merging. "Make current theme available to route area resolvers" would be my suggestion. Maybe prefixed by "Site Editor:"
080f230
to
6a1bfeb
Compare
6a1bfeb
to
00766d0
Compare
Or, you could let enable the theme support if theme.json exists, and still:
|
Ideally, we would add a new field to the REST API endpoint. This is about here. if ( rest_is_field_included( 'has_theme_json', $fields ) ) {
$data['has_theme_json'] = wp_theme_has_theme_json();
} However, I am hesitant to add such a new field just before the Beta release. |
@t-hamano, are there any blockers here? Can we merge this? Don't forget to add the "Backport to beta" label before merging. |
@Mamaduka After this PR was approved, I added one more selector by 00766d0. This selector is needed to determine if the theme has a theme.json file. See #68036 (comment) for details. |
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.
Thanks for the update, @t-hamano! I also left a comment on the issue: #68036 (comment).
I think this solution is okay for now.
…e area resolvers (#69299) * Router: Add context parameter to useMatch * Change `context` prop to `matchResolverArgs` * Remove `getThemeSupports` selector * Memorize matchResolverArgs value * Add editor settings to route area resolvers * Add comment for editorSettings Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org>
I just cherry-picked this PR to the wp/6.8 branch to get it included in the next release: 335079a |
…e area resolvers (WordPress#69299) * Router: Add context parameter to useMatch * Change `context` prop to `matchResolverArgs` * Remove `getThemeSupports` selector * Memorize matchResolverArgs value * Add editor settings to route area resolvers * Add comment for editorSettings Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org>
Preparation to move #69005 and #69043 forward
What?
This PR adds a new
context
matchResolverArgs
parameter to theuseMatch
hook.This will allow us to control whether or not to render a particular area based on the theme, for example.
Why?
Currently, the site editor determines what to render in which area based on the path, and if the area is not
undefined
, it renders the component in some wrapper element (example).As attempted in #69005 (review), there are cases where we don't want to render a specific area itself based on a condition. For example, whether it's a block theme.
However, even if a component returns null based on a certain condition, like this, the result is not equal to
undefined
, so the area wrapper itself will be rendered:How?
context
matchResolverArgs
parameter to theuseMatch
hook. This context can be used to pass any information through theRouterProvider
.Testing Instructions
For example, make the following changes: You should now have access to the information provided by your router provider:
In #69005, we are trying to control which screens are exposed to the classic theme. For example, to not expose the navigation screen to the classic theme, we should be able to disable the specific area itself as follows:
In #69043, we are trying to control access to the StyleBook based on theme support. For example, we should be able to disable the specific area itself as follows: