Why can't symbolic keys be stringified?
hrueger opened this issue · 1 comments
Hi,
I'm using SvelteKit together with Prisma with computed fields. Results cannot be stringified and sent to the client (in load
for example), because that throws this error:
Cannot stringify POJOs with symbolic keys
Interestingly, if I just comment out those checks here and here, it works just fine. Is there a reason for this check and some edge cases I haven't yet ran into?
Thanks in advance.
For anyone wanting to test, here's a patchfile for yarn patch
: devalue-npm-4.3.2-e483100d94.patch
Interestingly, if I just comment out those checks here and here, it works just fine. Is there a reason for this check and some edge cases I haven't yet ran into?
It "works" by silently ignoring any symbolic key.
devalue could serialize any well-know symbol (like Symbol.asyncIterator
) and any global symbol (like Symbol.for('something')
). It can't serialize any unique symbol (Symbol('something')
) because, by the nature of unique symbols, the deserialization would not match any unique symbol the receiver might be expecting.