Skip to content

Commit 9b60243

Browse files
committed
1 parent 696f448 commit 9b60243

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/PHPHtmlParser/Dom/HtmlNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ protected function clear(): void
186186
$this->innerHtml = null;
187187
$this->outerHtml = null;
188188
$this->text = null;
189+
$this->textWithChildren = null;
189190

190191
if (is_null($this->parent) === false) {
191192
$this->parent->clear();

src/PHPHtmlParser/Dom/InnerNode.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ public function insertAfter(AbstractNode $child, int $id): bool
203203
return $this->addChild($child, $this->children[$id]['next']);
204204
}
205205

206+
// clear cache
207+
$this->clear();
208+
206209
return $this->addChild($child);
207210
}
208211

@@ -344,6 +347,9 @@ public function replaceChild(int $childId, AbstractNode $newChild): void
344347

345348
// remove old child
346349
unset($this->children[$childId]);
350+
351+
// clean out cache
352+
$this->clear();
347353
}
348354

349355
/**
@@ -415,6 +421,9 @@ public function setParent(InnerNode $parent): AbstractNode
415421
throw new CircularException('Can not add descendant "'.$parent->id().'" as my parent.');
416422
}
417423

424+
// clear cache
425+
$this->clear();
426+
418427
return parent::setParent($parent);
419428
}
420429
}

0 commit comments

Comments
 (0)