Skip to content

Commit

Permalink
Keep propertyBag alive for duration of InstanceDestroyed event (#12364)
Browse files Browse the repository at this point in the history
* Keep propertyBag alive for duration of InstanceDestroyed event

* Change files
  • Loading branch information
acoates-ms committed Nov 8, 2023
1 parent 46d5f9d commit b87abc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Keep propertyBag alive for duration of InstanceDestroyed event",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
6 changes: 6 additions & 0 deletions vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ ReactInstanceWin::ReactInstanceWin(
m_whenDestroyedResult =
m_whenDestroyed.AsFuture().Then<Mso::Executors::Inline>([whenLoaded = m_whenLoaded,
onDestroyed = m_options.OnInstanceDestroyed,
// If the ReactHost has been released, this
// instance might be the only thing keeping
// the propertyBag alive.
// We want it to remain alive for the
// InstanceDestroyed callbacks
propBag = m_options.Properties,
reactContext = m_reactContext]() noexcept {
whenLoaded.TryCancel(); // It only has an effect if whenLoaded was not set before
Microsoft::ReactNative::HermesRuntimeHolder::storeTo(ReactPropertyBag(reactContext->Properties()), nullptr);
Expand Down

0 comments on commit b87abc8

Please sign in to comment.