wp-parsely
wp-parsely copied to clipboard
Fix issue with `numAddedLinks` state in Smart Linking component
Describe the bug
The numAddedLinks
state does not update correctly after smart links are applied, remaining at 0 despite the function being called with the correct value. This makes the number shown in the component notice sometimes different from the one shown in the snackbar message, since the notice fallback to the number of suggested smart links when numAddedLinks
is zero.
To Reproduce
Steps to reproduce the behavior:
- Go to the Smart Linking section
- Click on the button to generate and apply smart links
- In some scenarios, when there are suggestions that can't be applied, the number of smart links applied shown in the notice will be different from the number of actually applied smart links, and different from the value reported in the Snackbar (that is correct).
Expected behavior
The numAddedLinks
state should update to reflect the correct number of smart links applied to the content.
Additional context
The numAddedLinks
state updating issue appears to involve asynchronous state updates, where the function setNumAddedLinks
is being called with the correct values but does not reflect these changes in the UI. This may be due to asynchronous operations or side effects within the component that reset or interfere with the state before it can update the UI.
There could be potential race conditions where multiple state updates occur in rapid succession or interference from other components or state management logic. Investigating the sequence and handling of state updates in conjunction with component lifecycle events might provide further insights into the issue.