Skip to content

Commit 7a7577e

Browse files
authored
[Fabric] LogBox should destroy its window on instance shutdown (#13675)
* [Fabric] LogBox should destroy its window on instance shutdown * Change files * format
1 parent 5fbb012 commit 7a7577e

File tree

6 files changed

+18
-39
lines changed

6 files changed

+18
-39
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "[Fabric] LogBox should destroy its window on instance shutdown",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ struct CompositionReactViewInstance
5858
void UpdateRootView() noexcept;
5959
void UninitRootView() noexcept;
6060

61-
private:
62-
template <class TAction>
63-
Mso::Future<void> PostInUIQueue(TAction &&action) noexcept;
64-
6561
private:
6662
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland> m_weakRootControl;
6763
IReactDispatcher m_uiDispatcher{nullptr};
@@ -102,29 +98,6 @@ void CompositionReactViewInstance::UninitRootView() noexcept {
10298
}
10399
}
104100

105-
//===========================================================================
106-
// ReactViewInstance inline implementation
107-
//===========================================================================
108-
109-
template <class TAction>
110-
inline Mso::Future<void> CompositionReactViewInstance::PostInUIQueue(TAction &&action) noexcept {
111-
// ReactViewInstance has shorter lifetime than ReactRootControl. Thus, we capture this WeakPtr.
112-
auto promise = Mso::Promise<void>();
113-
114-
m_uiDispatcher.Post([promise, weakThis{get_weak()}, action{std::forward<TAction>(action)}]() mutable {
115-
if (auto strongThis = weakThis.get()) {
116-
if (auto rootControl = strongThis->m_weakRootControl.get()) {
117-
action(rootControl);
118-
promise.SetValue();
119-
return;
120-
}
121-
}
122-
promise.TryCancel();
123-
});
124-
125-
return promise.AsFuture();
126-
}
127-
128101
void ApplyConstraints(
129102
const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraintsIn,
130103
facebook::react::LayoutConstraints &layoutConstraintsOut) noexcept {

vnext/Microsoft.ReactNative/Modules/LogBoxModule.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919

2020
namespace Microsoft::ReactNative {
2121

22+
LogBox::~LogBox() {
23+
#ifdef USE_FABRIC
24+
if (m_hwnd) {
25+
m_context.UIDispatcher().Post([hwnd = m_hwnd]() { DestroyWindow(hwnd); });
26+
m_hwnd = nullptr;
27+
}
28+
#endif
29+
}
30+
2231
#ifdef USE_FABRIC
2332
constexpr PCWSTR c_logBoxWindowClassName = L"MS_REACTNATIVE_LOGBOX";
2433
constexpr auto CompHostProperty = L"CompHost";

vnext/Microsoft.ReactNative/Modules/LogBoxModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ REACT_MODULE(LogBox)
1414
struct LogBox : public std::enable_shared_from_this<LogBox> {
1515
using ModuleSpec = ReactNativeSpecs::LogBoxSpec;
1616

17+
~LogBox();
18+
1719
REACT_INIT(Initialize)
1820
void Initialize(winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept;
1921

vnext/Microsoft.ReactNative/ReactHost/MsoReactContext.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ ReactContext::ReactContext(
170170
m_properties{winrt::make<WeakRefPropertyBag>(properties)},
171171
m_notifications{notifications} {}
172172

173-
void ReactContext::Destroy() noexcept {
174-
if (auto notificationService =
175-
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNotificationService>(m_notifications)) {
176-
notificationService->UnsubscribeAll();
177-
}
178-
}
179-
180173
winrt::Microsoft::ReactNative::IReactPropertyBag ReactContext::Properties() const noexcept {
181174
return m_properties;
182175
}

vnext/Microsoft.ReactNative/ReactHost/MsoReactContext.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class ReactContext final : public Mso::UnknownObject<IReactContext> {
4545
winrt::Microsoft::ReactNative::IReactPropertyBag const &properties,
4646
winrt::Microsoft::ReactNative::IReactNotificationService const &notifications) noexcept;
4747

48-
// ReactContext may have longer lifespan than ReactInstance.
49-
// The ReactInstance uses the Destroy method to enforce the ReactContext cleanup
50-
// when the ReactInstance is destroyed.
51-
void Destroy() noexcept;
52-
5348
public: // IReactContext
5449
winrt::Microsoft::ReactNative::IReactPropertyBag Properties() const noexcept override;
5550
winrt::Microsoft::ReactNative::IReactNotificationService Notifications() const noexcept override;

0 commit comments

Comments
 (0)