@@ -12,13 +12,8 @@ import { store as interfaceStore } from '@wordpress/interface';
12
12
import { store as editorStore } from '../../store' ;
13
13
14
14
export default function StartPageOptions ( ) {
15
- const { postId, shouldEnable } = useSelect ( ( select ) => {
16
- const {
17
- isEditedPostDirty,
18
- isEditedPostEmpty,
19
- getCurrentPostId,
20
- getCurrentPostType,
21
- } = select ( editorStore ) ;
15
+ const { postId, enabled } = useSelect ( ( select ) => {
16
+ const { getCurrentPostId, getCurrentPostType } = select ( editorStore ) ;
22
17
const preferencesModalActive =
23
18
select ( interfaceStore ) . isModalActive ( 'editor/preferences' ) ;
24
19
const choosePatternModalEnabled = select ( preferencesStore ) . get (
@@ -27,24 +22,37 @@ export default function StartPageOptions() {
27
22
) ;
28
23
return {
29
24
postId : getCurrentPostId ( ) ,
30
- shouldEnable :
25
+ enabled :
31
26
choosePatternModalEnabled &&
32
27
! preferencesModalActive &&
33
- ! isEditedPostDirty ( ) &&
34
- isEditedPostEmpty ( ) &&
35
28
'page' === getCurrentPostType ( ) ,
36
29
} ;
37
30
} , [ ] ) ;
31
+ const { isEditedPostDirty, isEditedPostEmpty } = useSelect ( editorStore ) ;
38
32
const { setIsInserterOpened } = useDispatch ( editorStore ) ;
39
33
40
34
useEffect ( ( ) => {
41
- if ( shouldEnable ) {
35
+ if ( ! enabled ) {
36
+ return ;
37
+ }
38
+
39
+ const isFreshPage = ! isEditedPostDirty ( ) && isEditedPostEmpty ( ) ;
40
+ if ( isFreshPage ) {
42
41
setIsInserterOpened ( {
43
42
tab : 'patterns' ,
44
43
category : 'core/starter-content' ,
45
44
} ) ;
46
45
}
47
- } , [ postId , shouldEnable , setIsInserterOpened ] ) ;
46
+
47
+ // Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
48
+ // Examples: changing pages in the List View, creating a new page via Command Palette.
49
+ } , [
50
+ postId ,
51
+ enabled ,
52
+ setIsInserterOpened ,
53
+ isEditedPostDirty ,
54
+ isEditedPostEmpty ,
55
+ ] ) ;
48
56
49
57
return null ;
50
58
}
0 commit comments