Dynamically resizing NSPreferencePane content

Is it not possible to dynamically change or constrain an NSPreferencePane's mainView size? I have looked all over and this doesn't seem to be mentioned anywhere. The most I can seemingly do is set the frame and hope the user doesn't resize the window.

class scor: NSPreferencePane {
override func mainViewDidLoad() {
mainView = NSHostingView(rootView: ContentView())
mainView.frame = NSMakeRect(0, 0, 668, 1048)
}
}

Here is a screenshot, just with a simple webview as a test, note the scrollbar:

My storyboard is just from the default prefpane Xcode template, nothing special. I looked at the header file for NSPreferencePane and came up with nothing. All I can think of is that this is impossible due to the way they are implemented? The only thing we seemingly have access to is mainView, so I can't like constrain the size of mainView to its parent, for example.

Additionally, if I make a new preference pane, and make a button or other view that I choose to resize to fill horizontally and vertically, it does that, but not really? Here is what that looks like:

The behaviour is similar to the previous preference pane, the width does adapt correctly, the height stays the same, forever.

Not that it really matters but I am using macOS 14.7.6 on an M2 air

Dynamically resizing NSPreferencePane content
 
 
Q