You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browsers you attempted to reproduce this bug on (the more the merrier): Chrome, FF
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes
Actual behavior
When navigating from a sticky child live view, <.link> won't have its phx-click-loading cleared. This means that every link clicked in the sticky navigation child live view will have phx-click-loading classes, which fails my E2E tests that wait for the LV to sync.
Here is a (rather crappy) repro:
Application.put_env(:sample,Example.Endpoint,http: [ip: {127,0,0,1},port: 5001],server: true,live_view: [signing_salt: "aaaaaaaa"],secret_key_base: String.duplicate("a",64))Mix.install([{:plug_cowboy,"~> 2.5"},{:jason,"~> 1.0"},{:phoenix,"~> 1.7"},# please test your issue using the latest version of LV from GitHub!{:phoenix_live_view,github: "phoenixframework/phoenix_live_view",branch: "main",override: true}])defmoduleExample.ErrorViewdodefrender(template,_),do: Phoenix.Controller.status_message_from_template(template)enddefmoduleExample.NavdousePhoenix.LiveView,layout: {__MODULE__,:live_child}defmount(_,%{"current_url"=>url},socket)do{:ok,socket|>assign(:current_url,url)}enddefrender("live_child.html",assigns)do~H"""{@inner_content}"""enddefrender(assigns)do~H"""<nav><.linknavigate="/p/1"class={active(@current_url,"/p/1")}>Link 1</.link><.linknavigate="/p/2"class={active(@current_url,"/p/2")}>Link 2</.link><.linknavigate="/p/3"class={active(@current_url,"/p/3")}>Link 3</.link></nav>"""enddefpactive(current_url,url)doifcurrent_url==url,do: "active",else: nilendenddefmoduleExample.HomeLivedousePhoenix.LiveView,layout: {__MODULE__,:live}defhandle_params(params,url,socket)do{:noreply,assign(socket,:url,URI.parse(url).path)}enddefrender("live.html",assigns)do~H"""<scriptsrc="/assets/phoenix/phoenix.js"></script><scriptsrc="/assets/phoenix_live_view/phoenix_live_view.js"></script><script> window.addEventListener('phx:page-loading-stop', ({detail}) =>{if(detail.kind==='redirect'){//removecurrentactiveconstcurrentActiveItem=document.querySelector('nav .active')if(currentActiveItem){currentActiveItem.classList.remove('active')//currentActiveItem.classList.remove('phx-click-loading')}constnewActiveItem=document.querySelector( `nav[data-phx-link][href="${window.location.pathname + window.location.search}"]`)if(newActiveItem){newActiveItem.classList.add('active')//newActiveItem.classList.remove('phx-click-loading')}}}) let liveSocket = new window.LiveView.LiveSocket("/live", window.Phoenix.Socket) liveSocket.connect()</script><style> * {font-size: 1.1em} nav {margin-top: 1em} nav a {padding: 8px16px;border: 1pxsolidblack;text-decoration: none} nav a:visited {color: inherit} nav a.active {border: 3pxsolidgreen} nav a.phx-click-loading {animation: pulsate2s infinite} @keyframes pulsate {0%{background-color: white;}50%{background-color: red;}100%{background-color: white;}}</style><body><header>{live_render(@socket,Example.Nav,id: "app-nav",session: %{"current_url"=>@url},sticky: true)}</header><main>{@inner_content}</main></body>"""enddefrender(assigns)do~H"""<pstyle="margin-top: 2em; max-width: 55ch"> When clicking any of the above links in the sticky child LiveView, `phx-click-loading` is not cleared after navigation.</p>"""endenddefmoduleExample.PageLivedousePhoenix.LiveView,layout: {Example.HomeLive,:live}defmount(%{"id"=>id},_session,socket)do{:ok,assign(socket,:id,id)}enddefhandle_params(params,url,socket)do{:noreply,assign(socket,:url,URI.parse(url).path)}enddefrender(assigns)do~H"""<h1>Page {@id}</h1>"""endenddefmoduleExample.RouterdousePhoenix.RouterimportPhoenix.LiveView.Routerpipeline:browserdoplug(:accepts,["html"])endscope"/",Exampledopipe_through(:browser)live_session:defaultdolive("/",HomeLive,:index)live("/p/:id",PageLive,:show)endendenddefmoduleExample.EndpointdousePhoenix.Endpoint,otp_app: :samplesocket("/live",Phoenix.LiveView.Socket)plug(Plug.Static,from: {:phoenix,"priv/static"},at: "/assets/phoenix")plug(Plug.Static,from: {:phoenix_live_view,"priv/static"},at: "/assets/phoenix_live_view")plug(Example.Router)end{:ok,_}=Supervisor.start_link([Example.Endpoint],strategy: :one_for_one)Process.sleep(:infinity)
Expected behavior
Not sure what I expect really, I can solve it like the commented out JS line in the example repro above:
Environment
Actual behavior
When navigating from a sticky child live view,
<.link>
won't have itsphx-click-loading
cleared. This means that every link clicked in the sticky navigation child live view will havephx-click-loading
classes, which fails my E2E tests that wait for the LV to sync.Here is a (rather crappy) repro:
Expected behavior
Not sure what I expect really, I can solve it like the commented out JS line in the example repro above:
// currentActiveItem.classList.remove('phx-click-loading')
but @SteffenDE mentioned that it COULD be a bug so I created a repro, just in case :)
The text was updated successfully, but these errors were encountered: