devalue icon indicating copy to clipboard operation
devalue copied to clipboard

Reviving interlinked custom types produces wrong result

Open 7nik opened this issue 5 months ago • 0 comments

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

7nik avatar Sep 03 '25 10:09 7nik