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

PreviewOptions: critical error when children not passed #54283

Closed
t-hamano opened this issue Sep 8, 2023 · 0 comments · Fixed by #54284
Closed

PreviewOptions: critical error when children not passed #54283

t-hamano opened this issue Sep 8, 2023 · 0 comments · Fixed by #54284
Assignees
Labels
[Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Comments

@t-hamano
Copy link
Contributor

t-hamano commented Sep 8, 2023

Description

It was also reported in:

The PreviewOptions component renders child components. However, because it assumes that the child is a function, a critical error will occur if the child is not passed in the proper form.

In the pattern directory, no children are passed, as only a device preview is sufficient.

Step-by-step reproduction instructions

To reproduce this issue, rewrite the Edit component of the code block as follows:

/**
 * WordPress dependencies
 */
import {
	useBlockProps,
	__experimentalPreviewOptions as PreviewOptions,
} from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';

export default function CodeEdit() {
	const deviceType = useSelect( ( select ) => {
			return select( 'core/edit-post' ).__experimentalGetPreviewDeviceType();
	}, [] );
	const { __experimentalSetPreviewDeviceType: setPreviewDeviceType } =
		useDispatch( 'core/edit-post' );
	const blockProps = useBlockProps();
	return (
		<div { ...blockProps }>
			<PreviewOptions deviceType={ deviceType } setDeviceType={ setPreviewDeviceType } />
		</div>
	);
}
  • Insert a code block.
  • The block should break.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant