WordPress / gutenberg

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

PostViewLink Component breaks on undefined labels #62918

Open JNBG opened 3 months ago

JNBG commented 3 months ago

Description

When editing some Template Files via the Website-Editor the Page died with a JS-Error Message in the console that the component could not access "view_item" on labels.

Happend when accessing a Template like the header. The Page is using a custom built theme/editor Plugin so the Error is probably caused by that (using the 2024-Theme it did not occur).

Even tho the Issue is caused by custom Coding, the Checks for undefined could/should be in Place.

Issue Report in Slack (with some Infos from @Automattic)

Step-by-step reproduction instructions

  1. Open Website-Editor
  2. Go To Tempalte-Parts
  3. Click on Header
  4. Site crashes with Error in Console

Screenshots, screen recording, code snippet

Can be fixed by by changing the Line 16280 in editor.js from
label: postType?.labels.view_item to label: postType?.labels?.view_item (added the ? to check if labels is defined).

Other occurence on Line 13819 in editor.js in the "PostURL" Component might be experiencing the same Issue - According to Info from Slack, this could be just removed.

Environment info

WP 6.5.5 Desktop with Windows 10 Chrome Version 126.0.6478.127 Custom built WP Theme (non-official) Custom built WP Editor (non-official)

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, No

JNBG commented 3 months ago

Some further Digging revealed it appears that it is the "wp_template_part" PostType causing the Issues, this one is missing Labels, supports etc. Found it later as it broke the PostTypeSupportCheck Component next

JNBG commented 3 months ago

Further info on the PostTypeSupportCheck Component: It broke due to the "wp_template_part" Posttype not having a supports Key. (editor.js:7248) -> Wrapped that in an if statement to circumvent the Issue for now