Skip to content

metadata: fix DataCloneError when opening metadata dialog after filter click#705

Merged
ajslater merged 2 commits intov1.11-performancefrom
claude/unruffled-bohr-36fdab
May 3, 2026
Merged

metadata: fix DataCloneError when opening metadata dialog after filter click#705
ajslater merged 2 commits intov1.11-performancefrom
claude/unruffled-bohr-36fdab

Conversation

@ajslater
Copy link
Copy Markdown
Owner

@ajslater ajslater commented May 3, 2026

Summary

  • Removes the structuredClone call in getMetadata that was throwing DataCloneError: [object Array] could not be cloned when the metadata dialog opened after the user clicked a Genre / Author / etc. chip.
  • The clone was only there to allow delete data.mtime without mutating the caller's settings; replaced with a destructure that strips mtime cleanly.

Why

getMetadata is fed by useBrowserStore().metadataSettings, which reuses the inner state.settings.filters[k] arrays from the Pinia store. Those arrays are Vue reactive Proxies, and toRaw only unwraps one level — so the proxied arrays survived into structuredClone, which refuses to clone them.

The clone was also redundant: serializeParams (the only consumer of data here) already deep-clones via _deepClone, which recursively calls toRaw. So dropping the structured clone is both a fix and a small simplification.

Reproduces with the stack trace the user reported:

DataCloneError: Failed to execute 'structuredClone' on 'Window': [object Array] could not be cloned.
    at vf [as getMetadata]
    at Proxy.loadMetadata
    ...
    at Proxy.dialogOpened

Test plan

  • npx eslint src/api/v3/browser.js — clean
  • npx prettier --check src/api/v3/browser.js — clean
  • bun run test:ci — 1/1 passed
  • Manual: open the metadata dialog on a group, click a Genre chip, and confirm the dialog re-opens without a console error and tags load correctly.

🤖 Generated with Claude Code

ajslater and others added 2 commits May 2, 2026 17:24
The previous implementation cloned ``{ ...rawSettings, filters }`` via
``structuredClone`` purely so it could ``delete data.mtime`` without
mutating the caller's settings. But the filter payload comes straight
from the Pinia browser store, which keeps the inner ``filters[k]``
arrays as Vue reactive Proxies. ``toRaw`` only unwraps one level, so
those proxied arrays survived into ``structuredClone`` — which refuses
to clone certain Vue proxies, surfacing as
``DataCloneError: [object Array] could not be cloned`` whenever a user
clicked a Genre / Author / etc. chip in the metadata dialog.

The clone was redundant in any case: ``serializeParams`` (the only
consumer of ``data``) already deep-clones via ``_deepClone``, which
calls ``toRaw`` at every level. Replace the clone-then-delete dance
with a destructure that strips ``mtime`` cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The ``getMetadata`` ``DataCloneError`` fix landed earlier in this PR
applied to one site; the same anti-pattern lived in five other places.
Each one cloned a Vue reactive value (Pinia store row, breadcrumb,
route params) via ``structuredClone(toRaw(x))`` — the outer ``toRaw``
unwraps only one level, so a nested reactive Array proxy can still
trip ``DataCloneError: [object Array] could not be cloned``.

Two cleanup categories:

* **Destructure-and-drop** (breadcrumbs, reader close button) —
  the clone existed only to ``delete params.name``. Replaced with
  ``const { name: _name, ...params } = toRaw(crumb)``: no clone,
  no proxy hazard.
* **Genuine deep copy** (admin create/update dialog + its mixin) —
  promoted the existing private ``_deepClone`` in ``api/v3/common.js``
  to an exported ``deepClone``. It already does what these sites
  need: recursive ``toRaw`` at every level, no structuredClone
  fragility. Swapped four ``structuredClone(toRaw(x))`` calls for
  ``deepClone(x)``.

Also dropped one defensive clone entirely
(``reader-book-change-nav-button.vue``): vue-router snapshots
``params`` itself, so the outer clone was never load-bearing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ajslater ajslater merged commit bd1ef4d into v1.11-performance May 3, 2026
1 check failed
@ajslater ajslater deleted the claude/unruffled-bohr-36fdab branch May 4, 2026 02:46
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.

1 participant