JohnnyCurran

JohnnyCurran

TimeTravel - A Record/Replay debugger for LiveView

TimeTravel is an Elixir library (& browser extension) that allows one to record and replay the interactions in a LiveView application - enabling easy debugging of the LiveView socket state

:movie_camera: A video demonstration is available on GitHub :movie_camera:

What’s the problem?

When developing, your LiveView might not behave how you expect it to. If you’re anything like me, this means you drop several IO.inspect or dbg calls in your LiveView and scroll through terminal output to see the state of the assigns as they change through the life of your LiveView. But there’s a better way!

TimeTravel enables easier debugging of a LiveView because all assigns are visible in the viewing pane and one can replay interactions to see how assigns change over time - if you put an IO.inspect in the wrong event handler, no problem!

It also allows one to rewind the LiveView to a specific point-in-time and replay different interactions from a known good state. This is helpful if you are designing, for example, an online checkout page and need to test several different failure modes without replaying the entire interaction on each page refresh.

TimeTravel was inspired by Elm Reactor, rr-project, and Vue Devtools - The post on Elm Reactor is where I borrowed the online checkout page example from :slight_smile:

How does it work?

TimeTravel attaches to the telemetry events emitted by Phoenix LiveView and stores the socket state at the time of each event. The browser extension allows one to move the slider back and forth to inspect the socket state at the time of each event.

Demo, Usage, and Video

The TimeTravel Demo application is available on GitHub

If you don’t want to clone and run the demo application :movie_camera: a video demonstration is available on GitHub :movie_camera:

In the video, as items are added and removed from the list, the socket state inspector in the DevTools pane updates the items assign that’s easily visible. As the event slider is dragged back and forth, the socket assigns (& DevTools pane) are set to the values they held when that event was fired.

If you would like to try TimeTravel in your own LiveView application, follow the installation instructions on GitHub. Please report any issues running the application here

TimeTravel is, at this stage, more of a proof-of-concept than a fully functioning library and has all sorts of issues, bugs to iron out, and tests to write. Below is a list of known issues:

Known Issues

  • No graceful restore if LiveView crashes
    • If your LiveView crashes and re-mounts the event slider will only work for events that were fired after the remount. This is generally considered undesirable behavior for a debugger and will be addressed in the future
  • Chrome extension manifest is V2
    • Because the extension has a V2 manifest, it is unable to be distributed in the Chrome Web Store. If you have advice on how best to turn a V2 manifest into a V3 manifest, please let me know. Pull Requests are, of course, always welcome :slight_smile:
  • LiveComponent telemetry not supported
    • This is possible, I just haven’t yet implemented it
  • LiveView does not have a handle_info telemetry attachment
    • This is by design and I’ll need to think on how best to instrument handle_info for LiveViews
  • Must subscribe to PubSub in mount/3 callback to receive events
  • handle_info callbacks must be copied/pasted into LiveViews to debug them
    • This, like the PubSub issue, is really annoying. If there is a way to inject the handle_info callbacks into each LiveView, I’m all ears. For PubSub, I can probably cast to each GenServer that has a LiveView pid
  • Memory usage is high
    • Storing the socket state for every event gets large. As of now there is no code that deletes socket state (but socket state is only stored if the DevTools pane is open). Restart the server or run GenServer.cast(TimeTravel.Jumper, :reset) from IEx
    • Similarly for the browser extension, the chrome.runtime.storage API will hit its limit of 5MB fairly regularly. Use the “Clear Storage” button in the DevTools pane if you begin to see console errors.
  • Flash assigns are not supported at this time
    • Flash is a special assign and will need more work to support correctly

Other minutiae

My ideal implementation of this would store a diff snapshot every time the /live socket receives an update. This would allow for any kind of update from LiveView → DOM to be inspected regardless of whether or not it’s supported by Telemetry. I attempted to go down this road for about seven minutes before I decided I don’t want to go spelunking in the LiveView internals

Links 'n More

Thank you for reading :slight_smile:

Most Liked

JohnnyCurran

JohnnyCurran

TimeTravel now supports LiveComponents!

TimeTravel v0.3.2 is now available!

Extension v0.0.0.3 has been released

Changes include:

  • Preliminary support for LiveComponents
  • Now shows event arguments in the Extension pane
  • Library installation is much simpler & requires fewer changes to your code

The chrome extension is still under review but should hopefully be published “soon” - It can still be installed as an “unpacked” extension. See the README for more details

On the roadmap:

  • Show all LiveView and LiveComponent states on every event
  • Improved assigns viewer in the Chrome Extension (Collapsible key/value pairs for larger assigns maps)
  • Support handle_info callbacks on LiveViews
  • Automatically wire up Telemetry events

No good release announcement is complete without a new demo video, available at the link below:

derpycoder

derpycoder

People, why is there just 1 star on that repo.

It deserves more love. I like that redux like capability. :upside_down_face:

code-shoily

code-shoily

Looks great. It’s about time we get to have one of those.

caciatori

caciatori

That’s amazing!

Congrats for the project, I’ll start using it soon!

JohnnyCurran

JohnnyCurran

People, why is there just 1 star on that repo.

Well, the repo has only been public for about an hour so I’ll take that star :slight_smile:

Where Next?

Popular in Libraries Top

Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
New
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
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Sub Categories:

We're in Beta

About us Mission Statement