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.
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.
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.
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
|
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.
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.
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.
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.
I see, so we're trying to undo the effect of this code?
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/site-editor.php#L29-L35
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.
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.
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. |
| return ( | ||
| getQueryArg( window.location.href, 'wp_theme_preview' ) !== undefined | ||
| ); | ||
| return !! getQueryArg( window.location.href, 'wp_theme_preview' ); |
There was a problem hiding this comment.
@youknowriad Do you remember why you had to modify this? It looks like the wp_theme_preview query arg could be an empty string or some other falsy value, but the details are not clear. The old code, with its !== undefined check, returns true if the wp_theme_preview query arg is present, with any value.
There was a problem hiding this comment.
I remember it partially. I think it has to do with the "active theme" button. Basically when activating a theme, we actually set the wp_theme_preview to empty string (but keep in the url), for the site editor to adapt properly.
There's a reason it's kept in the url instead of undefined though but I don't remember the reason.
|
Hi All, |
|
Thanks for the report @JungleGenius! This was also reported in #68367 and I've got a fix coming up in #68388. |
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:
matchfunction in route definition with apathoption. I initially considered using pretty permalinks in the browser url (examplewp-admin/design/stylesto 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.pathin routes definitions means we have to change the urls of the site editor a little bit. I'm using a specialpargument for the path in the query string (because I can't use url rewrites). I've included redirects for backwards compatibility of old urls.areasandwidthconfigs 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