-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Reset zoom level on component unmount #69087
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
Merged
t-hamano
merged 8 commits into
WordPress:trunk
from
Infinite-Null:fix/reset-zoom-unmount
May 23, 2026
+8
−2
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
73e9e6f
Reset zoom level on component unmount
Infinite-Null f3b5029
Reset zoom level when viewport changes to desktop
Infinite-Null e8ce907
Improve block editor store hooks organization
Infinite-Null d04935a
Merge branch 'trunk' into fix/reset-zoom-unmount
Infinite-Null 761ffb2
Fix: import comment
Infinite-Null 6fe5791
Merge branch 'trunk' into fix/reset-zoom-unmount
Infinite-Null 46b8777
Merge branch 'trunk' into fix/reset-zoom-unmount
Infinite-Null 0f05233
Fix zoom handling in useScaleCanvas and remove unused resetZoomLevel …
Infinite-Null File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,17 @@ | ||||||
| /** | ||||||
| * WordPress dependencies | ||||||
| */ | ||||||
| import { useDispatch, useSelect, useRegistry } from '@wordpress/data'; | ||||||
| import { useDispatch, useSelect, useRegistry, select } from '@wordpress/data'; | ||||||
| import { store as blockEditorStore } from '@wordpress/block-editor'; | ||||||
| import { store as editorStore } from '@wordpress/editor'; | ||||||
| import { useLayoutEffect } from '@wordpress/element'; | ||||||
| import { store as preferencesStore } from '@wordpress/preferences'; | ||||||
|
|
||||||
| /** | ||||||
| * Internal dependencies | ||||||
| */ | ||||||
| import { unlock } from '../../lock-unlock'; | ||||||
|
|
||||||
| export function useAdaptEditorToCanvas( canvas ) { | ||||||
| const { clearSelectedBlock } = useDispatch( blockEditorStore ); | ||||||
| const { | ||||||
|
|
@@ -17,6 +22,8 @@ export function useAdaptEditorToCanvas( canvas ) { | |||||
| } = useDispatch( editorStore ); | ||||||
| const { get: getPreference } = useSelect( preferencesStore ); | ||||||
| const registry = useRegistry(); | ||||||
| const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) ); | ||||||
| const { isZoomOut } = unlock( select( blockEditorStore ) ); | ||||||
|
Member
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. The components shouldn't use global
Suggested change
|
||||||
| useLayoutEffect( () => { | ||||||
| const isMediumOrBigger = | ||||||
| window.matchMedia( '(min-width: 782px)' ).matches; | ||||||
|
|
@@ -39,6 +46,10 @@ export function useAdaptEditorToCanvas( canvas ) { | |||||
| } else { | ||||||
| setIsListViewOpened( false ); | ||||||
| } | ||||||
|
|
||||||
| if ( isMediumOrBigger && isZoomOut() ) { | ||||||
| resetZoomLevel(); | ||||||
| } | ||||||
| } ); | ||||||
| }, [ | ||||||
| canvas, | ||||||
|
|
@@ -49,5 +60,7 @@ export function useAdaptEditorToCanvas( canvas ) { | |||||
| setIsInserterOpened, | ||||||
| setIsListViewOpened, | ||||||
| getPreference, | ||||||
| resetZoomLevel, | ||||||
| isZoomOut, | ||||||
| ] ); | ||||||
| } | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
useDispatch( blockEditorStore )is also defined above. Let's move and combine them in single call.