Reviving interlinked custom types produces wrong result
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.8k
- Forks
- 99
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 17
Description
Problem
Reviving interlinked custom types, e.g. doubly linked list of custom objects, causes some fields to be undefined.
Example
The following happens:
during hydrating a: a's data refers to b, so b gets parsed:
during hydrating b: b's data refers to a, but a's data is marked as hydrated (even though it is unfinished yet), and the custom reviver is called with incomplete data.
Such cases cannot be revived via only a "constructor", for the same reason the doubly linked list cannot be created declaratively only (without assignments).
Workaround
This can be fixed by deferring "linking objects" to be done after parsing finishing.
But then another problem became clear: interlinks cause extra calls of revivers that break object identities, and the output is still not really correct. This can be fixed by introducing a cache of revived objects.
Thus, the workaround gets complicated.
Workaround example
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Start by reproducing the interlinked custom-type case in the linked Svelte playground and trace hydration of a and b. Compare it with the linked workaround, focusing on deferred linking and revived-object caching; done means interlinked objects retain their fields and object identities without extra broken reviver calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100