Records containing non-serializable values (e.g. Temporal, Decimal) throw DataCloneError during updates
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start at CollectionOptions and the core Collection update path where structuredClone copies records. Review the linked working branch and its tests for the proposed behavior, then verify that the default preserves structuredClone behavior while a supplied clone function is used during updates.
Written by the indexing model from the issue text.
Description
Problem
structuredClone is used internally to copy records before updates, but it throws a DataCloneError for non-serializable values like class instances with function own-properties (e.g. Temporal.PlainDate, Decimal from decimal.js). There's currently no way to provide an alternative cloning strategy.
Proposal
Add an optional clone property to CollectionOptions that allows users to provide a custom clone function (e.g. cloneDeep from es-toolkit). It defaults to structuredClone to preserve existing behavior.
const collection = new Collection({
schema,
clone: cloneDeep, // just an example, cloneDeep maintains references of non-serializable types, custom strategy may be preferred
})
Notes
The persist and sync extensions rely on JSON.stringify and serializeRecord respectively, so records must still be serializable when using those extensions. The clone option only affects how records are copied during updates in the core collection.
Suggested Implementation
I have a working branch with tests if you'd like me to open a PR: https://github.com/danmcdaid/data/tree/feat/custom-clone-option
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 66
- Avg merge
- 3m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mswjs/data
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
-
potentially resolved
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Non-nullable self-referencing relationsPossibly taken @kettanaito claimed this 371 days ago. Open
Similar issues
-
nextjs-tracking
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
cloudflare/vinext#3887 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/rocketmq-dashboard#6331 ·
Maintainers usually reply within 5 days
-
bug cache clinical-safety P1-critical
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
juspay/blend-design-system#1788 ·
Maintainers usually reply within 1 day
-
[Analytics] Add Focus Time-Block Efficiency Ratio Calculator in src/lib/focus/efficiency-ratio.tsOpenanalytics beginner friendly community contributions-welcome enhancement good first issue hacktoberfest help wanted up-for-grabs
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day