ux: [Live component] Invalid cheksum exception with own hydrating methods after upgrade from 2.10 to 2.11

I have got a Live Component which contains a LiveProp defined as array of DTO with custom hydrateWith and dehydrateWith methods.

/** @var CourseMeetingResponse[] $courseMeetings */
#[LiveProp(writable: true, hydrateWith: 'hydrateCourseMeetings', dehydrateWith: 'dehydrateCourseMeetings')]

In 2.10.* everything works fine, but after upgrading to 2.11* or 2.12.* or 2.13.* I started to receive a Hydration exception Invalid checksum sent when updating the live component.

I saw that in 2.11 you have changed the checksum calculation. However before it works fine for me and now the new calculation causes exception. I didn’t find any BC in changelog or any information about action which is required after upgrading to newer versions.

What should be done to avoid such behaviour?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

I fixed the problem by not storing entities in the live component, but only their ids (then retrieving the corresponding entities with their repositories).

I went from this :

public function dehydrate(MyObject $object): array
{
    return [
        'related' => $myObject->getRelated()
   ];
}

public function hydrate(array $data): MyObject
{
    $object = new MyObject();

    $object->setRelated($data['related']);

    return $object;
}

To this :

public function dehydrate(MyObject $object): array
{
    return [
        'related' => $myObject->getRelated()->getId()
   ];
}

public function hydrate(array $data): MyObject
{
    $object = new MyObject();

    $related = $this->relatedRepository->find($data['related']);

    $object->setRelated($related);

    return $object;
}

Hopefully this example can help anyone having the same issue in the future.

Just a inch with no certitude at all: could you try without the field “realizationDate” ?

@smnandre You were right. It seems that this field causes problem since 2.11. When I removed it from my component, checksum exception disappeared. I will dig into it.