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 Smart Linking: Fix removal of existing Smart Links on subsequent runs #2430

Closed
wants to merge 4 commits into from

Conversation

vaurdan
Copy link
Contributor

@vaurdan vaurdan commented Apr 24, 2024

Description

It was reported that when running the Smart Linking a second time in the same block would remove the existing Smart Links from that block and insert the new ones. This seems to be happening since at least WP 6.5.3.

This PR changes the how we were obtaining the block content - using originalContent - and now it uses the more appropriate getBlockContent function to get the most up-to-date content for that given block.

Motivation and context

Improve the reliability of the Parse.ly plugin and the Smart Linking feature in the latest WordPress release.

How has this been tested?

Tested locally by generating Smart Links on the same block multiple times, none of these tests resulted in the removal of any existing smart links.

Summary by CodeRabbit

  • Enhancements
    • Improved the smart linking feature within the editor sidebar, enhancing link generation and application based on content blocks and attributes.

@vaurdan vaurdan added this to the 3.15.0 milestone Apr 24, 2024
@vaurdan vaurdan self-assigned this Apr 24, 2024
@vaurdan vaurdan requested a review from a team as a code owner April 24, 2024 16:07
Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

Walkthrough

The update in the code primarily enhances the smart linking feature within the editor sidebar. It improves how block content is accessed and smart links are applied, optimizing the overall functionality and user experience in managing links based on content and attributes.

Changes

File Path Summary of Changes
.../editor-sidebar/smart-linking/component.tsx Adjusted access to block content and optimized smart linking in the editor sidebar.

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.

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 24, 2024

This is related and closes #2422

@vaurdan vaurdan linked an issue Apr 24, 2024 that may be closed by this pull request
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: 1

Out of diff range and nitpick comments (1)
src/content-helper/editor-sidebar/smart-linking/component.tsx (1)

5-5: Consider removing the eslint-disable-next-line import/named directive if it's no longer necessary.

@acicovic
Copy link
Collaborator

Some questions/thoughts:

  1. Would it be easy to implement this solution for a 3.14.4 patch release (base 3.14.3), or does it make things complicated because of other changes?
  2. It is mentioned here that this solution keeps previous smart links. I assume this means that it also keeps user-defined links intact.
  3. Whether this gets to be a part of a 3.14.4 patch release or 3.15, we should make sure it works in previous WordPress versions. Testing this with WordPress Playground should be easy, and this should work from at least WP 6.3 and newer. But let's decide first if it will be part of a patch or minor release to avoid more duplicate work.

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 26, 2024

Thank you for your questions!

Would it be easy to implement this solution for a 3.14.4 patch release (base 3.14.3), or does it make things complicated because of other changes?

That's a good question. If we are going to push this to 3.14.3 base, it might have conflict with a few recent PRs, namely the #2401 (provider refactoring) and API retries (#2386). Although it should be relatively easy to fix manually.

It is mentioned here that this solution keeps previous smart links. I assume this means that it also keeps user-defined links intact.

Yes, that is correct! The user-defined links were never a problem, since they were included in the block's originalContent prop already. So these will (still) be preserved.

Whether this gets to be a part of a 3.14.4 patch release or 3.15, we should make sure it works in previous WordPress versions. Testing this with WordPress Playground should be easy, and this should work from at least WP 6.3 and newer. But let's decide first if it will be part of a patch or minor release to avoid more duplicate work.

Yeah, agreed. I think it should, since this function - getBlockContent - is three years old. But I will spin up a test env and give it a try. I will update here with the results.

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 26, 2024

Yeah, agreed. I think it should, since this function - getBlockContent - is three years old. But I will spin up a test env and give it a try. I will update here with the results.

Update: it works as expected in 6.3, validated with a wp-now environment 🙂

@acicovic
Copy link
Collaborator

If we are going to push this to 3.14.3 base, it might have conflict with a few recent PRs, namely the #2401 (provider refactoring) and API retries (#2386). Although it should be relatively easy to fix manually.

I think the way I'd approach this is to just branch from 3.14.3 and add the updated function/code there, with any needed adaptations. Attempting to merge the current work could bring a lot of code in, and more points of failure which we don't want in a patch release. I hope I'm making sense. What do you think?

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 26, 2024

I think the way I'd approach this is to just branch from 3.14.3 and add the updated function/code there, with any needed adaptations. Attempting to merge the current work could bring a lot of code in, and more points of failure which we don't want in a patch release. I hope I'm making sense. What do you think?

Sounds good to me, yes!

@vaurdan vaurdan requested a review from acicovic April 29, 2024 09:02
@acicovic
Copy link
Collaborator

Hello, I see you re-requested a review. I think it might make more sense to make create and merge the 3.14.4 PR first, just in case this PR becomes redundant. No issue approving though 🙂

@acicovic
Copy link
Collaborator

acicovic commented May 6, 2024

Looking into this because I see it having conflicts but I wouldn't expect it to.

@acicovic
Copy link
Collaborator

acicovic commented May 6, 2024

@vaurdan, after merging develop into this, there seems to be only one whitespace change. I propose closing this PR and integrating the whitespace change in any Smart Linking work you're doing, or just ignore the change.

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

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4178215 and a8d36af.
Files selected for processing (1)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx

@vaurdan
Copy link
Contributor Author

vaurdan commented May 13, 2024

Sounds good to me! Closing this one.

@vaurdan vaurdan closed this May 13, 2024
@acicovic acicovic deleted the fix/smart-linking-remove-old-links branch June 12, 2024 07:26
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.

Smart Linking: Don't auto-remove existing links
2 participants