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

Template Part: 403 request error occurs in edit mode #68670

Closed
2 of 6 tasks
t-hamano opened this issue Jan 15, 2025 · 5 comments · Fixed by #68678
Closed
2 of 6 tasks

Template Part: 403 request error occurs in edit mode #68670

t-hamano opened this issue Jan 15, 2025 · 5 comments · Fixed by #68678
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@t-hamano
Copy link
Contributor

Description

When I open any template part in the site editor, a 403 error is recorded in the browser console:

{
    "code": "rest_cannot_read",
    "message": "Sorry, you are not allowed to view autosaves of this post.",
    "data": {
        "status": 403
    }
}

After investigating the problem, it appears that this issue occurred in #61273.

For example, if I temporarily comment out the Header component as shown below, the console error will disappear:

diff --git a/packages/editor/src/components/editor-interface/index.js b/packages/editor/src/components/editor-interface/index.js
index 6f6ffbec7b..c43dbe6383 100644
--- a/packages/editor/src/components/editor-interface/index.js
+++ b/packages/editor/src/components/editor-interface/index.js
@@ -112,19 +112,19 @@ export default function EditorInterface( {
                                ...interfaceLabels,
                                secondarySidebar: secondarySidebarLabel,
                        } }
-                       header={
-                               ! isPreviewMode && (
-                                       <Header
-                                               forceIsDirty={ forceIsDirty }
-                                               setEntitiesSavedStatesCallback={
-                                                       setEntitiesSavedStatesCallback
-                                               }
-                                               customSaveButton={ customSaveButton }
-                                               forceDisableBlockTools={ forceDisableBlockTools }
-                                               title={ title }
-                                       />
-                               )
-                       }
+                       // header={
+                       //      ! isPreviewMode && (
+                       //              <Header
+                       //                      forceIsDirty={ forceIsDirty }
+                       //                      setEntitiesSavedStatesCallback={
+                       //                              setEntitiesSavedStatesCallback
+                       //                      }
+                       //                      customSaveButton={ customSaveButton }
+                       //                      forceDisableBlockTools={ forceDisableBlockTools }
+                       //                      title={ title }
+                       //              />
+                       //      )
+                       // }
                        editorNotices={ <EditorNotices /> }
                        secondarySidebar={
                                ! isPreviewMode &&

It is likely that some request in the Header component is causing this error. I'm investigating the cause.

Step-by-step reproduction instructions

  • Open any template part in the site editor.
  • Check the browser console.

Screenshots, screen recording, code snippet

Image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@t-hamano t-hamano added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended REST API Interaction Related to REST API labels Jan 15, 2025
@Mamaduka
Copy link
Member

Mamaduka commented Jan 15, 2025

The error is a known issue and needs to be fixed in the core. See: WordPress/wordpress-develop#7272.

However, not sure why the code change from your example affects the behavior.

Also related: #64733.

@im3dabasia
Copy link
Contributor

Thank you @t-hamano for raising the issue.

I can confirm that a 403 error is recorded in the browser console.

Image

@t-hamano
Copy link
Contributor Author

@Mamaduka Thanks for letting me know!

From what I've researched, it seems like this error is happening with this request:

previewLink: editor.getEditedPostPreviewLink(),

I'm thinking that it might be a good idea to check isViewable beforehand as a condition for rendering the PostPreviewButton itself. If viewable is false, there's no need to get the preview link in the first place.

@t-hamano
Copy link
Contributor Author

I'm thinking that it might be a good idea to check isViewable beforehand as a condition for rendering the PostPreviewButton itself. If viewable is false, there's no need to get the preview link in the first place.

I'm starting to wonder if this approach is ideal.

Sure, it solves the problem with the PostPreviewButton component, but it doesn't solve the problem with the endpoint itself.

Maybe it's better to close this issue and move forward with WordPress/wordpress-develop#7272?

@Mamaduka
Copy link
Member

@t-hamano, yes, the core PR will resolve the root cause of the issue. However, this is also an opportunity for minor performance improvements for this component.

Here's my alternative PR #68678.

cc @dhananjaykuber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
3 participants