James_E

James_E

Whenever there’s a connection error on LiveView, the current version of phx.new sticks a completely fake progress bar at the top of the screen, which fills at the hardcoded rate of 5% of the remaining distance to 95%, each frame, without regard to any actual reconnection progress or post-reconnection sync progress.

I’d like to replace this with a less misleading disconnection indicator, such as an indeterminate progress bar. But I’d also like to (in the event that the latter takes more than 1 frame) switch over to showing a “real” progress bar showing the approximate completion of the actual post-reconnection sync.

So: does Phoenix have any hooks to tell the difference between these? I tried to find it myself, but I couldn’t spot where the existing “page-loading” hooks are coded, so I wasn’t immediately able to just look around at the neighboring code to check.

(I’m not asking about how to program the replacement topbar drawing code as that’s going to be a pretty simple exercise and is entirely out-of-scope of Elixir/Phoenix anyway; I’m only asking how I would hook into LiveView to know when to run which version of the drawing code.)

Showing Posts 1 to 3

Hermanverschooten

Hermanverschooten

a grep shows them in phoenix_live_view/assets/js/phoenix_live_view/live_socket.js around line 763.

gushonorato

gushonorato

Have you tried to implement a disconnection feedback using lifecycle events?

<div id="status" class="hidden" phx-disconnected={JS.show()} phx-connected={JS.hide()}>
  Attempting to reconnect...
</div>

You can find more information here: Bindings — Phoenix LiveView v1.2.5*

James_E

James_E OP

oh, wow, guess I was looking in the entirely wrong source tree. Thanks for the pointer.

Though it looks like that file just contains a wrapper function… a bit more digging didn’t reveal any obvious hooks into the larger state.

I see, thank you! :eyes: I didn’t realize Phoenix really does have a separate set of events for that.

I’m still not sure how to quantify a LiveView resync (for example, is there any interface to check the size of the socket’s queue during reconnect), but this at least allows my app to react differently to a mere loading event that happens to be taking a while vs. a clear disconnect from the LiveView.

/* app.js */
{
  // Show progress bar on live navigation and form submits
  // https://forum.elixirforum.com/t/phx-error-topbar-canvas-tell-the-difference-between-loading-and-connecting/67898?u=james_e
  topbar.config({
    barColors: {0: "#29d", "0.5": "orange", "1.0": "#29d"},
    shadowColor: "rgba(0, 0, 0, .3)",
    autoRun: "indeterminate" // https://github.com/buunguyen/topbar/issues/21
  })
  let is_loading = false, is_connected = true;
  window.addEventListener("phx:page-loading-start", _info => {
    is_loading = true;
    topbar.show(300); // TODO make this actually show reconnection, resync, or loading progress
  })
  window.addEventListener("phx:page-loading-stop", _info => {
    is_loading = false;
    if (is_connected)
      topbar.hide()
  })
  window.addEventListener("phx:x-liveview-disconnected", _info => {
    is_connected = false;
    topbar.show()
  })
  window.addEventListener("phx:x-liveview-connected", _info => {
    is_connected = true;
    if (!is_loading)
      topbar.hide();
  })
}
<%!-- home.html.heex -->
<main
  phx-disconnected={JS.dispatch("phx:x-liveview-disconnected")}
  phx-connected={JS.dispatch("phx:x-liveview-connected")}
>
  …
</main>
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews