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

Global Styles: fix screens crashing on exit animation #65790

Closed
Closed
Show file tree
Hide file tree
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 @@ -14,6 +14,7 @@ import {
FlexItem,
ToggleControl,
} from '@wordpress/components';
import { usePrevious } from '@wordpress/compose';
import { moreVertical } from '@wordpress/icons';
import { useState } from '@wordpress/element';

Expand All @@ -35,11 +36,25 @@ function FontSize() {
const [ isRenameDialogOpen, setIsRenameDialogOpen ] = useState( false );

const {
params: { origin, slug },
params: { origin: originParam, slug: slugParam },
goBack,
goTo,
} = useNavigator();

// When the screen animates out, the params become undefined. The following
// code retains the previous value around, to avoid the screen from crashing
// or removing its contents during the animation.
const previousOrigin = usePrevious( originParam );
const previousSlug = usePrevious( slugParam );
const origin =
previousOrigin !== undefined && originParam === undefined
? previousOrigin
: originParam;
const slug =
previousSlug !== undefined && slugParam === undefined
? previousSlug
: slugParam;

const [ fontSizes, setFontSizes ] = useGlobalSetting(
'typography.fontSizes'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Modal,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { usePrevious } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import {
Expand Down Expand Up @@ -73,9 +74,24 @@ const presetShadowMenuItems = [

export default function ShadowsEditPanel() {
const {
params: { category, slug },
params: { category: categoryParam, slug: slugParam },
goTo,
} = useNavigator();

// When the screen animates out, the params become undefined. The following
// code retains the previous value around, to avoid the screen from crashing
// or removing its contents during the animation.
const previousCategory = usePrevious( categoryParam );
const previousSlug = usePrevious( slugParam );
const category =
previousCategory !== undefined && categoryParam === undefined
? previousCategory
: categoryParam;
const slug =
previousSlug !== undefined && slugParam === undefined
? previousSlug
: slugParam;

const [ shadows, setShadows ] = useGlobalSetting(
`shadow.presets.${ category }`
);
Expand Down
Loading