         }
 
         override func didMove(toParent parent: UIViewController?) {
+            update()
             super.didMove(toParent: parent)
-            update()
         }
 
         func update() {
             if isPresented.wrappedValue {
-                if hostingWindow == nil {
-                    hostingWindow = UIHostingWindow(rootView: rootView)
-                    hostingWindow?.windowLevel = style.level
-                    hostingWindow?.windowLabel = style.label
-                }
-
-                hostingWindow?.show(isKey: style.isKey)
+                hostingWindow.show(isKey: style.isKey)
             } else {
-                hostingWindow?.hide()
-                hostingWindow = nil
+                hostingWindow.hide()
             }
         }
     }

    func updateUIViewController(_ viewController: ViewController, context: Context) {
        viewController.isPresented = isPresented
        viewController.style = style
        viewController.rootView.context = context
        viewController.update()

        // Fixes an issue where animations are broken.
        DispatchQueue.main.async {
            viewController.rootView.content = content
        }
    }
}



extension Window {
    final class ViewController: UIViewController {
        var hostingWindow: UIHostingWindow<RootView<Content>>
        var isPresented: Binding<Bool>
        var style: WindowStyle

        init(isPresented: Binding<Bool>, style: WindowStyle, rootView: RootView<Content>) {
            self.isPresented = isPresented
            self.style = style

            hostingWindow = UIHostingWindow(rootView: rootView).apply {
                $0.windowLevel = style.level
                $0.windowLabel = style.label
            }

            super.init(nibName: nil, bundle: nil)
        }

