Skip to content

undo history grows forever, btoa() dies on unicode, localStorage silently loses your work #352

@avinxshKD

Description

@avinxshKD

So actionArr in 4-undo-redo.js never gets pruned. ever. every move, resize, edge add, it all piles up. no max length, no cleanup.

this gets worse because 5-load-save.js serializes the entire history on every autosave via saveLocalStorage(). that fires on basically every graph event (debounced 1s). the whole thing goes through btoa() per action entry - JSON.stringify - localStorage.

two problems with that:

btoa() can't handle unicode. name a node "测试" or stick an emoji in there and stringifyAction() blows up with InvalidCharacterError. autosave breaks mid-session, history gets corrupted silently.

static stringifyAction({ actionName, parameters }) {
    return { actionName, parameters: window.btoa(JSON.stringify(parameters)) };
}

second, localStorage has a ~5MB cap. work on a decently sized graph for a while and the quota fills up. local-storage-manager.js catches the error and toasts it, but the graph state is just... gone on reload. no fallback, no partial save, nothing.

and the hash chain in addAction() depends on every previous entry so you can't just naively truncate without breaking server sync.

repro: create a graph, add 50+ nodes, drag them around a lot, check localStorage size in devtools. or just name a node with kanji and watch the console.

Needs to, history cap with truncation logic, unicode-safe encoding (TextEncoder or just drop the btoa nonsense), quota handling that doesn't just shrug when it fails. touches 4-undo-redo.js, 5-load-save.js, local-storage-manager.js, 6-server.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions