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" +} 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); diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index 3dce49c0146..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; @@ -539,17 +532,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;