From 631b2c0a39fda01339ab790379fe074dfe416628 Mon Sep 17 00:00:00 2001 From: Vladimir Morozov Date: Thu, 21 May 2020 22:04:10 -0700 Subject: [PATCH 1/3] Fix ReactInstance error state to avoid crashes --- vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp index 151f0141364..4bd4ec76d51 100644 --- a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +++ b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp @@ -407,7 +407,12 @@ void ReactInstanceWin::OnReactInstanceLoaded(const Mso::ErrorCode &errorCode) no if (auto strongThis = weakThis.GetStrongPtr()) { if (!strongThis->m_isLoaded) { strongThis->m_isLoaded = true; - strongThis->m_state = ReactInstanceState::Loaded; + if (!errorCode) { + strongThis->m_state = ReactInstanceState::Loaded; + } else { + strongThis->m_state = ReactInstanceState::HasError; + } + if (auto onLoaded = strongThis->m_options.OnInstanceLoaded.Get()) { onLoaded->Invoke(*strongThis, errorCode); } From b59f476495fdff3fa8ba8e2d4b691a686a32329d Mon Sep 17 00:00:00 2001 From: Vladimir Morozov Date: Thu, 21 May 2020 22:04:56 -0700 Subject: [PATCH 2/3] Change files --- ...windows-2020-05-21-22-04-55-PR-FixInstanceLoading.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-05-21-22-04-55-PR-FixInstanceLoading.json diff --git a/change/react-native-windows-2020-05-21-22-04-55-PR-FixInstanceLoading.json b/change/react-native-windows-2020-05-21-22-04-55-PR-FixInstanceLoading.json new file mode 100644 index 00000000000..3747500288b --- /dev/null +++ b/change/react-native-windows-2020-05-21-22-04-55-PR-FixInstanceLoading.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Fix ReactInstance error state to avoid crashes", + "packageName": "react-native-windows", + "email": "vmorozov@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-05-22T05:04:55.630Z" +} From 3c00ee0eaf0e1657205315eb0dd34155a18595ba Mon Sep 17 00:00:00 2001 From: Vladimir Morozov Date: Fri, 22 May 2020 12:16:58 -0700 Subject: [PATCH 3/3] Clean m_redboxContent after RedBox closing --- vnext/Microsoft.ReactNative/RedBox.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index e7eb49bad95..74e6048b640 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -46,10 +46,12 @@ struct RedBox : public std::enable_shared_from_this { } void WindowSizeChanged(winrt::Windows::UI::Core::WindowSizeChangedEventArgs const &args) noexcept { - m_redboxContent.MaxHeight(args.Size().Height); - m_redboxContent.Height(args.Size().Height); - m_redboxContent.MaxWidth(args.Size().Width); - m_redboxContent.Width(args.Size().Width); + if (m_redboxContent) { + m_redboxContent.MaxHeight(args.Size().Height); + m_redboxContent.Height(args.Size().Height); + m_redboxContent.MaxWidth(args.Size().Width); + m_redboxContent.Width(args.Size().Width); + } } void ShowNewJSError() noexcept { @@ -138,6 +140,7 @@ struct RedBox : public std::enable_shared_from_this { m_reloadButton.Click(m_tokenReload); xaml::Window::Current().SizeChanged(m_tokenSizeChanged); m_popup.Closed(m_tokenClosed); + m_redboxContent = nullptr; m_onClosedCallback(GetId()); }