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

fix(pro:search): segmentState should init only when item key changes #1496

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/pro/search/src/composables/useSegmentStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export function useSegmentStates(
let searchStateWatchStop: () => void
watch(
() => props.searchItem,
searchItem => {
(searchItem, oldSearchItem) => {
if (searchItem?.key === oldSearchItem?.key) {
return
}

searchStateWatchStop?.()
initSegmentStates()
if (searchItem?.key) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks good and there are no obvious bugs or issues. However, it is always a good idea to do some basic code review to make sure that the code is correct and does not have any potential problems.

First, I would suggest verifying that the searchItem and oldSearchItem variables are defined and not null before comparing them. This can be done by adding a simple check like:

if (searchItem && oldSearchItem && searchItem?.key === oldSearchItem?.key) {
    return;
}

Also, I would recommend adding some logging around the code patch, so we can see what is happening while the code is running. This can help in debugging any issues that may arise.

Finally, I would suggest adding some unit tests to ensure that the code is functioning correctly. This can be done using a testing framework such as Jest.

Overall, this code looks good and should be safe to use. However, it is always a good idea to double check and make sure that the code is correct and does not have any potential issues.

Expand Down