By using
assign_new
in the mount callback of your LiveView, you can instruct LiveView to re-use any assigns set in your Plug pipelines as part ofPlug.Conn
, avoiding sending additional queries to the database. Imagine you have a Plug that does:
it’s not clear anymore when does this happen.
for my case the reason of error is now clear,
for pull page reload:
on first render :current_user comes from Plug and so the components in the page gives an error, this if finally not
because assign_new is not triggered, because assign_new is triggered on second render
on second render, assign_new is triggered, since without the component the page shows current_user with preload (and with the component there is no second render because of error in first render).
so current_user is not shared between conn and socket, it’s just a bug in first render
for live_redirect, :current_user with preload is already there, so no problem with the component
so what does it mean that data is shared with conn ? it looks like there is no implicit share, and one has to resource for instance to session to pass variables