Skip to content
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

Site Editor: Avoid previous content flash when a new template is created #40841

Merged
merged 2 commits into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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