WKWebView Loading HTML Strings Taking An Extremely Long Time On Mac Catalyst (Ventura 13.2.1)

I have an area in my app where I load local HTML strings in WKWebView. Loading is fast on iOS. These local HTML strings are small.

On Mac Catalyst I added the ability to open this area of the UI in a new window scene (new window). And for some reason sometimes when I do this these simple HTML strings can take 10-15 seconds to load in the WKWebview in the new window.

These HTML strings are super small. I key value observed the loading property of the WKWebview and I hold the current date just before calling -loadHTMLString:baseURL:

Then when the web view completes loading I see how much time passed:

-(void)observeValueForKeyPath:(NSString*)keyPath
                     ofObject:(id)object
                       change:(NSDictionary<NSKeyValueChangeKey,id>*)change
                      context:(void*)context
{
     if (object == self.webview 
         && [keyPath isEqualToString:@"loading"])
   {
          if (!self.webview.isLoading)
          {
              NSTimeInterval timeInterval = [NSDate.date timeIntervalSinceDate:self.loadStartDate];
             NSLog(@"Web view took %f seconds to load",timeInterval);
         }
   }
   else 
  {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  }
}

Sometimes it is taking as long as 5 seconds to load a tiny HTML string. When opening these WKWebviews in the same window I don't get these long load times. But when I kick of WKWebView inside a new window scene I often do.

Just to add, I make the call to -loadHTMLString:baseURL: in -viewWIllAppear:. I use a BOOL to make sure I only call -loadHTMLString:baseURL: once since viewWillAppear: can be called multiple times. This is how my code has always been.

What's weird is if I move the -loadHTMLString:baseURL: call to -viewDidAppear: loading appears to be a bit faster (not as fast as it should be though, but better) even though -viewDidAppear is called after viewWillAppear.

Is it just in my head or is WKWebView trying to optimize and it's actually throttling/delaying the page load? If so it seems to be trying too hard to optimize the window is visible and active and I see my spinner for way too long. Is it waiting for some window state to finish "loading' and draw on screen?

WKWebView Loading HTML Strings Taking An Extremely Long Time On Mac Catalyst (Ventura 13.2.1)
 
 
Q