The current MEX code running with php-vuejs-templating version 2.2.0-beta.4 (and possibly earlier versions) can encounter a DOMException from PHP:
DOMException: Not Found Error Backtrace: from /var/www/html/w/vendor/wmde/php-vuejs-templating/src/Component.php(143) #0 /var/www/html/w/vendor/wmde/php-vuejs-templating/src/Component.php(143): DOMElement->replaceWith() #1 /var/www/html/w/vendor/wmde/php-vuejs-templating/src/Component.php(58): WMDE\VueJsTemplating\Component->handleComponent() #2 /var/www/html/w/vendor/wmde/php-vuejs-templating/src/Component.php(63): WMDE\VueJsTemplating\Component->handleNode()
@hoo tracked the issue down to this php issue which was fixed in php 8.1.21.
While we wait for the PHP version in Mediawiki (and mwcli (T388411) and CI) to get upgraded, we need a workaround for our own code to avoid triggering the bug.
Replacing:
$node->replaceWith( $node->ownerDocument->importNode( $rendered, true ) );
in Component.php with:
$importNode = $node->ownerDocument->importNode( $rendered, true ); if ($node != $importNode) { $node->replaceWith( $importNode ); }
avoids the DOMException, but also seems to fail to substitute the template data leading to invalid template renderings:
<div class="wikibase-mex-statement-heading">
<div class="wikibase-mex-statement-heading-row">
<mex-property-name :property-id="statement.mainsnak.property"></mex-property-name><div class="wikibase-mex-edit-link">
<span class="wikibase-mex-icon-edit-small"></span>
<a href="#" class="mex-link-heavy">edit</a>
</div>
</div>
</div>