-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Avoid browser freeze when copy paste icon in icon picker #14387
Conversation
4af2379
to
0ab938d
Compare
src/components/ha-icon-picker.ts
Outdated
this.comboBox.filteredItems = filteredItems; | ||
// Setting it sync cause browser freeze when user paste an icon text | ||
setTimeout(() => { | ||
this.comboBox.filteredItems = filteredItems; |
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.
I think this is a dirty fix to a bigger problem. The problem I think stems from going behind lit's back to update the items instead of tying them to a reactive property. So whenever a litElement update is triggered, you are starting over with iconItems
because that's in render
.
Instead, @property
the filtered items, update them on input, and let lit handle the update.
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.
Yes you right. I think the filtered items assignment is old code to avoid re-rendering the whole input (created before ha-combobox) but it doesn't make sense anymore. I will look to refactor the component 🙂
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.
👍 I think you could probably keep most as is and just replace this.combobox.filteredItems
everywhere with a reactive property update. Might also need to call this.requestUpdate()
if the property is only mutated.
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.
I changed it to a reactive state but the setTimeout is always needed... 😕 I have the same behavior. I didn't understand why it's just when pasting a text...
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.
Well, at least it's cleaner now 😜
I was so in disbelief that this actually fixes the problem that I pulled the branch down to try it out. When I test, the initial paste into an empty field goes smoothly, but then I can repeatedly crash the browser by:
- Tab to the next field
- Shift+tab back to the icon picker
- Paste over the 1st paste or just delete it and paste again
I'll try to spend a few more minutes on it to see if I can narrow it down.
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.
It also depend of the content paste. If you paste mdi:home
, it crash. If you paste mdi:account
it doesn't crash. I think the proper solution is to use web worker for the filter to do the search in a background thread.
Doing the computation in background seems to work. I also removed the minimum characters count because it's not needed anymore. |
My hypothesis last night was that the pastes are probably just firing too many
This seems to work smoothly no matter what I paste or how many times. I can push it to another branch if you want to take a look, but it was pretty simple. PS - I also noticed a potential issue when loading custom icon sets but that's unrelated to this. |
I think a combination of both solutions might be best, depending on how long filtering actually takes with the fix from Steve. (if it is fast, there is no need to do it in a background worker) |
I'll push it out so you guys can take a look and test |
See #14401 |
I can still repeatedly cause a crash by using the same technique as above even with the web worker. I can also crash it by quickly typing gibberish into the field. |
I removed the web worker and I use |
Maybe we can debounce the filter changed event? There is an open issue for vaadin combobox (vaadin/web-components#518), so we must add this for now. |
Nope, still crashes 😞 I had a similar idea though, but first did the changes I made in #14401 make any difference for you? |
Still crashes too 😕 |
Okay, one more trick to try... I'll push in a minute or two |
b3803d8
to
900b9cd
Compare
I rebased the PR to have the last I tested of several devices and saw no issues.
Test protocol :
@steverep Can you confirm the issue is fixed for you too? If not, can you describe the steps to reproduce it ? 🙂 |
Nope, this branch still has the issue for me on Windows 10 with Chrome. Firefox seems much more resistant because I haven't been able to reproduce it there for a while. Steps are the same as I stated above. Here's more detail:
I think browser is a factor, but if it's a timing issue then any number of factors could affect it. FYI, I've also tried many other things without success, including completely removing the rendering of icons in the overlay and field. I'm thinking we should treat this as a vaadin bug and solicit their help. |
Closing since #14401 was merged. |
Proposed change
Avoid browser freeze when copy paste icon in icon picker. I just did not understand why. It also depends of the pasted content. Setting
filteredItems
async fixes the problem.Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: