Style Book: Fix crash when previewing variations for blocks without examples#79131
Conversation
|
The changes look good to me, Let me know once the PR is ready for review! |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks @im3dabasia! This PR is ready for review from my side. |
t-hamano
left a comment
There was a problem hiding this comment.
Thank for the PR.
if ( ! variation || ! examples ) {
return examples;
}This logic seems strange. Why would it return an example when there is no example provided?
This seems to be an issue that should be addressed upstream.
if ( blockVariation && filteredExamples?.examples?.length ) {
return {
examples: applyBlockVariationsToExamples(
filteredExamples.examples,
blockVariation
),
};
}The advantage of this approach is that the stylebook does not become empty.
|
Thanks for the review and the great suggestion @t-hamano! I've moved the check upstream to |
What?
Closes #79130
Adds a protective guard to
applyBlockVariationsToExamplesto prevent aTypeErrorcrash when attempting to apply style variations to an undefined list of examples.Why?
When opening the style variation detail screen for a block that does not have standalone Style Book examples (like
core/column), the editor crashes.How?
Added an early return inside
applyBlockVariationsToExamples(inpackages/editor/src/components/style-book/index.js) to checkif ( ! variation || ! examples ). Ifexamplesevaluates toundefined, it safely returns early without calling.map(). This prevents the crash and allows the UI to gracefully render an empty/fallback preview state instead.Testing Instructions
TypeError: Cannot read properties of undefined (reading 'map')errors.Screenshots or screencast