Skip to content

Conversation

@tsriram
Copy link
Contributor

@tsriram tsriram commented Mar 9, 2019

This fixes #26 (hopefully)

It seems that the bug reported with search selection occurs because we update selectedElementID inside if condition which is likely to fail most of the times. searchIndex & prevSearchIndex would be 0 when there are elements in searchResults array and they don't seem to change if user doesn't manually move to previous / next search result. And even if the searchResults array is updated, searchIndex could still be 0 and point to a different element in the tree which should be highlighted. Updating the selectedElementID fixes this issue. I'm not sure why was this if condition added and removing this would impact anything else. Please let me know if this is not the right fix :)

Before:

react-devtools-experimental-search-BEFORE

After:

react-devtools-experimental-search-AFTER

@bvaughn
Copy link
Owner

bvaughn commented Mar 9, 2019

Thanks for the PR @tsriram! I'm excited to review it when I get to a good stopping point with the profiler. That may take a few days. Just wanted to say "thanks" in the meanwhile.

}

// Changes in search index should override the selected element.
if (searchIndex !== prevSearchIndex) {
Copy link
Owner

@bvaughn bvaughn Mar 26, 2019

Choose a reason for hiding this comment

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

The idea behind this was to avoid having to pay the cost of getIndexOfElementID every time the context re-rendered. That lookup isn't too expensive but it's also something I'd like to avoid doing unnecessarily. In theory, if the index didn't change, we shouldn't need to look things up again.

I wonder if we could treat 0 as a special case...

Ideally we could just detect the case where we need to re-run the computation for index 0, and reset prevSearchIndex to e.g. null at the start of the reducer.

Copy link
Owner

@bvaughn bvaughn Mar 26, 2019

Choose a reason for hiding this comment

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

Did you come up with a small repro steps by chance? 😄 I forget what sequence used to trigger this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we could handle index 0 as a special case and updating the original if condition with an additional check for index 0 makes it work. Does this make sense?

Reproduction is quite easy (if I understand it correctly 😉):

  1. Go to https://react-devtools-experimental.now.sh/
  2. In the devtools search box, type list - first element <List> should be selected
  3. Continue typing and enter listitem - ideally the second element in the tree <Memo(ListItem)> should be selected but the first element is still shown as selected.

react-devtools-repro

You could see another example in my original screen grabs as well in the PR.

@bvaughn
Copy link
Owner

bvaughn commented Apr 4, 2019

I think Dan found a slightly better fix for this (#62) and I'm now wondering if this PR is also still necessary. I'd love to hear your thoughts?

@tsriram
Copy link
Contributor Author

tsriram commented Apr 4, 2019

Oh yeah, that's definitely a better fix. Will close this PR. Thanks!

@tsriram tsriram closed this Apr 4, 2019
@bvaughn
Copy link
Owner

bvaughn commented Apr 4, 2019

Thanks for taking a look and thanks for the PR! 😅 Sorry it took me a few days to dig in

@tsriram
Copy link
Contributor Author

tsriram commented Apr 4, 2019

No worries @bvaughn 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Searching sometimes selects root node

2 participants