jquery.terminal icon indicating copy to clipboard operation
jquery.terminal copied to clipboard

Wrong history when using hot reload

Open jcubic opened this issue 1 year ago • 2 comments
trafficstars

Issue summary

Each time when hot reload, update the page that have the terminal new history is created.

Expected behavior

When a terminal is destroyed and created again, it should create the exact same terminal with the same history.

Steps to reproduce

  1. Clone repo https://github.com/jcubic/jquery.terminal-docs
  2. run in terminal cd docs && npm install && npm start
  3. When browser open up type few commands
  4. Modify something in the source code
  5. Press up arrow
  6. No history

Browser and OS

N/A

Additional notes

The terminal_id needs to be updated when a terminal is destroyed.

jcubic avatar Oct 22 '24 14:10 jcubic

The problem is with Cycle::length, it returned array length and not how many items were in the array, removing the item is using delete data[index]. So after each hot reload, the terminal_id is the next value.

Changing the behavior of Cycle breaks half of unit tests.

jcubic avatar Oct 22 '24 20:10 jcubic

This is only required by hot reload, so the fix was to add id option that replace old terminal with the same data in Cycle data structure.

With a single terminal on the page, you can use:

$('...').terminal(commands, {
   id: 0
});

And history will be preserved between reloads.

jcubic avatar Oct 26 '24 19:10 jcubic