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

Fix: Fixed site-editor crashing when added front-page template and clicking more option #67500

Conversation

Mayank-Tripathi32
Copy link
Contributor

resolves #67498

What?

This PR modifies how the array for actions is constructed by using default action destructuring and conditionally pushing values to the array.

Why?

The previous implementation was adding an empty array at the end of the actions list when the condition for shouldShowSetAsHomepageAction was false. This caused issues, particularly in the "More Options" menu, where an empty action was being passed and leading to a crash. This PR resolves that by ensuring that only valid actions are added to the array.

How?

To address this issue, I changed the following snippet:
Old Code:

let actions = [
    ...defaultActions,
    shouldShowSetAsHomepageAction ? setAsHomepageAction : [],
];

The previous code resulted in adding an empty array at the end when the condition shouldShowSetAsHomepageAction was false.

New Code:

let actions = [...defaultActions];
if (shouldShowSetAsHomepageAction) {
    actions.push(setAsHomepageAction);
}

This change ensures that if shouldShowSetAsHomepageAction is false, the setAsHomepageAction is not pushed into the array, avoiding the empty array scenario and preventing the crash.

Testing Instructions

  1. Go to Appearance > Editor (Site Editor) in the WordPress admin > Templates.
  2. Add a new Front Page template through the Site Editor.
  3. Save the changes to ensure the template is added.
  4. Click on the three dots (More Options) for any template in the template list.
  5. It should not crashe the page anymore
  6. Now delete front page template and click, it should work as expected.

Copy link

github-actions bot commented Dec 2, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano self-requested a review December 3, 2024 04:44
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Dec 3, 2024
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Perhaps the original code should have been written like this:

const actions = [
  ...defaultActions,
  ...(shouldShowSetAsHomepageAction ? [setAsHomepageAction] : []),
];

However, I think it would be clearer to use the push method, as done in this PR. Let's get some feedback from the contributors who worked on #65426.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@oandregal oandregal added this to the Gutenberg 19.9 milestone Dec 3, 2024
@oandregal oandregal merged commit 9addc70 into WordPress:trunk Dec 3, 2024
75 of 76 checks passed
@mikachan
Copy link
Member

mikachan commented Dec 3, 2024

Thanks for fixing this!

im3dabasia pushed a commit to im3dabasia/gutenberg that referenced this pull request Dec 4, 2024
Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: oandregal <[email protected]>
michalczaplinski pushed a commit that referenced this pull request Dec 5, 2024
Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: oandregal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site-Editor: Crashes when clicking on action after adding front page template
4 participants