-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Resets the Zoom on viewed/edited entity change #66232
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { useEffect, useMemo } from '@wordpress/element'; | |
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as coreDataStore } from '@wordpress/core-data'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -248,9 +249,14 @@ export default function useInitEditedEntityFromURL() { | |
useResolveEditedEntityAndContext( params ); | ||
|
||
const { setEditedEntity } = useDispatch( editSiteStore ); | ||
const { __unstableSetEditorMode, resetZoomLevel } = unlock( | ||
useDispatch( blockEditorStore ) | ||
); | ||
|
||
useEffect( () => { | ||
if ( isReady ) { | ||
__unstableSetEditorMode( 'edit' ); | ||
resetZoomLevel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed? It feels like a very weird place for this action to be called (sync hook) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the requirement to reset the zoom level when you move to a new entity has changed. I struggled to find a suitable location for this. I assume the concern is that we're calling a UI-specific hook (i.e. zoom level) in a hook which is primarily concerned with initialisation of editor state? Any more information on your concerns may help to refactor this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually removed this in a PR, so I could have introduced some regressions possibly. Based on your description, I would say we have two options:
|
||
setEditedEntity( postType, postId, context ); | ||
} | ||
}, [ isReady, postType, postId, context, setEditedEntity ] ); | ||
|
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.
Why can't we set an initial state instead? This is triggering a user preference to be set, which in turn triggers a REST API request to store this preference in the database, just by loading the site editor.
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.
Ok that's not good. Let's try and find a better fix.
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.
Ah...this doesn't affect WP 6.7 in the same way because it doesn't store the mode in a preference (only in state).
Nonetheless, this seems suboptimal.
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.
If I'm right we no longer want or need to set the editor mode here in
trunk
. If the mode is persisted as a preference then there's no need to reset it here. All we want to do is reset the zoom level.In WP 6.7 the editor mode is relevant (and is only stored in state) so we can leave "as is".
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.
Candidate fix in #66452.