-
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: Remove synchronization of canvas mode into store #66213
Conversation
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. |
import { useLayoutEffect } from '@wordpress/element'; | ||
import { store as preferencesStore } from '@wordpress/preferences'; | ||
|
||
export function useAdaptEditorToCanvas( canvasMode ) { |
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.
This was previously in the setCanvasMode action. But these are all "editor specific" changes, they should happen when the editor is rendered.
function push( | ||
params: Record< string, any >, | ||
state: Record< string, any >, | ||
options: PushOptions = {} |
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.
This change basically adds support for view transitions to our "private" router.
Size Change: -6 B (0%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
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 like the idea of this PR 👍🏻
I'm just not sure how the interaction between canvas
and canvasMode
is supposed to work. I based my testing on how trunk is working.
All the canvas modes are making me sleepy 😄
...params, | ||
canvasMode: | ||
undefined, | ||
}, |
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.
history.push( | ||
{ | ||
...params, | ||
canvasMode: '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.
Do the links for patterns and templates also need canvasMode: 'edit',
?
E.g.,
const { onClick } = useLink( {
postType: item.type,
postId: isUserPattern || isTemplatePart ? item.id : item.name,
canvas: 'edit',
canvasMode: 'edit',
} );
Otherwise, clicking on individual patterns and templates lead to the list + preview mix, similar to the screenshot above.
@@ -55,11 +55,15 @@ export default function useEditorIframeProps() { | |||
! currentPostIsTrashed | |||
) { | |||
event.preventDefault(); | |||
setCanvasMode( 'edit' ); | |||
history.push( { ...params, canvasMode: 'edit' }, undefined, { |
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.
Are we missing canvas: 'edit'
?
There is functionality that requires it.
For example, the param is checked to allow navigation between editing a page's template to work, useNavigateToPreviousEntityRecord.
Speaking of which, when editing a page's template I think we also need to add canvasMode: 'edit'
to the route now:
diff --git a/packages/edit-site/src/components/block-editor/use-navigate-to-entity-record.js b/packages/edit-site/src/components/block-editor/use-navigate-to-entity-record.js
index 120b15b8551..cf44b2ae0cd 100644
--- a/packages/edit-site/src/components/block-editor/use-navigate-to-entity-record.js
+++ b/packages/edit-site/src/components/block-editor/use-navigate-to-entity-record.js
@@ -16,7 +16,9 @@ export default function useNavigateToEntityRecord() {
const onNavigateToEntityRecord = useCallback(
( params ) => {
- history.push( { ...params, focusMode: true, canvas: 'edit' } );
+ history.push( { ...params, focusMode: true, canvas: 'edit', canvasMode: 'edit' }, undefined, {
+ transition: 'canvas-mode-edit-transition',
+ } );
},
[ history ]
);
} | ||
}, | ||
onClick: () => { | ||
setCanvasMode( 'edit' ); | ||
history.push( { ...params, canvasMode: 'edit' }, undefined, { |
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.
Also here... canvas: 'edit'
?
Actually this is a mistake that I made in this PR, all these links should be "canvas" :) |
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.
Thanks for the update.
Navigation between edit and view modes works as expected for me.
✅ Checked navigation between view and edit modes for all sidebar entities
✅ Page template editing from the block settings panel
✅ Edit template from command centre
Great to see this and have a single source of truth. Thanks! |
b40d4b3
to
2766d7f
Compare
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.
Nice 👍 We are lucky that that getCanvasMode
/setCanvasMode
was a private API and can be removed from the store without replacement.
Flaky tests detected in 2766d7f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11456342079
|
Looks like we forgot to rename a var, fixing in #66316. |
Interesting that tests didn't pick it up 🤔 |
Yeah, same thought. This is what I see:
My understanding is that GitHub 1) doesn't retrigger CI builds for PRs every time the base branch ( |
…ess#66213) Co-authored-by: youknowriad <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: ntsekouras <[email protected]>
Follow-up to #66030
What?
The canvasMode in edit-site is duplicated between edit site store and url which creates some very small and unfortunate side effects:
This PR removes the canvasMode state and always relies on the location from the url to solve that.
Testing Instructions
1- notice that when you go to "pages", the canvas animates to the right
2- notice that entering and exiting the canvas animates properly.