@@ -12,7 +12,7 @@ import { has, set, uniqueId } from 'lodash';
12
12
* WordPress dependencies
13
13
*/
14
14
import { setLocaleData } from '@wordpress/i18n' ;
15
- import { dispatch } from '@wordpress/data' ;
15
+ import { dispatch , select } from '@wordpress/data' ;
16
16
17
17
/**
18
18
* Internal dependencies
@@ -110,6 +110,22 @@ export const loadGutenbergBlockAvailability = store => {
110
110
} ) ;
111
111
} ;
112
112
113
+ export const resetGutenbergState = ( registry , selectedSiteId ) => {
114
+ // Always reset core/editor, core/notices, and other UI parts
115
+ registry . reset ( 'core/editor' ) ;
116
+ registry . reset ( 'core/notices' ) ;
117
+ dispatch ( 'core/edit-post' ) . closePublishSidebar ( ) ;
118
+ dispatch ( 'core/edit-post' ) . closeModal ( ) ;
119
+
120
+ // Only reset core/data on site change
121
+ const previousGutenbergSiteId = select ( 'gutenberg/calypso' ) . getSelectedSiteId ( ) ;
122
+
123
+ if ( ! ! previousGutenbergSiteId && previousGutenbergSiteId !== selectedSiteId ) {
124
+ registry . reset ( 'core/data' ) ;
125
+ }
126
+ dispatch ( 'gutenberg/calypso' ) . setSelectedSiteId ( selectedSiteId ) ;
127
+ } ;
128
+
113
129
export const redirect = ( { store : { getState } } , next ) => {
114
130
const state = getState ( ) ;
115
131
const siteId = getSelectedSiteId ( state ) ;
@@ -140,11 +156,7 @@ export const post = async ( context, next ) => {
140
156
141
157
const { Editor, registry } = initGutenberg ( userId , context . store ) ;
142
158
143
- // Reset the Gutenberg state
144
- registry . reset ( 'core/editor' ) ;
145
- registry . reset ( 'core/notices' ) ;
146
- dispatch ( 'core/edit-post' ) . closePublishSidebar ( ) ;
147
- dispatch ( 'core/edit-post' ) . closeModal ( ) ;
159
+ resetGutenbergState ( registry , siteId ) ;
148
160
149
161
return props => (
150
162
< Editor { ...{ siteId, postId, postType, uniqueDraftKey, isDemoContent, ...props } } />
0 commit comments