From 0ab85ffe76ea4cf664ec20abebc630ca8702b9eb Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 15 May 2025 10:38:32 -0700 Subject: [PATCH 1/5] Fix crash when reloading an instance with an active ReactNativeIsland --- .../Fabric/Composition/ReactNativeIsland.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index 3dce49c0146..2ffbcad2b62 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp @@ -539,17 +539,6 @@ void ReactNativeIsland::UninitRootView() noexcept { auto uiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties( winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties())); uiManager->stopSurface(static_cast(RootTag())); - - // This is needed to ensure that the unmount JS logic is completed before the the instance is shutdown during - // instance destruction. Aligns with similar code in ReactInstanceWin::DetachRootView for paper Future: Instead - // this method should return a Promise, which should be resolved when the JS logic is complete. The task will auto - // set the event on destruction to ensure that the event is set if the JS Queue has already been shutdown - Mso::ManualResetEvent mre; - m_context.JSDispatcher().Post([autoMRE = std::make_unique(AutoMRE{mre})]() {}); - mre.Wait(); - - // Paper version gives the JS thread time to finish executing - Is this needed? - // m_jsMessageThread.Load()->runOnQueueSync([]() {}); } m_rootTag = -1; From 10a795fb6110e3fc0d5f12fab9a0e6b2746158ef Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 15 May 2025 10:38:41 -0700 Subject: [PATCH 2/5] Change files --- ...ative-windows-2e987ef7-fe10-47ca-9390-fb04d7839be3.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-2e987ef7-fe10-47ca-9390-fb04d7839be3.json diff --git a/change/react-native-windows-2e987ef7-fe10-47ca-9390-fb04d7839be3.json b/change/react-native-windows-2e987ef7-fe10-47ca-9390-fb04d7839be3.json new file mode 100644 index 00000000000..ec2db646d7b --- /dev/null +++ b/change/react-native-windows-2e987ef7-fe10-47ca-9390-fb04d7839be3.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix crash when reloading an instance with an active ReactNativeIsland", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} From 84c176be1047396b1fe1ae953ac81b1cd2408b03 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 15 May 2025 10:39:42 -0700 Subject: [PATCH 3/5] Update simple sample to use function component rather than component class --- packages/playground/Samples/simple.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/playground/Samples/simple.tsx b/packages/playground/Samples/simple.tsx index 1ba97312559..3434f1e43c4 100644 --- a/packages/playground/Samples/simple.tsx +++ b/packages/playground/Samples/simple.tsx @@ -6,17 +6,15 @@ import React from 'react'; import {AppRegistry, View} from 'react-native'; -export default class Bootstrap extends React.Component { - render() { - return ( - - - - ); - } -} +const Bootstrap = () => { + return ( + + + + ); +}; AppRegistry.registerComponent('Bootstrap', () => Bootstrap); From e03d905afe55b7e6c320a41ede55f3d704659b9b Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 15 May 2025 10:42:48 -0700 Subject: [PATCH 4/5] More cleanup --- .../Fabric/Composition/ReactNativeIsland.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index 2ffbcad2b62..b4f76662d7d 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp @@ -520,13 +520,6 @@ void ReactNativeIsland::UpdateRootViewInternal() noexcept { } } -struct AutoMRE { - ~AutoMRE() { - mre.Set(); - } - Mso::ManualResetEvent mre; -}; - void ReactNativeIsland::UninitRootView() noexcept { if (!m_isInitialized) { return; From 45e5d6b1c33a2d3ab9956a952948b56d2ab35ee4 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 15 May 2025 11:15:28 -0700 Subject: [PATCH 5/5] Fix warnings --- .../windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp | 2 +- .../playground-composition/Playground-Composition.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp b/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp index fab77b3b75b..7ebc89be95e 100644 --- a/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp +++ b/packages/e2e-test-app-fabric/windows/RNTesterApp-Fabric/RNTesterApp-Fabric.cpp @@ -331,7 +331,7 @@ void InsertExpandCollapseStateValueIfNotDefault( } } -winrt::Windows::Data::Json::JsonObject ListErrors(winrt::Windows::Data::Json::JsonValue payload) { +winrt::Windows::Data::Json::JsonObject ListErrors(winrt::Windows::Data::Json::JsonValue /*payload*/) { winrt::Windows::Data::Json::JsonObject result; winrt::Windows::Data::Json::JsonArray jsonErrors; winrt::Windows::Data::Json::JsonArray jsonWarnings; diff --git a/packages/playground/windows/playground-composition/Playground-Composition.cpp b/packages/playground/windows/playground-composition/Playground-Composition.cpp index 3a4e4211d78..57436b63087 100644 --- a/packages/playground/windows/playground-composition/Playground-Composition.cpp +++ b/packages/playground/windows/playground-composition/Playground-Composition.cpp @@ -53,7 +53,7 @@ void RegisterCustomComponent(winrt::Microsoft::ReactNative::IReactPackageBuilder */ struct EllipseImageHandler : winrt::implements { - bool CanLoadImageUri(winrt::Microsoft::ReactNative::IReactContext context, winrt::Windows::Foundation::Uri uri) { + bool CanLoadImageUri(winrt::Microsoft::ReactNative::IReactContext, winrt::Windows::Foundation::Uri uri) { return uri.SchemeName() == L"ellipse"; } @@ -239,12 +239,12 @@ struct WindowData { ::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SIZEBOX); m_compRootView.SizeChanged( [hwnd, props = InstanceSettings().Properties()]( - auto sender, const winrt::Microsoft::ReactNative::RootViewSizeChangedEventArgs &args) { + auto /*sender*/, const winrt::Microsoft::ReactNative::RootViewSizeChangedEventArgs &args) { auto compositor = winrt::Microsoft::ReactNative::Composition::CompositionUIService::GetCompositor(props); auto async = compositor.RequestCommitAsync(); async.Completed([hwnd, size = args.Size()]( - auto asyncInfo, winrt::Windows::Foundation::AsyncStatus /*asyncStatus*/) { + auto /*asyncInfo*/, winrt::Windows::Foundation::AsyncStatus /*asyncStatus*/) { RECT rcClient, rcWindow; GetClientRect(hwnd, &rcClient); GetWindowRect(hwnd, &rcWindow); @@ -340,7 +340,7 @@ struct WindowData { case IDM_UNLOAD: { auto async = Host().UnloadInstance(); async.Completed([&, uidispatch = InstanceSettings().UIDispatcher()]( - auto asyncInfo, winrt::Windows::Foundation::AsyncStatus asyncStatus) { + auto /*asyncInfo*/, winrt::Windows::Foundation::AsyncStatus asyncStatus) { asyncStatus; OutputDebugStringA("Instance Unload completed\n"); @@ -583,7 +583,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) L"ReactNative.Composition", L"CompositionContext"}); auto async = data->m_host.UnloadInstance(); - async.Completed([host = data->m_host](auto asyncInfo, winrt::Windows::Foundation::AsyncStatus asyncStatus) { + async.Completed([host = data->m_host](auto /*asyncInfo*/, winrt::Windows::Foundation::AsyncStatus asyncStatus) { asyncStatus; assert(asyncStatus == winrt::Windows::Foundation::AsyncStatus::Completed); host.InstanceSettings().UIDispatcher().Post([]() { PostQuitMessage(0); });