Skip to content

Commit

Permalink
Deep rebind attribute callbacks after clone
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Feb 10, 2023
1 parent b337212 commit cee10c9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/BaseHtmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ public function renderUnwrapped()

public function __clone()
{
$copy = $this->copy();
if ($copy !== null) {
$copy->then(function (SplObjectStorage $copies): void {
foreach ($copies as $ignored) {
// SplObjectMap always iterates over the attached objects that
// are the elements before they have been cloned.
// But we want to work with the cloned element.
$copy = $copies->getInfo();
if ($copy instanceof self) {
$copy->getAttributes()->rebindAttributeCallbacks($this->objectId(), $this);
}
}
});
}

parent::__clone();

if ($this->attributes !== null) {
Expand Down

0 comments on commit cee10c9

Please sign in to comment.