-
Notifications
You must be signed in to change notification settings - Fork 959
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
push_navigate
in handle_progress
callback of LiveView Upload causes Floki exception in Test
#3662
Comments
The same happens if you do a |
SteffenDE
added a commit
that referenced
this issue
Feb 13, 2025
Because the channel did not immediately stop when an upload progress handler redirected, the following could happen: 1. upload does a push_navigate 2. channel sends a :redirect message to the root_pid 3. render_upload tries to render the page Now it depended on your luck: 4. LiveViewTest render asks the ClientProxy for the new HTML 5. ClientProxy tries to ping the channel 6. ClientProxy succeeds in pinging and returns HTML 7. Tests fail, because they expected {:error, {:live_redirect, ...}} or 4. LiveViewTest render asks the ClientProxy for the new HTML 5. ClientProxy tries to ping the channel 6. ClientProxy exits, because ping crashes (channel already exited) or 4. LiveViewTest render akss the ClientProxy for the new HTML 5. ClientProxy already exited Fixes: #3662 I changed the code to immediately exit the channel when possible, therefore at least the ping should always fail. I don't fully understand the interactions at play here though and I don't really like the code.
SteffenDE
added a commit
that referenced
this issue
Feb 13, 2025
Because the channel did not immediately stop when an upload progress handler redirected, the following could happen: 1. upload does a push_navigate 2. channel sends a :redirect message to the root_pid 3. render_upload tries to render the page Now it depended on your luck: 4. LiveViewTest render asks the ClientProxy for the new HTML 5. ClientProxy tries to ping the channel 6. ClientProxy succeeds in pinging and returns HTML 7. Tests fail, because they expected {:error, {:live_redirect, ...}} or 4. LiveViewTest render asks the ClientProxy for the new HTML 5. ClientProxy tries to ping the channel 6. ClientProxy exits, because ping crashes (channel already exited) or 4. LiveViewTest render akss the ClientProxy for the new HTML 5. ClientProxy already exited Fixes: #3662 I changed the code to immediately exit the channel when possible, therefore at least the ping should always fail. I don't fully understand the interactions at play here though and I don't really like the code.
❤️💚💛💜💙❤️ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environment
Actual behavior
@SteffenDE This is a re-opening of this issue: #2047 (comment)
Here's a demo repo that replicates the bug: https://github.com/PJUllrich/phoenix-live-view-file-upload-test-bug
See this test: https://github.com/PJUllrich/phoenix-live-view-file-upload-test-bug/blob/main/test/demo_web/live/upload_live/show_test.exs
The bug does not always occur, because there's a race-condition between the LiveView shutting down (if you have a good way of catching this in the test and assert against it, i'd appreciate it by the way) and the re-rendering of the HTML. That's why I run the test 5 times, because then usually the bug occurs at least once.
In essence, if I mark a socket with
push_navigate/2
inside thehandle_progress
callback of a LiveView upload, I receive this Floki exception:Expected behavior
There's no Floki exception (and ideally I could assert against the live_redirect return of the LiveView in my test somehow like I can do with
render_submit/2
.The text was updated successfully, but these errors were encountered: