WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.16k stars 4.05k forks source link

LinkControl suggestions query with multiple subtypes breaks if a subtype isn't registered #55810

Open marincarroll opened 8 months ago

marincarroll commented 8 months ago

Description

LinkControl's suggestionsQuery allows you to add multiple post types by giving the subtype property a comma-separated list of post type slugs. However, if one of those post types is not registered, it's seen as an invalid parameter with a 400 response and no suggestions will show.

Step-by-step reproduction instructions

Example – this works when 'other-type' is registered, otherwise 400s.

<LinkControl
    suggestionsQuery={ {
        type: 'post',
        subtype: 'post, other-type'
    } }
  />

Screenshots, screen recording, code snippet

GIF

Environment info

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

Yes

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

No

talldan commented 8 months ago

Thanks for reporting, this is an interesting one.

I'm personally not sure it's a bug, the implementer of Link Control can check the available post types before specifying the prop (using wp.data.select( 'core' ).getPostTypes()). The LinkControl component could also do this internally, but I think it would be overkill for lots of use cases to make it the default.

I think there's also an argument that the REST API response isn't great (completely failing to work for a minor misconfiguration), but that's not something that can be fixed in the Gutenberg project, it'd require a WordPress core change (and so a ticket in trac - https://core.trac.wordpress.org/).

github-actions[bot] commented 7 months ago

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.