Skip to content

Commit

Permalink
Site Editor: Avoid previous content flash when a new template is crea…
Browse files Browse the repository at this point in the history
…ted (#40841)

* Site Editor: Avoid previous content flash when a new template is created
* Pass slug
  • Loading branch information
Mamaduka committed May 6, 2022
1 parent bcc497b commit 6f11e0b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { store as noticesStore } from '@wordpress/notices';
* Internal dependencies
*/
import { useHistory } from '../routes';
import { store as editSiteStore } from '../../store';

const DEFAULT_TEMPLATE_SLUGS = [
'front-page',
Expand Down Expand Up @@ -86,6 +87,7 @@ export default function NewTemplate( { postType } ) {
);
const { saveEntityRecord } = useDispatch( coreStore );
const { createErrorNotice } = useDispatch( noticesStore );
const { setTemplate } = useDispatch( editSiteStore );

async function createTemplate( { slug } ) {
try {
Expand All @@ -106,6 +108,9 @@ export default function NewTemplate( { postType } ) {
{ throwOnError: true }
);

// Set template before navigating away to avoid initial stale value.
setTemplate( template.id, template.slug );

// Navigate to the created template editor.
history.push( {
postId: template.id,
Expand Down

0 comments on commit 6f11e0b

Please sign in to comment.