If the custom post type is 'publicly_queryable' => false the editor show the notice "Updating failed" when it tries to save the draft.

Because of this error:

Let me know if more info is needed.
Additional context
Thanks for the report, @heldervilela.
In your Developer Tools, can you take a screenshot of and share the API request / response itself? I'm curious whether the JSON is properly formed, and what sort of HTTP response you're getting from WordPress.
@danielbachhuber I'm glad to help
From what I saw when comparing with another CPT the answer is the same.
Request:

Response:

Oh, interesting. And there's no preview_link value because the post isn't publicly_queryable.
I think the Gutenberg JavaScript shouldn't be trying to access the preview_link in this case. I've flagged this as a bug for WordPress 5.0.1.
Would you be able to share the full code of your custom post type registration?
I've been unable to reproduce the save failure / error notice using the following code:
<?php
/**
* Plugin Name: Demo CPT
*/
add_action( 'init', function() {
register_post_type( 'book', [
'label' => 'Book',
'show_in_rest' => true,
'public' => true,
'publicly_queryable' => false,
'supports' => [ 'title', 'editor' ],
] );
} );
You have to add revisions to supports.
I can reproduce the issue with WordPress 5.0 and Gutenberg the plugin at b7e343d
add_action( 'init', function() {
register_post_type( 'book', [
'label' => 'Book',
'show_in_rest' => true,
'public' => true,
'publicly_queryable' => false,
'supports' => [ 'title', 'editor', 'revisions' ],
] );
} );
Here's a GIF of my experience:

And here's the final state:

Ah, here's the earlier report of this too: https://core.trac.wordpress.org/ticket/45404
The error happens here, where the passed url is undefined, thus indexOf will throw:
This happens with the fallback case of the editor's handling of save completion, where it attempts to set a query parameter to the post url:
The problems are:
post is a revision, so it doesn't include linkpreview_link is _set_ on post, but it is an empty string (the || triggers the RHS logic because the falsiness of empty string)The reason it is assigned as an empty string can be tracked to the preview_link assignment in the autosaves controller:
The value is null because when a post type is publicly_queryable => false, it is not "viewable":
https://github.com/WordPress/wordpress-develop/blob/5.0/src/wp-includes/link-template.php#L1235-L1243
https://github.com/WordPress/wordpress-develop/blob/5.0/src/wp-includes/post.php#L1781
There's a few action items here:
addQueryArgs should never throw. Based on the equivalent behavior from add_query_arg, I suspect it should return the string with only query arguments.previewLink reducer should not return a new value if neither preview_link nor link are usablepreview_link be assigned even if 'publicly_queryable' => false ? I'm unsure of the repercussions of changing get_preview_post_linkVerify no regressions in preview behavior if the preview link can't be assigned
We already handle this: The preview button will not be shown if the post type is not viewable, following the same logic noted previously considering publicly_queryable.
addQueryArgsshould never throw. Based on the equivalent behavior fromadd_query_arg, I suspect it should return the string with only query arguments.
See: #12803
- The
previewLinkreducer should not return a new value if neitherpreview_linknorlinkare usable
See: #12800
Most helpful comment
Oh, interesting. And there's no
preview_linkvalue because the post isn'tpublicly_queryable.I think the Gutenberg JavaScript shouldn't be trying to access the
preview_linkin this case. I've flagged this as a bug forWordPress 5.0.1.