WKWebView: SVG with 100% height and width is rendered truncated

If you render an SVG in the WKWebView component that has an <image> tag, xlink:href attribute and 100% height and width, the lower part of the SVG is always cut off.

My expectation would have been that the SVG would be rendered entirety. This happens on all devices I have tested it on and in the simulator. It also happens regardless of the SVG file. It does not happen on Android devices or in other browsers.

Minimal code example to reproduce:

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    let webView: WebViewController = WebViewController()
    webView.loadView()
    view.addSubview(webView.webView)
    webView.setAnchors(view: self.view)
    }
}

class WebViewController: UIViewController, WKUIDelegate {
    var webView: WKWebView!
    
    func setAnchors(view: UIView) {
        webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        webView.heightAnchor.constraint(equalToConstant: 160).isActive = true
        webView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1.0).isActive = true
    }
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        
        webView.translatesAutoresizingMaskIntoConstraints = false
        view = webView
        
        webView.loadHTMLString("""
                               <svg width="100%" height="100%">
                                 <image xlink:href="https://upload.wikimedia.org/wikipedia/en/5/56/Batman_Logo.svg" width="100%" height="100%"/>
                               </svg>
                               ''';
    """, baseURL: nil);
    }
}

Xcode version: 15.2 (15C500b)

Bug reporting feedback reference id: FB13589238

Thank you for your report. Do you know if this issue occurred on older versions of iOS?

WKWebView: SVG with 100% height and width is rendered truncated
 
 
Q