I am adding a viewport tag from within my contrib theme using hook_page_attachments_alter but core's does not get overridden so I end up with two viewport tags, one from my theme and the other from core. The viewport tag from core seems to come from:
class DefaultHtmlFragmentRenderer implements HtmlFragmentRendererInterface
in
/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
($page->addMetaElement(new MetaElement(NULL, array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0')));)
I add my custom viewport meta tag like this in my theme's .theme file:
function MYTHEME_page_attachments_alter(array &$page) {
$viewport = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
),
);
$page['#attached']['html_head'][] = [$viewport, 'viewport'];
}
It ends up looking like this:

Comments
Comment #1
berdirI would suggest to wait for #2352155: Remove HtmlFragment/HtmlPage or try the patch there before trying to do anything here. That will probably change a lot related to all this.
Comment #2
danny englander@Berdir - thanks for all your help and link to that issue.
Comment #3
danny englanderThis is now fixed in Beta 4.