Skip to content

Commit 4ccc086

Browse files
Don’t clone node in handleRawHtml()
I don’t know why the code cloned the node before modifying it – there’s no explanation of this in #2, and the rest of the code is happy to modify nodes directly. However, this causes attribute binding on nodes with v-html to have no effect – after handleRawHtml(), the original node is skipped for further processing (isRemovedFromTheDom() returns true), and even if it wasn’t, handling attributes on it wouldn’t have any effect on the node that’s actually in the DOM now. Given that removing the cloning doesn’t seem to break any tests, let’s just remove it and add a test for attribute binding in conjunction with v-html. Bug: T396633 Bug: T396634
1 parent 4d3000d commit 4ccc086

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Component.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,7 @@ private function handleRawHtml( DOMNode $node, array $data ) {
319319
$variableName = $node->getAttribute( 'v-html' );
320320
$node->removeAttribute( 'v-html' );
321321

322-
$newNode = $node->cloneNode( true );
323-
324-
$this->appendHTML( $newNode, $data[$variableName] );
325-
326-
$node->parentNode->replaceChild( $newNode, $node );
322+
$this->appendHTML( $node, $data[$variableName] );
327323
}
328324
}
329325

tests/php/TemplatingTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public function testTemplateWithVhtmlVariable_ReplacesVariableWithGivenValue() {
102102
$this->assertSame( '<div><div><p>some value</p></div></div>', $result );
103103
}
104104

105+
public function testTemplateWithVhtmlVariableAndAttributeBinding_ReplacesBoth(): void {
106+
$result = $this->createAndRender(
107+
'<div><div :data-a="a" v-html="html"></div></div>',
108+
[ 'a' => 'A', 'html' => '<p>HTML</p>' ]
109+
);
110+
111+
$this->assertSame( '<div><div data-a="A"><p>HTML</p></div></div>', $result );
112+
}
113+
105114
public function testTemplateWithVhtmlAndDiacritcsInValue_ReplacesVariableWithEncodedValue() {
106115
$result = $this->createAndRender(
107116
'<div><div v-html="value"></div></div>',

0 commit comments

Comments
 (0)