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

Selections are immediately cleared/reset with Liveview 1.0 #72

Closed
markolson-powerschool opened this issue Jun 14, 2024 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@markolson-powerschool
Copy link

markolson-powerschool commented Jun 14, 2024

Upgrading our application to LV 1.0.0-rc.0, we're now seeing every LiveSelect with a value reset to its previous selection once the input has a blur event triggered.

There was a bug pre 1.0 where liveview wouldn't focus readonly inputs, meaning that blur events wouldn't fire afterwards, and we suspect that's what's triggering this behavior. Watching which HANDLE EVENT log messages come in, we do see that there is no "blur" event triggered with lv 0.20.14, but there is with 1.0.0-rc.0.

Changing the dep to {:phoenix_live_view, "==1.0.0-rc.0", override: true}, and updating the assets, you see this behavior on the sample app:

LV1.0.0-rc.0.mov

We can't think of a situation where blurring should reset the field, but wanted to see if there was some subtlety we were missing before making a PR that...

  • removed the call to maybe_restore_selection in handle_event("blur", ...)
  • removed the call to clear in handle_event("focus", ...), using parent_event consistently.

Doing those two things gets the dropdown behaving as we'd expect, as best we can tell...

Removing clear doesn't let you search again, of course..

lv-1.0.0-rc.0-with-patch.mov
@maxmarcon
Copy link
Owner

maxmarcon commented Jun 14, 2024

Hi and thanks for flagging this! I will have a look as soon as I find some time

@maxmarcon
Copy link
Owner

maxmarcon commented Jun 16, 2024

Hi @markolson-powerschool, I just pushed c85673c to fix this specific problem on main, can you please check if it works for you?

There was a bug pre 1.0 where liveview wouldn't focus readonly inputs

Confused because live view has been focusing my readonly (i.e. with an active selection) live_select input just fine so far.
However, when I run it against LV 1.0.0-rc.0., I no longer get a focus event when the user click on the field. Consequently, the field is not cleared and the user can't search:

Screen.Recording.2024-06-16.at.23.52.12.mov

Pretty annoying. Why do you say that LV pre 1.0 wasn't focusing readonly inputs? If that was the case, live_select would have never worked.

@maxmarcon
Copy link
Owner

maxmarcon commented Jun 17, 2024

Even stranger: I do get the focus event after I submit the form

Screen.Recording.2024-06-17.at.06.38.18.mov

If you have any idea of what might be going on here, that'd would be very helpful :)

This doesn't make much sense and smells like a LV bug to me

@maxmarcon maxmarcon added the bug Something isn't working label Jun 17, 2024
@markolson-powerschool
Copy link
Author

Hi @markolson-powerschool, I just pushed c85673c to fix this specific problem on main, can you please check if it works for you?

This does seems to work! We'll give it a more thorough once-over this morning.

There was a bug pre 1.0 where liveview wouldn't focus readonly inputs
Pretty annoying. Why do you say that LV pre 1.0 wasn't focusing readonly inputs? If that was the case, live_select would have never worked.

phoenixframework/phoenix_live_view@c46af7d
I don't fully grok the guts of how diffing works, but this is the commit that began to cause the issue - actively blurring a readonly field if it'd just been patched as part of a liveview update.

@maxmarcon
Copy link
Owner

maxmarcon commented Jun 17, 2024

FYI: I ran the showcase app against phoenixframework/phoenix_live_view@c46af7d and the issues mentioned here didn't occur. So that's certainly not the commit that introduced this bug

@markolson-powerschool
Copy link
Author

markolson-powerschool commented Jun 17, 2024

Huh, well then. I'm wondering what I recreated using that commit then, and wishing I'd taken better contemporaneous notes.
Eitherway, it is working now, so thank you for the quick investigation and fix.

@maxmarcon
Copy link
Owner

No you were right and I made a mistake: it's phoenixframework/phoenix_live_view@c46af7d that introduced the bug.

(I had checked out the commit but forgotten to rebuild the live_view assets locally, they're not updated with every new commit to the js code!)

Ok, cool, so now we narrowed it down to that commit. I'm gonna try to fix the remaining problem (the input not getting focus)

@maxmarcon
Copy link
Owner

Fixed with b31a9f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants