-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Site Editor: Use path based routing instead of query args and site-editor.php routes #67199
Conversation
Size Change: +3.2 kB (+0.18%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
d1052a3
to
b0c11e8
Compare
bc7da78
to
eca0126
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. |
eca0126
to
f84d4ac
Compare
addQueryArgs( path, { | ||
layout: newView.type, | ||
} ) | ||
); |
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 would be nice to keep the getLocationWithParams
pattern. The idea is that the click handler can read the current path
at the time when it's called, non-reactively. The component doesn't need to be rerendered on every path
change and the callback doesn't need to be recomputed.
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.
The problem is that we need to know the registered routes, it's not just about reading the arguments from the url, so IMO, it's better to remove it entirely.
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.
Then we can expose a method on the history = useHistory()
object that does the job of useMatch
. You can call it imperatively/synchronously at any time, and subscribe to updates. Then the actual useLocation
will merely a React binding (with useSyncExternalStore
) for this.
3754c93
to
d03a835
Compare
packages/edit-site/src/components/block-editor/use-navigate-to-entity-record.js
Show resolved
Hide resolved
So now that most of the code details are addressed and the PR is ready. I would like to ask your global opinion on this PR. Is it going in the right direction? Are we ok we these small urls changes for the moment?... |
p: `/${ postType }/${ record.id }`, | ||
canvas: 'edit', | ||
} | ||
); |
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.
One of the follow-up steps will be to somehow abstract away and remove this conditional navigation. When the rewrite rules are enabled, the target URL should be
document.location = `/wp-admin/design/${ postType }/${ record.id }?canvas=edit`;
The history.navigate
call
history.navigate( `/${ postType }/${ record.id }?canvas-edit` );
is almost identical except the /wp-admin/design
base path. If the "base paths" match, it's an SPA navigation, and a full navigation otherwise.
} | ||
return $default_handler; | ||
} | ||
add_filter( 'wp_die_handler', 'gutenberg_styles_wp_die_handler' ); |
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 think this fix deserves some detailed explanation in a comment. It looks completely magical to me, I don't know what it does, I don't even know what a "hybrid theme" is.
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.
haha, you're right. Basically, site-editor.php's access is forbidden for hybrid/classic themes and only allowed with some very special query args (some very special pages like template parts...). This is done in Core and the only way to disable it if we change urls in Gutenberg is to override the wp_die_handler
. (We did this in the past when we introduced the patterns page in classic themes too).
I think in the backport PR of this PR, I'm going to try to remove that blocking condition entirely from Core cause I believe it doesn't really make much sense anymore.
But I'll add a comment.
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 see, so we're trying to undo the effect of this code?
What would explain it to me would be:
- mentioning/linking this code explicitly in a comment
- saying how exactly are we going to modify/delete this code when backporting this compat patch to Core
Such information will be also super useful for the person who will actually do the 6.8 backporting.
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.
Is the last comment good enough or you think I should modify it? I'm doing the backporting btw since now it's mandatory to open a PR before being able to merge this PR into Gutenberg :)
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.
Now when I know what's going on I'm personally satisfied 🙂 And it's written down in GitHub comments, a motivated researcher can track it down.
I love this PR 🙂 It's in principle very simple, and yet it brings us only one |
Thanks for the great work on this one, @youknowriad. It's exciting to see! I'd like to take a broader look, but I may be unable to take another look before tomorrow. Anyway, don't feel blocked by my review. |
Why can't it all be top-level? The REST API also has them top-level, so it seems fine? It would be cool to mirror the paths from that |
Yes, REST API is the first thing that comes to my mind, too. It has all the custom post type paths already solved. Every CPT has a
The UI frontend router should exactly mirror these paths. |
I don't think the frontend should mirror the REST API at all. The client's API rely on "postType" slug and not RestPath as an identifier. In the REST API, the REST path is unique across all entities but the "postType" might be shared with taxonomy slug for instance. You can have a post type with name "x" and a taxonomy with name "x" and there's no way to disambiguate between both. We can only do it if we use the REST path in the router and have an endpoint to fetch the actual post type or the actual entity based on the REST path. This is really not worth the complexity. I think we should have the following routes instead:
|
Spending some time testing this, and filing some PRs where I found something: |
Yes, you convinced me this makes sense 🙂
|
Another follow-up fix for template author filter nav here: #67382 |
I ran into some issues in |
Please let's call it something other than |
* @return callable The default handler or a custom handler. | ||
*/ | ||
function gutenberg_styles_wp_die_handler( $default_handler ) { | ||
if ( ! wp_is_block_theme() && str_contains( $_SERVER['REQUEST_URI'], 'site-editor.php' ) && isset( $_GET['p'] ) ) { |
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.
Why do we need && isset( $_GET['p'] )
? This means it's not possible to access the site editor root, which I need for #66851
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 entirely sure that it's necessary tbh, it was just defensive coding because p
is almost always defined now due to the redirects in place.
…itor.php routes (#67199) Co-authored-by: youknowriad <[email protected]> Co-authored-by: jsnajdr <[email protected]> Co-authored-by: tyxla <[email protected]>
Related #60584
This PR makes our routing framework a bit more solid and getting us closer to opening the registration API publicly.
The main changes in the PR include:
match
function in route definition with apath
option. I initially considered using pretty permalinks in the browser url (examplewp-admin/design/styles
to access the styles page in the site editor) but because URL rewrites might not be supported in all WP instances, I left this part out of the PR.path
in routes definitions means we have to change the urls of the site editor a little bit. I'm using a specialp
argument for the path in the query string (because I can't use url rewrites). I've included redirects for backwards compatibility of old urls.areas
andwidth
configs of the routes can now be functions that receive the current location (query and params) as arguments. This was done to avoid separating the routes for quick edit, list view... I think this makes our routes way more clear and prevents us from having "convenient" routes, instead we can think about "1 Path" = "1 route"Todo