nicky

nicky

layout updating when using push_navigate

The application I’m developing has a background gradient that I noticed flashing between liveviews so I inspected the dom and was surprised to see the layout re-rendered w/ each transition to a new liveview. I’m specifying the :layout and I’ve got a live_session wrapping the liveviews in the router and I’m using push_navigate to navigate between liveview. In the documentation it says live sessions keep the same layout, which it is, but I thought that would mean the layout elements was tracked and not re-rendered without changes to their props. Or am I doing something wrong?

Liveview:

  @impl true
  def handle_event("continue", _, socket) do
    {:noreply, push_navigate(socket, to: ~p"/provider/enter-mrn")}
  end

Router:

  scope "/provider", ProviderWeb do
    pipe_through([:browser])

    live_session :provider,
      layout: {ProviderWeb.Layouts, :provider},
      on_mount: [{ProviderWeb.ProviderHooks, :version}] do
      live("/welcome", WelcomeLive, :index)
      live("/enter-mrn", MRNLive, :index)
      live("/enter-dob", DOBLive, :index)
      live("/orders", OrdersLive, :index)
    end
  end

layout:

<link phx-track-static rel="stylesheet" href={~p"/assets/provider"} />

<ProviderWeb.CoreComponents.header />

<main class="provider">
  <%= @inner_content %>
</main>

<footer class="provider">
  <p>
    version: <%= @version %>
  </p>
</footer>

Most Liked

sodapopcan

sodapopcan

Hello and welcome!

Is says the root layout (:root_layout vs :layout) is not updated between redirects (if they share one), everything else is. This is the static layout generally shared between live views and dead views alike and is not change tracked—it’s generally rendered once can have its title updated through the special assign :live_title.

codeanpeace

codeanpeace

Have you tried creating a separate root layout specific to that live session? You should be able to do something like this:

live_session :provider,
      root_layout: {ProviderWeb.Layouts, :provider_root},

If you wanted to keep a single root layout, you could move the shared unchanging parts of the :layout into the :root_layout and put it behind a check based on the live_session by checking an assign set on mount or on_mount for the name of the live_session, which should be available somewhere in the session callback parameter.

nicky

nicky

thanks for the suggestion! the css attached to the layout was causing the issue so I created a plug that holds a list of css & js files that I loop through in the root layout. I’ll take your suggestion though and move the other common parts in the root layout behind a check.

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

We're in Beta

About us Mission Statement