JohnnyCurran

JohnnyCurran

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:

Showing Posts 1 to 9

code-shoily

code-shoily

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

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:

caciatori

caciatori

That’s amazing!

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

JohnnyCurran

JohnnyCurran OP

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:

JohnnyCurran

JohnnyCurran OP

Please let me know if you run into any crazy issues!

lleger

lleger

Awesome work! I had a thought to do something like this. Glad someone else did.

pedromtavares

pedromtavares

Cool stuff, great work John! :clap:

JohnnyCurran

JohnnyCurran OP

Thanks Pedro! Hope you’re doing well – Too bad about Brazil’s World Cup hopes :frowning:

JohnnyCurran

JohnnyCurran OP

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

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews