-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Environment
- Elixir version (elixir -v): 1.18.4
- Phoenix version (mix deps): 1.17.21
- Phoenix LiveView version (mix deps): 1.0.11
- Operating system: MacOS 15.6.1
- Browsers you attempted to reproduce this bug on (the more the merrier): Brave
- Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes
Actual behavior
In my ConnCase
, I'm using Phoenix.LiveViewTest.put_connect_params/2
to set a value similar to what my app.js
does when running my full application. I then attempt to use Phoenix.LiveView.get_connect_params/1
to read that value in an on_mount
hook that is used by most of my LiveViews.
This works fine for the first LiveView I visit in my test. However, if I think perform an action that navigates (usually live navigation, but not always) to another LiveView, my connect_params
are no longer present.
When I run the application in the browser, everything works fine. It's just during the tests that it's a problem.
Expected behavior
I expect that my tests will work the same way as the real application does in the browser, where the connect_params are available to all of the LiveViews I visit during the test.
Notes
I've done some digging here, and the root cause is that Phoenix.ConnTest.recycle/1
(or Phoenix.ConnTest.ensure_recycled/1
) is called from several places during the navigation, and that function doesn't preserve the conn.private[:live_view_connect_params]
(or anything else in conn.private
for that matter.
I'm not sure of the correct fix here. Phoenix shouldn't really know about a :private
being set by LiveView, and it probably shouldn't blindly preserve everything in conn.private
when recycling.
It might be possible to add a LiveView-specific version of recycle
that preserves the connect params across a call to the original recycle
. That would likely require other libraries to be updated. For example, PhoenixTest also calls the original version of recycle
, so it wouldn't use the LiveView-specific version of recycle
without an update.