dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

@bind-Text on Entry can cause an infinite loop in some cases #430

Closed Dreamescaper closed 2 years ago

Dreamescaper commented 2 years ago

STR:

  1. Create an Entry element with @bind-Text.
  2. On Android with Google Keyboard, set focus to field and type: 'a', 'b', '\<space>', '\<space>'

ER: Entry has text "ab."

AR: Application and Google Keyboard freezes.

Because of Google Keyboard feature to add '.' automatically if you type twice, Entry produces two TextChanged events at the same time - for "ab" and for "ab.". We handle handle both of those events, therefore change Text back to "ab", and then to "ab.". That leads to more TextChanged events, and therefore to an infinite loop.

A simple workaround would be to use actual Entry text instead of event's NewText property in MBB TextChanged event, that would still invoke TextChanged event twice, but will prevent it from an infinite loop. I'm wondering whether this issue happened in Web Blazor, and how it was solved there.

AmirImam commented 2 years ago

I tried the same steps as you mentioned but this error never appeared

Dreamescaper commented 2 years ago

My bad, bad github formatting. The point is you need to type spacebar twice.

AmirImam commented 2 years ago

My bad, bad github formatting. The point is you need to type spacebar twice.

Yes that's what I understood and what I did, but the app didn't freeze

Dreamescaper commented 2 years ago

Actually you're absolutely right. This only happens in my fork, which contains changes from this PR (among others): https://github.com/dotnet/MobileBlazorBindings/pull/425

My bad, I'll update that PR to fix that.

Thanks!!!