You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Site editor: missing "Back" button in Document bar in focused editor coming from page #69016
When editing a page in the Site editor and entering focused mode to edit a template or template part there is supposed to be a "Back" button in the Document bar.
Step-by-step reproduction instructions
Edit a page in the Site editor
Either:
Select a template part and click "Edit" in its toolbar
Click "Edit template" from the "Template options" menu in the Document summary panel
Note that there is no "Back" button in the Document bar
Screenshots, screen recording, code snippet
The following demonstrates the issue for both templates and template parts and at the 19 second mark also demonstrates how the "Back" button does appear if you edit a template part when already editing the template.
missing-back-button-doc-bar.mp4
Environment info
WP 6.7.1 with Gutenberg plugin at trunk
Chrome
macOS
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.
I tried reproducing the issue using WP 6.7.1 and the Gutenberg plugin, as well as the Gutenberg trunk. However, I wasn’t able to reproduce the bug. Is there a step I might have missed?
changed the title [-]Missing "Back" button in Document bar in focused editor coming from page[/-][+]Site editor: missing "Back" button in Document bar in focused editor coming from page[/+]on Feb 4, 2025
Hi @SainathPoojary, thank you for testing. It looks like you tested the Post editor and not the Site editor. I had that in the instructions but now I’ve updated the issue title as well in hopes no one else misses that detail.
Thank you for the clarification @stokesman . You’re right I initially tested in the Post editor. After switching to the Site editor, I was able to reproduce the issue as described.
Hi @Mayank-Tripathi32@SainathPoojary, I tried to debug the issue and found this issue which is related to this - #67199, but not sure if this had cause the regression to be happened and to be more specific - c9a5cab, this commit may have cause this issue.
I've worked it out. In order to decide whether to show the back button, we rely on usePrevious, which stores a ref. Because the areas.preview component changes between the home route and the template-part-item route, the ref gets reset, so there's no previous and the back button doesn't get shown.
Thanks Aki, that comment is helpful. It’s interesting that it was in reply to your finding on how an e2e test failure was due to a missing back button #66851 (comment). It seems like there’s a lack of coverage for a similar scenario with pages and this could have been caught.
More from that same comment:
We could potentially use HomeViewPreview on every route that uses the editor and can be accessed from the canvas, so the component doesn't change, and call it something generic like MaybeEditor. I'm not sure if there's a better solution, open to ideas!
It looks like that idea was used for the solution and I found that applying the same idea for the page item route fixed this in my testing.
Thanks for your detailed investigation, I think I'm starting to understand what's causing this.
It looks like the best approach would probably be to centralize all the logic into the base editor (EditSiteEditor) to avoid rendering different components depending on the route.
That makes sense. I came up with another approach that I think might be favorable #69103. It makes the code concerned with the back button more robust (remounts won’t affect it). So the branching for the classic theme preview can be kept to just the home route.
Activity
SainathPoojary commentedon Feb 4, 2025
Hey @stokesman,
I tried reproducing the issue using WP 6.7.1 and the Gutenberg plugin, as well as the Gutenberg trunk. However, I wasn’t able to reproduce the bug. Is there a step I might have missed?
2025-02-04.08-07-59.mp4
[-]Missing "Back" button in Document bar in focused editor coming from page[/-][+]Site editor: missing "Back" button in Document bar in focused editor coming from page[/+]stokesman commentedon Feb 4, 2025
Hi @SainathPoojary, thank you for testing. It looks like you tested the Post editor and not the Site editor. I had that in the instructions but now I’ve updated the issue title as well in hopes no one else misses that detail.
SainathPoojary commentedon Feb 4, 2025
Thank you for the clarification @stokesman . You’re right I initially tested in the Post editor. After switching to the Site editor, I was able to reproduce the issue as described.
Mayank-Tripathi32 commentedon Feb 4, 2025
This looks like a possible regression from recent PR, I will investigate it to find the bad commit.
Update: this issue is regression, I was able to locate some good commits:
9da58a749e2958f65c51352afd2f469379057fc4But taking a bit of time to locate the exact commit that introduced this bug.
I will keep working on this.
hbhalodia commentedon Feb 5, 2025
Hi @Mayank-Tripathi32 @SainathPoojary, I tried to debug the issue and found this issue which is related to this - #67199, but not sure if this had cause the regression to be happened and to be more specific - c9a5cab, this commit may have cause this issue.
Thank You,
Mayank-Tripathi32 commentedon Feb 5, 2025
@hbhalodia Thank you for identifying the faulty commit. I'll investigate further to determine the root cause of the bug and create a PR with a fix.
t-hamano commentedon Feb 5, 2025
From my research, this issue was caused by #66851. It's strange because it seems like an unrelated PR at first glance.
The console error when you click the "Go back" link in the snack bar should be a clue:
By the way, I noticed that the following console error also occurs in WP 6.7. It would be good if we could fix this too.
3f05d1753661ab6b4f28d6527c4c6cf2.mp4
t-hamano commentedon Feb 6, 2025
I haven't been able to solve the problem yet, but I have found that making the following changes temporarily fixes the problem:
Diff
Perhaps this comment might give us a clue:
stokesman commentedon Feb 6, 2025
Thanks Aki, that comment is helpful. It’s interesting that it was in reply to your finding on how an e2e test failure was due to a missing back button #66851 (comment). It seems like there’s a lack of coverage for a similar scenario with pages and this could have been caught.
More from that same comment:
It looks like that idea was used for the solution and I found that applying the same idea for the page item route fixed this in my testing.
Diff
I'm not sure this is the ideal solution or if there are potentially some other routes where it ought to be applied.
t-hamano commentedon Feb 7, 2025
Thanks for your detailed investigation, I think I'm starting to understand what's causing this.
It looks like the best approach would probably be to centralize all the logic into the base editor (EditSiteEditor) to avoid rendering different components depending on the route.
I've started trying this approach in #69093.
stokesman commentedon Feb 8, 2025
That makes sense. I came up with another approach that I think might be favorable #69103. It makes the code concerned with the back button more robust (remounts won’t affect it). So the branching for the classic theme preview can be kept to just the home route.