-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Live component] Invalid cheksum exception with own hydrating methods after upgrade from 2.10 to 2.11 #2000
Comments
It's a bit old for me to remember but one thing that could be related is we removed the hard dependency on symfony/serializer ... it is possible you don't have it anymore and this prevent something during hydration ? |
Could you give us a (simplified) set of data to understand the duffzrence for you ? And see if and how we can find a fix ? |
First array is sorted by Below is a {"props":{"title":"Dostępne terminy","courseMeetings":[{"id":7199,"variantCode":"symbol_243188","realizationDate":{"date":"2024-05-10 10:00:00.000000","timezone_type":3,"timezone":"UTC"},"placeName":"szkolenie online","earlyClubMembershipPrice":85000,"clubMembershipPrice":90000,"earlyNonClubMembershipPrice":90000,"nonClubMembershipPrice":100000,"consultantId":1388},{"id":7200,"variantCode":"symbol_243195","realizationDate":{"date":"2024-05-19 00:00:00.000000","timezone_type":3,"timezone":"UTC"},"placeName":"szkolenie online","earlyClubMembershipPrice":85000,"clubMembershipPrice":90000,"earlyNonClubMembershipPrice":90000,"nonClubMembershipPrice":100000,"consultantId":1388},{"id":7201,"variantCode":"symbol_243196","realizationDate":{"date":"2024-05-22 12:00:00.000000","timezone_type":3,"timezone":"UTC"},"placeName":"Gdańsk","earlyClubMembershipPrice":85000,"clubMembershipPrice":90000,"earlyNonClubMembershipPrice":90000,"nonClubMembershipPrice":100000,"consultantId":1350},{"id":7202,"variantCode":"symbol_243197","realizationDate":{"date":"2024-05-29 17:20:00.000000","timezone_type":3,"timezone":"UTC"},"placeName":"Sopot","earlyClubMembershipPrice":85000,"clubMembershipPrice":90000,"earlyNonClubMembershipPrice":90000,"nonClubMembershipPrice":100000,"consultantId":1388},{"id":7203,"variantCode":"symbol_243206","realizationDate":{"date":"2024-06-05 12:00:00.000000","timezone_type":3,"timezone":"UTC"},"placeName":"szkolenie online","earlyClubMembershipPrice":85000,"clubMembershipPrice":90000,"earlyNonClubMembershipPrice":90000,"nonClubMembershipPrice":100000,"consultantId":1412}],"itemsErrors":[],"formName":"add_to_cart","add_to_cart":{"courseMeeting":"symbol_243188","addToCartSubmit":null},"isValidated":false,"validatedFields":[],"@attributes":{"data-live-id":"live-962431554-0"},"@checksum":"Xo5RMRMvZz4DMff3vSPadkxqC32GnD5nDTStuTVSiGg="},"updated":{"add_to_cart.courseMeeting":"symbol_243206","validatedFields":["add_to_cart.courseMeeting"]}} As you can see the |
That should not have impact, as POST data is also recursively sorted before we compute and compare checksum. Just a inch with no certitude at all: could you try without the field "realizationDate" ? |
Hey @sabat24! Could you create a basic reproducer? So we can look at your issue, I didn't manage to reproduce it locally. Thanks for the report! |
@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. |
Ok good to know and tell us if you cannot sort this out. by curiosity what was the différence between both array representations ? |
In 2.11 when component was mounted and Then after In 2.10 when component was mounted the behaviour was same as above. But when live action was triggered the On the first call from Regardless of that second call, using @WebMamba I can try to create a reproducer in a few days. |
I created repo to reproduce the issue -> https://github.com/sabat24/symfony-ux-2000 After installing just go to home page and select radio button. |
Some things, not sure if one particular solves all $courseMeetings = [];
foreach ($data as $courseMeeting) {
/** @var array{id: int, variantCode: string, realizationDate: array{date: string}, placeName: string, earlyClubMembershipPrice: string|null, clubMembershipPrice: string|null, earlyNonClubMembershipPrice: string|null, nonClubMembershipPrice: string|null, consultantId: int|null} $courseMeetingArray */
$courseMeetingArray = (array) $courseMeeting;
$courseMeetings[] = $courseMeetingArray;
} This is false, (array) $courseMeeting does not transform realizationDate into an array, it's still a DateTime (you can dd($courseMeetingArray) to check) -- Your mock data uses strings for date, not your hydrate/dehydrate methods after that
-- I updated twig & live packages (in 2.18) and installed Serializer (not required since 2.something) .. Then i removed your hydrate/dehydrate and things seems to "work". Maybe start doing the same and see where it goes for you ? |
I think that I know where the "problem" was. In short in my dehydration method as you mentioned.
Here the checksum exception is raised.
If i modify my dehydration method to $courseMeetings = [];
foreach ($data as $courseMeeting) {
/** @var array{id: int, variantCode: string, realizationDate: array{date: string}, placeName: string, earlyClubMembershipPrice: string|null, clubMembershipPrice: string|null, earlyNonClubMembershipPrice: string|null, nonClubMembershipPrice: string|null, consultantId: int|null} $courseMeetingArray */
$courseMeetingArray = (array) $courseMeeting;
$courseMeetingArray['realizationDate'] = (array) $courseMeetingArray['realizationDate']; // <-- added
$courseMeetings[] = $courseMeetingArray;
} everything works fine. I was sure that LiveComponent calculates checksum based on props from point 4 and not from point 3. |
Really happy for you! 😃 |
I'm running into the same error after implementing my own hydration / dehydration logic, and it's not entirely clear what I'm doing wrong / how it should be fixed (and the docs don't mention anything about checksums) |
Could you open a support question, and ideally provide some code to better understand what is happeing ? |
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. |
I have got a Live Component which contains a LiveProp defined as array of DTO with custom
hydrateWith
anddehydrateWith
methods.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?
The text was updated successfully, but these errors were encountered: