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

Template part block doesn't handle a missing template part entity #36510

Closed
talldan opened this issue Nov 16, 2021 · 2 comments · Fixed by #37370
Closed

Template part block doesn't handle a missing template part entity #36510

talldan opened this issue Nov 16, 2021 · 2 comments · Fixed by #37370
Assignees
Labels
[Block] Template Part Affects the Template Parts Block Needs Design Feedback Needs general design feedback. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@talldan
Copy link
Contributor

talldan commented Nov 16, 2021

Description

When a template part block's associated template part entity/post is missing, the block is designed to show a warning to the user:

// We don't want to render a missing state if we have any inner blocks.
// A new template part is automatically created if we have any inner blocks but no entity.
if (
innerBlocks.length === 0 &&
( ( slug && ! theme ) || ( slug && isMissing ) )
) {
return (
<TagName { ...blockProps }>
<Warning>
{ sprintf(
/* translators: %s: Template part slug */
__(
'Template part has been deleted or is unavailable: %s'
),
slug
) }
</Warning>
</TagName>
);
}

Unfortunately this is never shown since the code that determines isMissing doesn't work. It uses the value from getEditedEntityRecord which always returns a (truthy) object when resolved.

I'm also unsure about this comment next to that code

A new template part is automatically created if we have any inner blocks but no entity.

This might be outdated as I can't see any evidence that this happens.

To solve this, some design guidance will probably be needed to determine the right behavior.

Related is #36507, which fixes the same issue in the navigation block. In that change we make the nav block go back to its placeholder when the associated menu id deleted or non-existent. That regressed and the message is back again 😞 .

Step-by-step reproduction instructions

  1. Add a paragraph with some text in the site editor
  2. Make it a template part using the 'Make template part' option in the block settings menu, give it a name, and create it.
  3. Save all the changes
  4. In wp-admin, navigate to Appearance > Template Parts and delete the template part you just created
  5. Go back to the site editor
  6. Observe that the template part made in step 2 is now empty. Blocks can be added to it, but they can't be saved.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress trunk
Gutenberg trunk
Brave on Mac OS

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 talldan added [Block] Template Part Affects the Template Parts Block [Type] Bug An existing feature does not function as intended labels Nov 16, 2021
@talldan talldan added the Needs Design Feedback Needs general design feedback. label Nov 16, 2021
@talldan
Copy link
Contributor Author

talldan commented Dec 14, 2021

#37222 mentions a similar issue with slightly different results.

@Mamaduka
Copy link
Member

I am assigning this to myself.

I think resolving isMissing is the smallest fix we can ship with 5.9. Then, we can discuss a better alternative for the "missing" state for the next release.

P.S. Adding a block to a missing Template Part also triggers an error:

actions.js:300 Uncaught TypeError: Cannot read properties of undefined (reading 'blocks')
    at actions.js:300
    at Array.reduce (<anonymous>)
    at actions.js:299
    at thunk-middleware.js:4
    at index.js:24
    at promise-middleware.js:20
    at Object.dispatch (resolvers-cache-middleware.js:57)
    at index.js:312
    at entity-provider.js:199
    at use-block-sync.js:223

@Mamaduka Mamaduka self-assigned this Dec 14, 2021
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block Needs Design Feedback Needs general design feedback. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants