Skip to content

Commit 2f0af8d

Browse files
committed
[Live] Fix checksum calculation for deeply nested data
1 parent 2e2b82d commit 2f0af8d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/LiveComponent/src/LiveComponentHydrator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private static function coerceStringValue(string $value, string $type, bool $all
244244
private function calculateChecksum(array $dehydratedPropsData): ?string
245245
{
246246
// sort so it is always consistent (frontend could have re-ordered data)
247-
ksort($dehydratedPropsData);
247+
$this->recursiveKeySort($dehydratedPropsData);
248248

249249
return base64_encode(hash_hmac('sha256', json_encode($dehydratedPropsData), $this->secret, true));
250250
}
@@ -550,4 +550,14 @@ private function combineAndValidateProps(array $props, array $updatedPropsFromPa
550550

551551
return $dehydratedOriginalProps;
552552
}
553+
554+
private function recursiveKeySort(array &$data): void
555+
{
556+
foreach ($data as &$value ) {
557+
if (is_array($value)) {
558+
$this->recursiveKeySort($value);
559+
}
560+
}
561+
ksort($data);
562+
}
553563
}

0 commit comments

Comments
 (0)