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

Gutenberg crash if custom post type has template lock #37912

Closed
Tropicalista opened this issue Jan 12, 2022 · 3 comments · Fixed by #42677
Closed

Gutenberg crash if custom post type has template lock #37912

Tropicalista opened this issue Jan 12, 2022 · 3 comments · Fixed by #42677
Assignees
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Templates API Related to API powering block template functionality in the Site Editor

Comments

@Tropicalista
Copy link

Description

I create a custom post type with template lock. All works great, but if I select patterns on block inserter Gutenberg crashes.

I think the problem is template lock, because disabling it, all works great.

Step-by-step reproduction instructions

  1. Create a simple custom post type and set a template lock:
'template' => array(
    array( 'core/paragraph' ),
),
'template_lock' => 'insert',
  1. Go to your cpt and select block patterns
  2. Gutenberg crash
  3. If you are lazy, simply download my Popper plugin, try to disable the template lock and all works as expected.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 5.8.3
  • TwentyTwentyTwo theme
  • Clean install

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

@Mamaduka Mamaduka added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Templates API Related to API powering block template functionality in the Site Editor Needs Testing Needs further testing to be confirmed. labels Jan 12, 2022
@Mamaduka
Copy link
Member

Mamaduka commented Jan 13, 2022

Hello, @Tropicalista

How are you inserting the pattern? The template_lock disables block inserter.

Am I missing any details?

Screenshot

CleanShot 2022-01-13 at 12 15 24

@Tropicalista
Copy link
Author

I have probably messed up something. I was testing the 5.9 release candidate.

Once the custom post type is created, the button is disabled. But if I try to insert a child block the pattern is enabled and should work. This was working great on 5.8.3.

You can test it using my plugin: https://wordpress.org/plugins/popper/

@t-hamano
Copy link
Contributor

I have confirmed that this issue occurs not only with custom post types.

If template_lock is set to insert, the block should be locked and the inserter should be disabled.
But in the column block, it is unlocked and the editor crashes when the pattern is inserted.

I think blocks should not be able to be inserted at either level of hierarchy

Testing Instruction

  • Insert a column block and one paragraph block on the post editor.
  • Activate template_lock with the following code:
function custom_registered_post_type_post( $post_type, $post_type_object ) {
  $post_type_object->template = array(
    array( 'core/paragraph' )
  );
  $post_type_object->template_lock = 'insert';
}
add_action( 'registered_post_type_post', 'custom_registered_post_type_post', 10, 2 );
  • Reload the post editor and confirm that the paragraph block is not locked.
  • Press Enter to confirm that a new paragraph is created and the block inserter is activated.
  • Selecting a pattern from the inserter will crash the editor.
95a52899d702f54688531442ccb9b5dc.mp4

Error Info

pattern-panel.js:68 Uncaught TypeError: Cannot read properties of undefined (reading 'name')
    at PatternInserterPanel (pattern-panel.js:68:31)
    at renderWithHooks (react-dom.js?ver=6.0.1:15015:20)
    at mountIndeterminateComponent (react-dom.js?ver=6.0.1:17841:15)
    at beginWork (react-dom.js?ver=6.0.1:19079:18)
    at HTMLUnknownElement.callCallback (react-dom.js?ver=6.0.1:3942:16)
    at Object.invokeGuardedCallbackDev (react-dom.js?ver=6.0.1:3991:18)
    at invokeGuardedCallback (react-dom.js?ver=6.0.1:4053:33)
    at beginWork$1 (react-dom.js?ver=6.0.1:23994:9)
    at performUnitOfWork (react-dom.js?ver=6.0.1:22806:14)
    at workLoopSync (react-dom.js?ver=6.0.1:22737:7)

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jul 25, 2022
@t-hamano t-hamano linked a pull request Jul 31, 2022 that will close this issue
@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 25, 2022
@t-hamano t-hamano removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 2, 2022
@t-hamano t-hamano removed [Status] In Progress Tracking issues with work in progress Needs Testing Needs further testing to be confirmed. labels Sep 10, 2022
@t-hamano t-hamano mentioned this issue Oct 7, 2022
89 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Templates API Related to API powering block template functionality in the Site Editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants