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

PCH Related Posts: Fix hang under edge cases #2432

Merged
merged 3 commits into from
May 6, 2024

Conversation

acicovic
Copy link
Collaborator

@acicovic acicovic commented Apr 26, 2024

Description

PCH Related Posts would hang under the edge case described in #2423. In this particular case the issue was the post author's ID, but we've also hardened getting the post's category IDs and tag IDs, since all these use the same Gutenberg function and could thus fail similarly.

As part of this, we now treat the result received by usePostData() as unknown and perform validation on it to see that it resembles User[] or Taxonomy[] objects, and that name fields actually exist.

Our assumption so far had been that we could always get the current post's author. As this turned out to be incorrect, making the post's author an optional field resulted in a few UI glitches that were also resolved as part of this PR.

Motivation and context

Fixes #2423.

How has this been tested?

Manually tested by setting irregular values to authorId, categoryIds and tagIds within the usePostData() function.

Summary by CodeRabbit

  • New Features

    • Enhanced filter settings in the editor sidebar to dynamically display options based on data availability for authors, categories, and tags.
    • Improved error handling and data checks in the related posts component to ensure robust performance.
    • Updated styling for the related posts section to improve layout and spacing.
  • Bug Fixes

    • Refined data handling logic to prevent issues with invalid or incomplete data in related posts functionalities.
  • Documentation

    • No visible changes to end-users.
  • Refactor

    • Internal updates to improve code maintainability and readability, with no direct impact on end-user experience.
  • Style

    • Adjustments made to CSS for better visual organization of related posts in the editor sidebar.
  • Tests

    • Enhanced testing structures to support new functionalities and ensure reliability.

Copy link
Contributor

coderabbitai bot commented Apr 26, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates across various components in the editor-sidebar/related-posts module primarily enhance the robustness of the Related Posts functionality. These changes include improved error handling, dynamic rendering based on data availability, and refined data validation. The modifications aim to ensure smoother user experiences even when encountering data inconsistencies or errors.

Changes

File Path Summary of Changes
.../component-filter-settings.tsx, .../component.tsx Updated rendering logic, added error handling, refined data checks, and modified component structures.
.../hooks.ts Enhanced data validation and added readiness checks.
.../related-posts/related-posts.scss Adjusted CSS for layout and spacing.
tests/js/content-helper/structure.test.tsx Updated test structures and added new test functions.

Assessment against linked issues

Objective Addressed Explanation
Prevent PCH Related Posts from hanging when receiving errors for filter data [#2423]
Ensure Related Posts tool remains operational despite errors in filter data [#2423]
Display error message if all filters are erroneous [#2423] The changes do not explicitly mention handling or displaying a message when all filters are invalid.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@acicovic acicovic added this to the 3.14.4 milestone Apr 26, 2024
@acicovic acicovic marked this pull request as ready for review April 26, 2024 14:19
@acicovic acicovic requested a review from a team as a code owner April 26, 2024 14:19
@acicovic
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Copy link
Contributor

@vaurdan vaurdan 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 tackling this issue! Looks good to me!

@acicovic
Copy link
Collaborator Author

acicovic commented May 6, 2024

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented May 6, 2024

Actions Performed

Comments resolved and changes approved.

@acicovic acicovic merged commit 9492519 into prepare/3.14.4-release May 6, 2024
34 checks passed
@acicovic acicovic deleted the fix/hanging-pch-related-posts branch May 6, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants