#Date serialization bug?

36 messages · Page 1 of 1 (latest)

brazen spindle
#

Hoping another set of eyes can take a look at this for me. The issue is present in v0.17.5/0.1.0, but was also around before then. I think something isn't working right, but it's always possible I'm doing something wrong. In the attached blitz the issue occurs when I try to create some derived state by filtering the original store object with a Date type.

https://stackblitz.com/edit/qwik-starter-ugs6ea?file=src/routes/index.tsx

StackBlitz

json-server simple starter

ember oar
#

as far as I know qwik can't serialize dates. i use getTime() to pass them to timestamps (number)

#

JSON can't serialize some object types. For example, DOM references, Dates, etc...

#

there it is

brazen spindle
#

Keep reading and that same page will contradict itself

Here is a list of types that can be serialized with Qwik:
* DOM references
* Promises (See resources)
* Function closures (if wrapped in QRL)
* Dates
#

And the loader$ serializes it just fine.

ember oar
#

oh nvm, i was reading what json can't do, but qwik can

#

it is indeed broken because i've been using timestamps because of that

brazen spindle
#

Ah, that got me too.

ember oar
#

maybe submit an issue?

brazen spindle
#

Yeah, I know it used to not working in some places because I opened a bug and @primal steeple closed it as resolved and said it was fixed.

primal steeple
#

Date serialization works

#

it should work

#

how is it failing?

ember oar
#

because i had to create this just to avoid issues:

export function serializeMetadata(metadata) {
  return {
    ...metadata,
    createdAt: metadata.createdAt.getTime(),
    updatedAt: metadata.updatedAt.getTime(),
    publishedAt: metadata.publishedAt.getTime(),
  }
}

export function deserializeMetadata(metadata) {
  return {
    ...metadata,
    createdAt: new Date(metadata.createdAt),
    updatedAt: new Date(metadata.updatedAt),
    publishedAt: new Date(metadata.publishedAt),
  }
}
#

looks like now it works. @primal steeple can you please confirm that it was broken but was fixed recently?

#

or am i going crazy 😂

primal steeple
#

you mean in the loader$()

#

yes, it was fixed!

brazen spindle
#

@primal steeple It's failing inside a useTask$. It says Target must be a serializable object. If you run the stackblitz it will error immediately. The issue seems to be with the filtering of a date in the useTask$.

#

I know you fixed in the loader, that seems to be fine. I'm trying to use useTask$ to calculate some derived state and that is where it's balking on the Date.

#

I'm happy to submit an issue. Just posted here to make sure I wasn't simply doing something "wrong".

primal steeple
#

if you can provide a simple repo case using latest qwik please!!

#

i am curious how you getting this issue though!

brazen spindle
#

Everything you need to see is right in that index.tsx file.

primal steeple
#

The bug is in {deep: true}

#

we can watch inside a Date, but yep, this is a bug

#

can you open a issue? i will try to fix asap

#

can not

brazen spindle
primal steeple
#

cool! expect it fixed tomorrow 😉

brazen spindle
#

Thank you for your continued efforts, you and the team are amazing!