-
Notifications
You must be signed in to change notification settings - Fork 33
Stop fetch retries when ParselyAborted errors occur #3455
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
Stop fetch retries when ParselyAborted errors occur #3455
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (4)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the 📝 WalkthroughError: 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 suggestionClamp
maxRetriesto prevent negative or non-integer values
options?.maxRetriesis accepted as-is. If a caller passes-1,Infinity, orNaN, thewhileloop never hits the0 === maxRetriesguard, 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.
noRetryFetchErrorsis rebuilt every timeContentHelperErroris instantiated. Given that the list is static, declare it once (e.g. as astatic readonlyproperty or a module-levelconst) 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 identicalMAX_FETCH_RETRIESconstants across modules.The same hard-coded value (1) is now present in several files. Consider exporting a single
MAX_FETCH_RETRIESconstant 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_RETRIESavoids 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_RETRIESlocally.src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (1)
141-147: Export & centralise the retry constant
MAX_FETCH_RETRIESimproves 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
⛔ Files ignored due to path filters (8)
build/admin-settings.asset.phpis excluded by!build/**build/admin-settings.jsis excluded by!build/**build/content-helper/dashboard-page.asset.phpis excluded by!build/**build/content-helper/dashboard-page.jsis excluded by!build/**build/content-helper/dashboard-widget.asset.phpis excluded by!build/**build/content-helper/dashboard-widget.jsis excluded by!build/**build/content-helper/editor-sidebar.asset.phpis excluded by!build/**build/content-helper/editor-sidebar.jsis 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.tsxsrc/content-helper/dashboard-widget/components/top-posts.tsxsrc/content-helper/editor-sidebar/related-posts/component.tsxsrc/content-helper/editor-sidebar/performance-stats/component.tsxsrc/content-helper/editor-sidebar/smart-linking/component.tsxsrc/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 theretryFetchflag.src/content-helper/editor-sidebar/smart-linking/component.tsx (2)
554-556: Good touch – retry count carried forward for abort message.
The calculation ofnumRetriesbased onMAX_FETCH_RETRIESmaintains correct user feedback.
63-66:Details
✅ Verification successful
Potential breaking change – constant no longer exported.
MAX_NUMBER_OF_RETRIESwas previously exported; the newMAX_FETCH_RETRIESis 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_RETRIESfound.
- The ripgrep search only returned the JSDoc line in
component.tsx.- Removing the export poses no breakage since no code imports the old constant.
…s-whenparselyborted-errors-occur" (81a85b5)
Description
When
AbortErrors occur (e.g. anAbortControlleris aborting), we throw aParselyAbortederror. However, until now theParselyAbortederror wouldn't stop the firing of additional fetch requests in PCH tools.We always check the
ContentHelperError.retryFetchto determine whether we should retry any fetch operations. By makingParselyAbortedsetContentHelperError.retryFetchtofalse, we make it stop further fetch retries.While working on this, I also changed all related constant names to
MAX_FETCH_RETRIESfor coherence and easier retrieval across the codebase.Motivation and context
When
AbortErrors come up, we shouldn't continue execution. This PR makes theParselyAbortederror work as we would expect it.How has this been tested?
Manually tested that firing a
ParselyAborterror results in a retry fetch loop to only execute once.Summary by CodeRabbit
Refactor
Bug Fixes