Skip to content

Conversation

@acicovic
Copy link
Collaborator

@acicovic acicovic commented Jun 12, 2025

Description

When AbortErrors occur (e.g. an AbortController is aborting), we throw a ParselyAborted error. However, until now the ParselyAborted error wouldn't stop the firing of additional fetch requests in PCH tools.

We always check the ContentHelperError.retryFetch to determine whether we should retry any fetch operations. By making ParselyAborted set ContentHelperError.retryFetch to false, we make it stop further fetch retries.

While working on this, I also changed all related constant names to MAX_FETCH_RETRIES for coherence and easier retrieval across the codebase.

Motivation and context

When AbortErrors come up, we shouldn't continue execution. This PR makes the ParselyAborted error work as we would expect it.

How has this been tested?

Manually tested that firing a ParselyAbort error results in a retry fetch loop to only execute once.

Summary by CodeRabbit

  • Refactor

    • Standardized the naming of constants controlling fetch retry limits across various components for consistency.
    • Updated documentation comments for retry constants to clarify their purpose and version history.
    • Adjusted the scope of certain retry constants to reduce unnecessary exports.
  • Bug Fixes

    • Improved error handling for fetch operations by refining which errors will trigger a retry, particularly for Traffic Boost suggestions.

@acicovic acicovic added this to the 3.21.0 milestone Jun 12, 2025
@acicovic acicovic self-assigned this Jun 12, 2025
@acicovic acicovic added Maintenance & Fixes Ticket/PR related to codebase maintenance tasks Feature: PCI Ticket/PR related to Content Intelligence labels Jun 12, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (4)
  • build/admin-settings.asset.php is excluded by !build/**
  • build/admin-settings.js is excluded by !build/**
  • build/content-helper/dashboard-page.asset.php is excluded by !build/**
  • build/content-helper/dashboard-page.js is excluded by !build/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

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

📝 Walkthrough

Error: Could not generate a valid Mermaid diagram after multiple attempts.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 marked this pull request as ready for review June 12, 2025 15:28
@acicovic acicovic requested a review from a team as a code owner June 12, 2025 15:28
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: 0

🔭 Outside diff range comments (1)
src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (1)

233-237: 🛠️ Refactor suggestion

Clamp maxRetries to prevent negative or non-integer values

options?.maxRetries is accepted as-is. If a caller passes -1, Infinity, or NaN, the while loop never hits the 0 === maxRetries guard, opening the door to an infinite retry loop.

-let maxRetries = options?.maxRetries ?? MAX_FETCH_RETRIES;
+let maxRetries = Number.isFinite( options?.maxRetries as number )
+	? Math.max( 0, Math.floor( options!.maxRetries! ) )
+	: MAX_FETCH_RETRIES;

This keeps the current behaviour for valid inputs (including 0) while safeguarding against pathological values.

🧹 Nitpick comments (5)
src/content-helper/common/content-helper-error.tsx (1)

76-98: Extract no-retry list to a shared constant to avoid per-instance allocation.

noRetryFetchErrors is rebuilt every time ContentHelperError is instantiated. Given that the list is static, declare it once (e.g. as a static readonly property or a module-level const) and reference it from the constructor. This removes needless allocations and keeps the list single-sourced.

-		// Errors for which we should not retry a fetch operation.
-		const noRetryFetchErrors: Array<ContentHelperErrorCode> = [
+// Errors for which we should not retry a fetch operation.
+const NO_RETRY_FETCH_ERRORS: readonly ContentHelperErrorCode[] = [
 			ContentHelperErrorCode.AccessToFeatureDisabled,
 			ContentHelperErrorCode.ParselyAborted,
 			/* … */
 		];
 …
-		this.retryFetch = ! noRetryFetchErrors.includes( this.code );
+		this.retryFetch = ! NO_RETRY_FETCH_ERRORS.includes( this.code );
src/content-helper/editor-sidebar/related-posts/component.tsx (1)

38-44: Avoid duplicating identical MAX_FETCH_RETRIES constants across modules.

The same hard-coded value (1) is now present in several files. Consider exporting a single MAX_FETCH_RETRIES constant from a common utility (e.g. common/retry.ts) so the limit can be adjusted from one place and remains consistent.

src/content-helper/dashboard-widget/components/top-posts.tsx (1)

26-33: Centralise retry constant to prevent drift.

Same comment as for Related Posts: exporting a shared MAX_FETCH_RETRIES avoids future divergence and makes the retry policy discoverable.

src/content-helper/editor-sidebar/performance-stats/component.tsx (1)

38-44: Consolidate retry configuration.

Consider re-using a project-wide constant rather than redefining MAX_FETCH_RETRIES locally.

src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (1)

141-147: Export & centralise the retry constant

MAX_FETCH_RETRIES improves readability, but the same literal is still being introduced in several modules in this PR. To avoid future drift, place it in a shared constants module (e.g. src/content-helper/common/constants.ts) and export it:

-const MAX_FETCH_RETRIES = 3;
+export const MAX_FETCH_RETRIES = 3; // Shared across content-helper modules.

Downstream files can then import { MAX_FETCH_RETRIES } …, giving you a single source of truth.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97a8dee and 8a528ae.

⛔ Files ignored due to path filters (8)
  • build/admin-settings.asset.php is excluded by !build/**
  • build/admin-settings.js is excluded by !build/**
  • build/content-helper/dashboard-page.asset.php is excluded by !build/**
  • build/content-helper/dashboard-page.js is excluded by !build/**
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.js is excluded by !build/**
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
📒 Files selected for processing (6)
  • src/content-helper/common/content-helper-error.tsx (1 hunks)
  • src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (2 hunks)
  • src/content-helper/dashboard-widget/components/top-posts.tsx (2 hunks)
  • src/content-helper/editor-sidebar/performance-stats/component.tsx (2 hunks)
  • src/content-helper/editor-sidebar/related-posts/component.tsx (5 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,ts,tsx,jsx}`: "Perform a detailed review of the provided code with following key aspects in mind: - Review the code to ensure it is well-structured and adheres to best ...

**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
  • src/content-helper/common/content-helper-error.tsx
  • src/content-helper/dashboard-widget/components/top-posts.tsx
  • src/content-helper/editor-sidebar/related-posts/component.tsx
  • src/content-helper/editor-sidebar/performance-stats/component.tsx
  • src/content-helper/editor-sidebar/smart-linking/component.tsx
  • src/content-helper/dashboard-page/pages/traffic-boost/provider.ts
🔇 Additional comments (5)
src/content-helper/editor-sidebar/related-posts/component.tsx (1)

204-205: LGTM – rename propagated correctly.

The updated constant is referenced consistently in all call sites. No functional issues spotted.

Also applies to: 227-228, 266-267, 300-302

src/content-helper/dashboard-widget/components/top-posts.tsx (1)

71-73: Rename applied correctly.
Usage updated; behaviour unchanged.

src/content-helper/editor-sidebar/performance-stats/component.tsx (1)

237-239: Rename looks good.
Fetch logic still honours the retryFetch flag.

src/content-helper/editor-sidebar/smart-linking/component.tsx (2)

554-556: Good touch – retry count carried forward for abort message.
The calculation of numRetries based on MAX_FETCH_RETRIES maintains correct user feedback.


63-66:

Details

✅ Verification successful

Potential breaking change – constant no longer exported.

MAX_NUMBER_OF_RETRIES was previously exported; the new MAX_FETCH_RETRIES is file-local. Any external imports will now fail. Please verify there are no remaining references.

Run the following check:


🏁 Script executed:

#!/bin/bash
# Find leftover references to the removed constant.
rg -n "MAX_NUMBER_OF_RETRIES"

Length of output: 168


No external references to MAX_NUMBER_OF_RETRIES found.

  • The ripgrep search only returned the JSDoc line in component.tsx.
  • Removing the export poses no breakage since no code imports the old constant.

@acicovic acicovic merged commit 81a85b5 into develop Jul 3, 2025
33 checks passed
@acicovic acicovic deleted the update/stop-fetch-retries-whenparselyborted-errors-occur branch July 3, 2025 09:07
github-actions bot added a commit that referenced this pull request Jul 3, 2025
@acicovic acicovic added the Changelog: Fixed PR to be added under the changelog's "Fixed" section label Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed PR to be added under the changelog's "Fixed" section Feature: PCI Ticket/PR related to Content Intelligence Maintenance & Fixes Ticket/PR related to codebase maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants