Skip to content

Commit

Permalink
Hack around flash of presence
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Aug 26, 2024
1 parent 6c4bc26 commit 6a2bb80
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/edit-site/src/components/welcome-guide/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { Guide } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as editorStore } from '@wordpress/editor';
import { useState } from '@wordpress/element';
import { useDebounce } from '@wordpress/compose';

export default function WelcomeGuideTemplate() {
const { toggle } = useDispatch( preferencesStore );

const isVisible = useSelect( ( select ) => {
const visibility = useSelect( ( select ) => {
const isTemplateActive = !! select( preferencesStore ).get(
'core/edit-site',
'welcomeGuideTemplate'
Expand All @@ -30,6 +32,13 @@ export default function WelcomeGuideTemplate() {
);
}, [] );

// The visibility conditions change in such a way that it’s tricky to avoid
// an unexpected flash of the component. Using state and debouncing writes
// to it works around the issue.
const [ isVisible, setIsVisible ] = useState();
const debouncedSetIsVisible = useDebounce( setIsVisible, 32 );
debouncedSetIsVisible( visibility );

if ( ! isVisible ) {
return null;
}
Expand Down

0 comments on commit 6a2bb80

Please sign in to comment.