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

TypeError: Cannot read property 'prefix' of null #12482

Closed
petenelson opened this issue Nov 30, 2018 · 5 comments · Fixed by #12884
Closed

TypeError: Cannot read property 'prefix' of null #12482

petenelson opened this issue Nov 30, 2018 · 5 comments · Fixed by #12884
Assignees
Labels
[Feature] Saving Related to saving functionality [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Comments

@petenelson
Copy link

petenelson commented Nov 30, 2018

When adding a new custom post type, upon hitting "Save Draft", the "The editor has encountered an unexpected error." message appears, and this is the error message. This had been working in 4.5

Editing an existing custom post type shows the error immediately.

TypeError: Cannot read property 'prefix' of null
    at http://devsite.local/wp-content/plugins/gutenberg/build/edit-post/index.js?ver=1543608571:12:54832
    at mountIndeterminateComponent (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:14687:13)
    at beginWork (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:15187:16)
    at performUnitOfWork (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:17944:12)
    at workLoop (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:17984:24)
    at renderRoot (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:18070:7)
    at performWorkOnRoot (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:18961:7)
    at performWork (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:18873:7)
    at performSyncWork (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:18847:3)
    at requestWork (http://devsite.local/wp-content/plugins/gutenberg/vendor/react-dom.60482cc7.js:18716:5)

Additional context

  • Gutenberg 4.6.0
@swissspidy
Copy link
Member

How did you register the custom post type? Could you perhaps share that code here?

The only place where I see prefix in the edit-post package is related to permalinks.

@swissspidy swissspidy added the [Status] Needs More Info Follow-up required in order to be actionable. label Dec 1, 2018
@petenelson
Copy link
Author

Here's the args for the post type.

$args = [
	'labels'              => $labels,
	'exclude_from_search' => true,
	'publicly_queryable'  => true,
	'show_in_nav_menus'   => false,
	'show_ui'             => true,
	'show_in_menu'        => true,
	'menu_position'       => 2,
	'menu_icon'           => 'dashicons-admin-home',
	'has_archive'         => false,
	'supports'            => [
		'title',
		'editor',
		'revisions',
	],
	'rewrite'             => false,
	'capability_type'     => get_post_type_name(),
	'map_meta_cap'        => true,

	// Needs to be true for Gutenberg.
	'show_in_rest'        => true,
];

$args = apply_filters( get_post_type_name() . '_args', $args );

\register_post_type( get_post_type_name(), $args );

@swissspidy swissspidy added Needs Testing Needs further testing to be confirmed. [Package] Editor /packages/editor and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Dec 3, 2018
@joshuafredrickson
Copy link
Contributor

This occurred for me in 4.6.1 with custom post types with 'public' => false. When I change it to true, the error goes away.

When set to false:

screen shot 2018-12-06 at 2 39 03 pm

And in the console:

TypeError: Cannot read property 'prefix' of null
    at index.js?ver=1544119766:12
    at ph (react-dom.min.713f0afa.js:97)
    at eg (react-dom.min.713f0afa.js:125)
    at fg (react-dom.min.713f0afa.js:126)
    at wc (react-dom.min.713f0afa.js:138)
    at fa (react-dom.min.713f0afa.js:137)
    at gg (react-dom.min.713f0afa.js:135)
    at Ca (react-dom.min.713f0afa.js:133)
    at Object.enqueueSetState (react-dom.min.713f0afa.js:191)
    at r.q.setState (react.min.1b974caa.js:20)

@jorgefilipecosta
Copy link
Member

Maybe related: #12677

@danielbachhuber danielbachhuber added the [Feature] Saving Related to saving functionality label Dec 10, 2018
@apermo
Copy link

apermo commented Dec 11, 2018

I have the same issue.

With Gutenberg 4.5.1 it works fine. Updating to GB 4.6.x breaks the code, disabled nearly all plugins besides Gutenberg and the one registering my posttype.

$args = array(
			'label'               => __( 'Portal Page', 'r24-portal-pages' ),
			'description'         => __( 'Portal Page', 'r24-portal-pages' ),
			'labels'              => $labels,
			'supports'            => array( 'title', 'editor', 'custom-fields' ),
			'taxonomies'          => array( 'node_tax' ),
			'hierarchical'        => false,
			'public'              => false,
			'show_ui'             => true,
			'show_in_menu'        => true,
			'menu_position'       => 15,
			'menu_icon'           => 'dashicons-schedule',
			'show_in_admin_bar'   => false,
			'show_in_nav_menus'   => false,
			'can_export'          => true,
			'has_archive'         => false,
			'exclude_from_search' => true,
			'publicly_queryable'  => current_user_can( 'edit_posts' ),
			'rewrite'             => false,
			'capability_type'     => 'page',
			'show_in_rest'        => true,
		);
register_post_type( 'portal_page', $args );

This is my code for the CPT

Edit:
Changing publicly_queryableto hardcoded true does not fix this problem.

Changing publicfrom false to true will restore the editor and fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Saving Related to saving functionality [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended
Projects
None yet
6 participants