onlook icon indicating copy to clipboard operation
onlook copied to clipboard

[feat] Restore unmodified files exactly on cleanup

Open Kitenite opened this issue 11 months ago • 0 comments

Problem

Currently, we are transforming every jsx/tsx files with data-oid. While this helps with modifying the code exactly, it creates large commits that include irrelevant files.

Proposed solution

We should only track files that have been changed after the project is transformed. One way to do this is to create cache files and restore all the files that remain unchanged between the transform and cleaup. The algorithm should roughly be:

Start project

  1. Create a .onlook folder if it doesn't already exist
  2. Create cache files for each tsx/jsx files before they are transformed
  3. Transform file with oid
  4. Store a hash of each file's content
  5. Edit project as usual

Clean up

  1. Hash file content
  2. Check if hash is the same (file unchanged since transform) a. If hash is the same, restore cached file b. Else, clean up as usual

Some optimizations: In the cache folder root, store map of path to hash, something like this:

{
  "actual/file/path.tsx": {
    "hash": "sha123",
    "cache_path": "123.tsx"
  },
  ...
}

Kitenite avatar Apr 05 '25 19:04 Kitenite