Skip to content
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

Fixed non-existing path issue #67773

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

rinkalpagdar
Copy link
Contributor

Part of #67445

What?

Site Editor should display a 404 message when you navigate to a non-existing path

Why?

Currently, the Site Editor is showing a black page with no message or content when the user miss-type the link

How?

It will show a 404 message with a button to get back to the site editor.

Testing Instructions

Try navigating to wp-admin/site-editor.php?p=%2Ftemplate-fdgfdgdfg

Screenshots or screencast

fix-non-existing-path.mp4

Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: rinkalpagdar <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +36 to +39
async function checkPathExists(path) {
const response = await fetch(`/wp-json/wp/v2/templates${path}`);
return response.ok;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea, though I this can be implemented as part of the routing code to avoid the need to fetch asynchronously. In the site editor the routing is implemented here:

return (
<RouterProvider
routes={ routes }
pathArg="p"
beforeNavigate={ beforeNavigate }
>
<AppLayout />
</RouterProvider>

The routes come from this file:
https://github.com/WordPress/gutenberg/blob/trunk/packages/edit-site/src/components/site-editor-routes/index.js

The implementation is using the router package as a library. I can see that there's some handling for 404 here:

if ( ! result ) {
return {
name: '404',
path: addQueryArgs( path, query ),
areas: {},
widths: {},
query,
params: {},
};
}

I'm not familiar with the code though, so I don't know how to make this display something. Perhaps it should be possible to define a 404 route in the site editor package

@talldan talldan requested a review from jsnajdr December 10, 2024 07:13
@talldan talldan added [Type] Enhancement A suggestion for improvement. [Package] Edit Site /packages/edit-site labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Edit Site /packages/edit-site [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants