-
Notifications
You must be signed in to change notification settings - Fork 32
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 Smart Linking: Fix bug causing ‘No smart links’ error despite valid API response #2662
Conversation
WalkthroughWalkthroughThe recent changes to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SmartLinkingPanel
participant LinkProcessor
User->>SmartLinkingPanel: Request to process links
SmartLinkingPanel->>LinkProcessor: processSmartLinks(links)
LinkProcessor-->>SmartLinkingPanel: return processedSmartLinks
SmartLinkingPanel->>SmartLinkingPanel: Check processedSmartLinks.length
alt Links found
SmartLinkingPanel->>User: Open review modal
else No links found
SmartLinkingPanel->>User: Throw error (ContentHelperErrorCode.ParselySuggestionsApiNoData)
end
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
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
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files ignored due to path filters (2)
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 (1)
- src/content-helper/editor-sidebar/smart-linking/component.tsx (3 hunks)
Additional context used
Path-based instructions (1)
src/content-helper/editor-sidebar/smart-linking/component.tsx (1)
Pattern
**/*.{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."
Additional comments not posted (4)
src/content-helper/editor-sidebar/smart-linking/component.tsx (4)
354-355
: LGTM! Approve the type change.The change to explicitly define the return type as
Promise<SmartLink[]>
improves type safety and clarity.
488-498
: LGTM! Approve the changes.The function now stores the processed smart links in a new variable
processedSmartLinks
and checks its length to determine error handling. This change improves the accuracy of error handling.
Line range hint
501-539
:
LGTM! No changes observed.The
generateSmartLinksWithRetry
function handles retries and error handling for generating smart links. No changes are observed in this function.
Line range hint
357-433
:
Ensure all function calls toprocessSmartLinks
match the new signature.The function now returns a
Promise<SmartLink[]>
. Verify that all calls toprocessSmartLinks
handle the returned promise correctly.Verification successful
All function calls to
processSmartLinks
handle the returned promise correctly.
- The function call to
processSmartLinks
is awaited, ensuring the promise is handled properly.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `processSmartLinks` handle the returned promise correctly. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type tsx -A 5 $'processSmartLinks'Length of output: 66
Script:
#!/bin/bash # Description: Verify all function calls to `processSmartLinks` handle the returned promise correctly. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --glob '**/*.tsx' -A 5 'processSmartLinks'Length of output: 1349
64f67ee
to
75280f5
Compare
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
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files ignored due to path filters (2)
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 (1)
- src/content-helper/editor-sidebar/smart-linking/component.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/content-helper/editor-sidebar/smart-linking/component.tsx
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.
Thanks!
Description
The #2654 PR introduced a bug where, even though the API would return valid Smart Links, the UI would throw a "No smart links were generated." error.
This was due to how React handles store variables. Even though
processSmartLinks
updates thesmartLinks
variable in the Smart Linking store, thesmartLinks
variable would be empty/outdated when we check its length (if (smartLinks.length === 0)
).This PR addresses this issue by returning the processed smart links from the
processSmartLinks
function and using that returned value to determine if an error should be outputted.Motivation and context
Fix bug that prevents the proper usage of the Smart Linking feature
How has this been tested?
Tested manually with different mocked-up API responses.
Summary by CodeRabbit
New Features
Improvements