Skip to content

fix(persist): delete IndexedDB keys for symbolDelete - #663

Open
Steve0x2a wants to merge 1 commit into
LegendApp:mainfrom
Steve0x2a:fix/indexeddb-symbol-delete
Open

fix(persist): delete IndexedDB keys for symbolDelete#663
Steve0x2a wants to merge 1 commit into
LegendApp:mainfrom
Steve0x2a:fix/indexeddb-symbol-delete

Conversation

@Steve0x2a

Copy link
Copy Markdown

When a persist change uses Legend-State's existing symbolDelete sentinel, the IndexedDB plugin treated it as a stored value and called IDBObjectStore.put(). IndexedDB uses the structured clone algorithm, which cannot clone Symbol, so every persisted deletion crashed:

DataCloneError: Failed to execute 'put' on 'IDBObjectStore': Symbol(delete) could not be cloned.

_setItem already deletes on falsy values. symbolDelete is truthy, so it fell through to put. This also hits the full-table path because _setTable delegates each entry to _setItem.

The plugin now treats symbolDelete like the existing delete path and calls store.delete(key) instead of putting the Symbol. No new delete protocol.

Credits @LinusOssmann for the report and repro.

Fixes #658

Signed-off-by: Yi Zhan <stevesough@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexedDB persistence crashes with DataCloneError when persisting a deleted (symbolDelete) value

1 participant