-
Notifications
You must be signed in to change notification settings - Fork 47
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
Client event selection_recovery fails when wrapped in input_for #96
Comments
Hi @atcherry! Thanks for reporting this and taking the time to dig into it. Would you be able to produce a MR for this? Your proposed fix sounds good to me |
Can do! I'm looking into more about what the exact scenario is that causes this. I tried reproducing this in a new project with no success with an unchanging number of inputs. That leads me to think that perhaps it is a bit more nuanced than just |
We encountered the same issue, causing a crash loop on the LiveView process. I've tested replacing |
I tested the fix in production and we started getting this error:
On the line
Of At least the user browser doesn't stay on a crash loop. |
@thiagopromano that is a problem. Sounds like you aren't giving your live select an id, so it generates the default id. @maxmarcon thoughts? |
I would like to point out that in our use case, the form that contains the Therefore, it is understandable that the I don't know if this is the same scenario in which you first encountered this issue, but if it is, I suppose the real solution would be to prevent sending the What do you think? |
@thiagopromano yes, mine is a similar situation. Please refer to this repo for more information. The issue is two fold. You need to make proper use of That's the crux of the issue. Not sending the event if the component is no longer in the DOM would probably be a good thing to do, but you still need to reference the DOM element by id. I encourage you to study that repo. |
I merged @atcherry MR (thanks again!) and released a new version as his changes are fixing the problem. Making form recovery work in the context of a popup that has disappeared from the DOM seems out of the scope of this issue. |
LiveSelect and LiveView versions
have you tried LiveSelect's and LiveView's latest versions? Please try them and see if the bug still occur
which LiveSelect version are you on?
1.5.2
which LiveView version are you on?
1.0.1
I'm happy to create a PR for this.
Describe the bug
The
selection_recovery
event gets submitted to a parent LiveView instead of the LiveSelect LiveComponent for live selects wrapped in LiveView'sinputs_for
component.Expected behavior
The
LiveSelect
hook'sreconnected
callback pushes theselection_recover
event to the live select LiveComponent.Actual behavior
The
LiveSelect
hook'sreconnected
callback pushes theselection_recovery
event to the parent live view.Screenshots
If applicable (in most cases it is), do add a screenshot (or even better, a GIF or a video) that describes the problem.
Browsers
Firefox
Issue Repo
The following repo demonstrates the issue.
https://github.com/atcherry/live_select_example
Additional context
When the
reconnected
callback for the LiveSelect hook gets called, somehow the element that is being referred to in thepushEventTo
call lacks DOM information on where the live component is. This can be traced to theowner
call in the Phoenix JS code forlive_socket
which makes a call toel.closest(...)
.el.closest(...)
returns null.I believe a simple but effective fix would be to call
pushEventTo(this.el.id, ...)
instead ofpushEventTo(this.el, ...)
. I think I tested this and it worked, but I can make sure that is the case.The text was updated successfully, but these errors were encountered: