-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
[LiveComponent] Fix issue with onUpdated not triggered on nested array proprety #2013
base: 2.x
Are you sure you want to change the base?
Changes from all commits
0b0e7bb
b968810
0ea98bc
6c46e0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -686,13 +686,13 @@ private function processOnUpdatedHook(object $component, string $frontendName, L | |
} | ||
|
||
$key = \sprintf('%s.%s', $frontendName, $propName); | ||
if (!$dehydratedUpdatedProps->hasPropValue($key)) { | ||
continue; | ||
} | ||
$fullPaths = $dehydratedUpdatedProps->searchFullPathsForProperty($key); | ||
|
||
$this->ensureOnUpdatedMethodExists($component, $funcName); | ||
$propertyOldValue = $dehydratedOriginalProps->getPropValue($key); | ||
$component->{$funcName}($propertyOldValue); | ||
foreach ($fullPaths as $fullPath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop concern one callback for a prop. It should not be called multiple times. I this you could "just" replace the prevous "hasPropValue" to some "matchPropValue" or something like this and let the rest flow. |
||
$this->ensureOnUpdatedMethodExists($component, $funcName); | ||
$propertyOldValue = $dehydratedOriginalProps->getPropValue($fullPath); | ||
Comment on lines
+692
to
+693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not compute this every loop |
||
$component->{$funcName}($propertyOldValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the receiving callable as no way to get what is "old value". If a "*" is used, we should pass the full prop |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,13 @@ public function getNestedPathsForProperty(string $prop): array | |
return $nestedPaths; | ||
} | ||
|
||
public function searchFullPathsForProperty(string $prop): array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some tests if possible (with failing / problematic cases, not just happy path) |
||
{ | ||
$regex = '/^'.preg_replace(['/\\\\\*$/i', '/\\\\\*/i'], ['', '.*?'], preg_quote($prop, '/')).'/i'; | ||
|
||
return preg_grep($regex, array_keys($this->propValues)); | ||
} | ||
|
||
public function calculateUnexpectedNestedPathsForProperty(string $prop, array $expectedNestedPaths): array | ||
{ | ||
$clone = clone $this; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this only under conditions, and keep previous code if no "*"