Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong history when using hot reload #978

Open
jcubic opened this issue Oct 22, 2024 · 2 comments
Open

Wrong history when using hot reload #978

jcubic opened this issue Oct 22, 2024 · 2 comments
Labels
Bug resolved if issue is resolved, it will be open until merge with master

Comments

@jcubic
Copy link
Owner

jcubic commented Oct 22, 2024

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 jcubic added the Bug label Oct 22, 2024
@jcubic
Copy link
Owner Author

jcubic commented Oct 22, 2024

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 added a commit that referenced this issue Oct 26, 2024
This feature allow to create same terminal with hot reload
@jcubic
Copy link
Owner Author

jcubic commented Oct 26, 2024

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 jcubic added the resolved if issue is resolved, it will be open until merge with master label Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

1 participant