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:

https://github.com/JohnnyCurran/TimeTravel#demo

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.

Where Next?

Popular in Announcing Top

tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
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

Latest on Elixir Forum

We're in Beta

About us Mission Statement