From 25426cb2874c4c999213faffb2271a921582c1e3 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 4 May 2020 12:54:31 -0700 Subject: [PATCH 01/10] Expose ability for apps to provide their own RedBox implementation --- .../Microsoft.ReactNative.vcxproj | 11 ++ .../Microsoft.ReactNative.vcxproj.filters | 1 + .../ReactHost/ReactInstanceWin.cpp | 2 +- .../ReactInstanceSettings.h | 12 ++ .../ReactInstanceSettings.idl | 2 + .../Microsoft.ReactNative/ReactNativeHost.cpp | 6 + vnext/Microsoft.ReactNative/RedBox.cpp | 164 ++++++++++++++---- vnext/Microsoft.ReactNative/RedBox.h | 5 +- vnext/Microsoft.ReactNative/RedBoxHandler.cpp | 55 ++++++ vnext/Microsoft.ReactNative/RedBoxHandler.h | 35 ++++ vnext/Microsoft.ReactNative/RedBoxHandler.idl | 42 +++++ 11 files changed, 294 insertions(+), 41 deletions(-) create mode 100644 vnext/Microsoft.ReactNative/RedBoxHandler.cpp create mode 100644 vnext/Microsoft.ReactNative/RedBoxHandler.h create mode 100644 vnext/Microsoft.ReactNative/RedBoxHandler.idl diff --git a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj index 57d6d88ea13..aa023e6908c 100644 --- a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +++ b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj @@ -318,6 +318,10 @@ ReactInstanceSettings.idl Code + + RedBoxHandler.idl + Code + ReactNativeHost.idl Code @@ -476,6 +480,10 @@ ReactInstanceSettings.idl Code + + RedBoxHandler.idl + Code + ReactNativeHost.idl Code @@ -528,6 +536,9 @@ Designer + + Designer + Designer diff --git a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters index e53f5484d2f..e402a4d9453 100644 --- a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +++ b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters @@ -695,6 +695,7 @@ + diff --git a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp index d759d30a997..5dcc0badd60 100644 --- a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +++ b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp @@ -519,7 +519,7 @@ std::shared_ptr ReactInstanceWin::GetRedBoxHandler() noexcept { return m_options.RedBoxHandler; } else if (m_options.DeveloperSettings.IsDevModeEnabled) { auto localWkReactHost = m_weakReactHost; - return CreateRedBoxHandler(std::move(localWkReactHost), m_uiMessageThread.LoadWithLock()); + return CreateDefaultRedBoxHandler(std::move(localWkReactHost)); } else { return {}; } diff --git a/vnext/Microsoft.ReactNative/ReactInstanceSettings.h b/vnext/Microsoft.ReactNative/ReactInstanceSettings.h index 081ef1d2cfb..d6942f4402d 100644 --- a/vnext/Microsoft.ReactNative/ReactInstanceSettings.h +++ b/vnext/Microsoft.ReactNative/ReactInstanceSettings.h @@ -78,6 +78,9 @@ struct ReactInstanceSettings : ReactInstanceSettingsT { uint16_t DebuggerPort() noexcept; void DebuggerPort(uint16_t value) noexcept; + RedBox::IRedBoxHandler RedBoxHandler() noexcept; + void RedBoxHandler(RedBox::IRedBoxHandler const &value) noexcept; + private: hstring m_mainComponentName{}; bool m_useDeveloperSupport{REACT_DEFAULT_USE_DEVELOPER_SUPPORT}; @@ -97,6 +100,7 @@ struct ReactInstanceSettings : ReactInstanceSettingsT { hstring m_debugBundlePath{}; hstring m_bundleRootPath{}; uint16_t m_debuggerPort{9229}; + RedBox::IRedBoxHandler m_redBoxHandler{nullptr}; }; } // namespace winrt::Microsoft::ReactNative::implementation @@ -257,4 +261,12 @@ inline void ReactInstanceSettings::DebuggerPort(uint16_t value) noexcept { m_debuggerPort = value; } +inline RedBox::IRedBoxHandler ReactInstanceSettings::RedBoxHandler() noexcept { + return m_redBoxHandler; +} + +inline void ReactInstanceSettings::RedBoxHandler(RedBox::IRedBoxHandler const &value) noexcept { + m_redBoxHandler = value; +} + } // namespace winrt::Microsoft::ReactNative::implementation diff --git a/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl b/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl index d78b4149020..42995610f1a 100644 --- a/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl +++ b/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl @@ -2,6 +2,7 @@ // Licensed under the MIT License. import "NoExceptionAttribute.idl"; +import "RedBoxHandler.idl"; namespace Microsoft.ReactNative { @@ -28,5 +29,6 @@ namespace Microsoft.ReactNative { String DebugBundlePath { get; set; }; String BundleRootPath { get; set; }; UInt16 DebuggerPort { get; set; }; + Microsoft.ReactNative.RedBox.IRedBoxHandler RedBoxHandler { get; set; }; } } diff --git a/vnext/Microsoft.ReactNative/ReactNativeHost.cpp b/vnext/Microsoft.ReactNative/ReactNativeHost.cpp index 61ed3d4e4a4..5b3403a01bd 100644 --- a/vnext/Microsoft.ReactNative/ReactNativeHost.cpp +++ b/vnext/Microsoft.ReactNative/ReactNativeHost.cpp @@ -6,6 +6,7 @@ #include "ReactNativeHost.g.cpp" #include "ReactPackageBuilder.h" +#include "RedBox.h" using namespace winrt; using namespace Windows::Foundation::Collections; @@ -78,6 +79,10 @@ void ReactNativeHost::ReloadInstance() noexcept { legacySettings.UseWebDebugger = m_instanceSettings.UseWebDebugger(); legacySettings.DebuggerPort = m_instanceSettings.DebuggerPort(); + if (m_instanceSettings.RedBoxHandler()) { + legacySettings.RedBoxHandler = std::move(Mso::React::CreateRedBoxHandler(m_instanceSettings.RedBoxHandler())); + } + Mso::React::ReactOptions reactOptions{}; reactOptions.DeveloperSettings.IsDevModeEnabled = legacySettings.EnableDeveloperMenu; reactOptions.DeveloperSettings.SourceBundleName = legacySettings.DebugBundlePath; @@ -90,6 +95,7 @@ void ReactNativeHost::ReloadInstance() noexcept { reactOptions.DeveloperSettings.DebugHost = legacySettings.DebugHost; reactOptions.BundleRootPath = legacySettings.BundleRootPath; reactOptions.DeveloperSettings.DebuggerPort = legacySettings.DebuggerPort; + reactOptions.RedBoxHandler = legacySettings.RedBoxHandler; reactOptions.LegacySettings = std::move(legacySettings); diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index 90279a135e7..639c868aca3 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -4,6 +4,7 @@ #include "RedBox.h" #include #include +#include #include #include #include @@ -18,10 +19,10 @@ namespace Mso::React { struct RedBox : public std::enable_shared_from_this { RedBox( - Mso::WeakPtr weakReactHost, + const Mso::WeakPtr &weakReactHost, Mso::Functor &&onClosedCallback, ErrorInfo &&errorInfo) noexcept - : m_weakReactHost(std::move(weakReactHost)), + : m_weakReactHost(weakReactHost), m_onClosedCallback(std::move(onClosedCallback)), m_errorInfo(std::move(errorInfo)) {} @@ -346,26 +347,24 @@ struct RedBox : public std::enable_shared_from_this { /* * This class is implemented such that the methods on IRedBoxHandler are thread safe. */ -struct RedBoxHandler : public std::enable_shared_from_this, IRedBoxHandler { - RedBoxHandler( - Mso::WeakPtr weakReactHost, - std::shared_ptr uiMessageQueue) noexcept - : m_weakReactHost(std::move(weakReactHost)), m_wkUIMessageQueue(std::move(uiMessageQueue)) {} +struct DefaultRedBoxHandler : public std::enable_shared_from_this, IRedBoxHandler { + DefaultRedBoxHandler(Mso::WeakPtr &&weakReactHost) noexcept + : m_weakReactHost(std::move(weakReactHost)), + m_uiDispatcher(winrt::Windows::ApplicationModel::Core::CoreApplication::MainView().CoreWindow().Dispatcher()) {} - ~RedBoxHandler() { + ~DefaultRedBoxHandler() { // Hide any currently showing redboxes std::vector> redboxes; { std::scoped_lock lock{m_lockRedBox}; std::swap(m_redboxes, redboxes); } - if (auto uiQueue = m_wkUIMessageQueue.lock()) { - uiQueue->runOnQueue([redboxes = std::move(redboxes)]() { - for (const auto redbox : redboxes) { - redbox->Dismiss(); - } - }); - } + m_uiDispatcher.TryRunAsync( + winrt::Windows::UI::Core::CoreDispatcherPriority::Low, [redboxes = std::move(redboxes)]() { + for (const auto redbox : redboxes) { + redbox->Dismiss(); + } + }); } virtual void showNewError(ErrorInfo &&info, ErrorType /*exceptionType*/) override { @@ -404,28 +403,26 @@ struct RedBoxHandler : public std::enable_shared_from_this, IRedB } } if (redbox) { - if (auto uiQueue = m_wkUIMessageQueue.lock()) { - uiQueue->runOnQueue([redboxCaptured = std::move(redbox), errorInfo = std::move(info)]() { - redboxCaptured->UpdateError(std::move(errorInfo)); - }); - } + m_uiDispatcher.TryRunAsync( + winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, + [redboxCaptured = std::move(redbox), errorInfo = std::move(info)]() { + redboxCaptured->UpdateError(std::move(errorInfo)); + }); } } virtual void dismissRedbox() override { - if (auto uiQueue = m_wkUIMessageQueue.lock()) { - uiQueue->runOnQueue([&]() { - std::scoped_lock lock{m_lockRedBox}; - if (!m_redboxes.empty()) - m_redboxes[0]->Dismiss(); - }); - } + m_uiDispatcher.TryRunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [&]() { + std::scoped_lock lock{m_lockRedBox}; + if (!m_redboxes.empty()) + m_redboxes[0]->Dismiss(); + }); } private: // When notified by a redbox that its been dismisssed void onDismissedCallback(uint32_t id) noexcept { - // Save a local ref, so if we are removing the last redbox which could hold the last ref to the RedBoxHandler + // Save a local ref, so if we are removing the last redbox which could hold the last ref to the DefaultRedBoxHandler // We ensure that we exit the mutex before the handler is destroyed. std::shared_ptr redbox; { @@ -453,25 +450,116 @@ struct RedBoxHandler : public std::enable_shared_from_this, IRedB } } - if (auto uiQueue = m_wkUIMessageQueue.lock()) { - if (m_showingRedBox || !redbox) // Only show one redbox at a time - return; - m_showingRedBox = true; - uiQueue->runOnQueue([redboxCaptured = std::move(redbox)]() { redboxCaptured->ShowNewJSError(); }); - } + if (m_showingRedBox || !redbox) // Only show one redbox at a time + return; + m_showingRedBox = true; + + m_uiDispatcher.TryRunAsync( + winrt::Windows::UI::Core::CoreDispatcherPriority::Low, + [redboxCaptured = std::move(redbox)]() { redboxCaptured->ShowNewJSError(); }); } bool m_showingRedBox = false; // Access from UI Thread only std::mutex m_lockRedBox; std::vector> m_redboxes; // Protected by m_lockRedBox const Mso::WeakPtr m_weakReactHost; - const std::weak_ptr m_wkUIMessageQueue; + const winrt::Windows::UI::Core::CoreDispatcher m_uiDispatcher; +}; + +struct RedBoxErrorFrameInfo + : public winrt::implements { + RedBoxErrorFrameInfo(Mso::React::ErrorFrameInfo &&errorFrameInfo) : m_frame(std::move(errorFrameInfo)) {} + + winrt::hstring File() noexcept { + return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_frame.File).c_str(); + } + + winrt::hstring Method() noexcept { + return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_frame.Method).c_str(); + } + + uint32_t Line() noexcept { + return m_frame.Line; + } + uint32_t Column() noexcept { + return m_frame.Column; + } + + private: + Mso::React::ErrorFrameInfo m_frame; +}; + +struct RedBoxErrorInfo : public winrt::implements { + RedBoxErrorInfo(Mso::React::ErrorInfo &&errorInfo) : m_errorInfo(std::move(errorInfo)) {} + + winrt::hstring Message() noexcept { + return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_errorInfo.Message).c_str(); + } + + uint32_t Id() noexcept { + return m_errorInfo.Id; + } + + winrt::Windows::Foundation::Collections::IVectorView + Callstack() noexcept { + if (!m_callstack) { + m_callstack = winrt::single_threaded_vector(); + for (auto frame : m_errorInfo.Callstack) { + m_callstack.Append(winrt::make(std::move(frame))); + } + } + + return m_callstack.GetView(); + } + + private: + winrt::Windows::Foundation::Collections::IVector m_callstack{ + nullptr}; + + Mso::React::ErrorInfo m_errorInfo; +}; + +struct RedBoxHandler : public Mso::React::IRedBoxHandler { + RedBoxHandler(winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) + : m_redBoxHandler(redBoxHandler) {} + + static_assert( + static_cast(Mso::React::ErrorType::JSFatal) == + static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::JavaScriptFatal)); + static_assert( + static_cast(Mso::React::ErrorType::JSSoft) == + static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::JavaScriptSoft)); + static_assert( + static_cast(Mso::React::ErrorType::Native) == + static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::Native)); + + virtual void showNewError(Mso::React::ErrorInfo &&info, Mso::React::ErrorType errorType) override { + m_redBoxHandler.ShowNewError( + winrt::make(std::move(info)), + static_cast(static_cast(errorType))); + } + virtual bool isDevSupportEnabled() override { + return m_redBoxHandler.IsDevSupportEnabled(); + } + virtual void updateError(Mso::React::ErrorInfo &&info) override { + m_redBoxHandler.UpdateError(winrt::make(std::move(info))); + } + + virtual void dismissRedbox() override { + m_redBoxHandler.DismissRedBox(); + } + + private: + winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler m_redBoxHandler; }; std::shared_ptr CreateRedBoxHandler( - Mso::WeakPtr &&weakReactHost, - std::shared_ptr &&uiMessageQueue) noexcept { - return std::make_shared(std::move(weakReactHost), std::move(uiMessageQueue)); + winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) noexcept { + return std::make_shared(redBoxHandler); +} + +std::shared_ptr CreateDefaultRedBoxHandler(Mso::WeakPtr &&weakReactHost) noexcept { + return std::make_shared(std::move(weakReactHost)); } } // namespace Mso::React diff --git a/vnext/Microsoft.ReactNative/RedBox.h b/vnext/Microsoft.ReactNative/RedBox.h index 8be0393b921..f711b587568 100644 --- a/vnext/Microsoft.ReactNative/RedBox.h +++ b/vnext/Microsoft.ReactNative/RedBox.h @@ -8,7 +8,8 @@ namespace Mso::React { std::shared_ptr CreateRedBoxHandler( - Mso::WeakPtr &&weakReactHost, - std::shared_ptr &&uiMessageQueue) noexcept; + winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) noexcept; + +std::shared_ptr CreateDefaultRedBoxHandler(Mso::WeakPtr &&weakReactHost) noexcept; } // namespace Mso::React diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp new file mode 100644 index 00000000000..fb7b4c70924 --- /dev/null +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" +#include "RedBoxHandler.h" +#if __has_include("RedBox.RedBoxHandler.g.cpp") +#include "RedBox.RedBoxHandler.g.cpp" +#endif + +#include +#include +#include + +namespace winrt::Microsoft::ReactNative::RedBox::implementation { + +RedBoxHandler::RedBoxHandler(ReactNativeHost const &host) noexcept { + auto hostImpl = winrt::get_self(host); + Mso::WeakPtr wkHost(hostImpl->ReactHost()); + m_redBoxHandler = Mso::React::CreateDefaultRedBoxHandler(std::move(wkHost)); +} + +Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) +{ + Mso::React::ErrorInfo ei; + ei.Id = info.Id(); + ei.Message = ::Microsoft::Common::Unicode::Utf16ToUtf8(info.Message()); + for (auto frame : info.Callstack()) + { + Mso::React::ErrorFrameInfo efi; + efi.Method = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.Method()); + efi.File = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.File()); + efi.Line = frame.Line(); + efi.Column = frame.Column(); + ei.Callstack.push_back(std::move(efi)); + } + return std::move(ei); +} + +inline void RedBoxHandler::ShowNewError(IErrorInfo const & info, ErrorType type) noexcept { + m_redBoxHandler->showNewError(std::move(CreateErrorInfo(info)), static_cast(static_cast(type))); +} + +inline bool RedBoxHandler::IsDevSupportEnabled() noexcept { + return m_redBoxHandler->isDevSupportEnabled(); +} + +inline void RedBoxHandler::UpdateError(IErrorInfo const &info) noexcept { + m_redBoxHandler->updateError(std::move(CreateErrorInfo(info))); +} + +inline void RedBoxHandler::DismissRedBox() noexcept { + m_redBoxHandler->dismissRedbox(); +} + +} // namespace winrt::Microsoft::ReactNative::RedBox::implementation diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.h b/vnext/Microsoft.ReactNative/RedBoxHandler.h new file mode 100644 index 00000000000..207bb804afa --- /dev/null +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.h @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include "RedBox.RedBoxHandler.g.h" + +namespace Mso::React { +struct IRedBoxHandler; +} + +namespace winrt::Microsoft::ReactNative::RedBox::implementation { + +struct RedBoxHandler : RedBoxHandlerT { + RedBoxHandler(ReactNativeHost const &host) noexcept; + + void ShowNewError(IErrorInfo const &info, ErrorType type) noexcept; + bool IsDevSupportEnabled() noexcept; + void UpdateError(IErrorInfo const &info) noexcept; + void DismissRedBox() noexcept; +private: + std::shared_ptr m_redBoxHandler; +}; + +} // namespace winrt::Microsoft::ReactNative::RedBox::implementation + +namespace winrt::Microsoft::ReactNative::RedBox::factory_implementation { + +struct RedBoxHandler : RedBoxHandlerT {}; + +} // namespace winrt::Microsoft::ReactNative::RedBox::factory_implementation + +namespace winrt::Microsoft::ReactNative::RedBox::implementation { + +} // namespace winrt::Microsoft::ReactNative::RedBox::implementation diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.idl b/vnext/Microsoft.ReactNative/RedBoxHandler.idl new file mode 100644 index 00000000000..c4d6085434b --- /dev/null +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.idl @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import "ReactNativeHost.idl"; + +namespace Microsoft.ReactNative.RedBox { + + enum ErrorType { + JavaScriptFatal, // A JS Exception was thrown or otherwise fatal error + JavaScriptSoft, // An error coming from JS that isn't fatal, such as console.error + Native, + }; + + [webhosthidden] interface IErrorFrameInfo { + String File { get; }; + String Method { get; }; + UInt32 Line { get; }; + UInt32 Column { get; }; + } + + [webhosthidden] interface IErrorInfo { + String Message { get; }; + UInt32 Id { get; }; + IVectorView Callstack { get; }; + } + + [webhosthidden] + interface IRedBoxHandler + { + void ShowNewError(IErrorInfo info, ErrorType type); + Boolean IsDevSupportEnabled { get; }; + void UpdateError(IErrorInfo info); + void DismissRedBox(); + } + + [webhosthidden] + [default_interface] + runtimeclass RedBoxHandler : IRedBoxHandler { + RedBoxHandler(Microsoft.ReactNative.ReactNativeHost host); + } + +} From 25e6be685142844e6a0da27085786b94543191e2 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 4 May 2020 12:54:41 -0700 Subject: [PATCH 02/10] Change files --- ...ve-windows-2020-05-04-12-54-41-publiccustomredbox.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-05-04-12-54-41-publiccustomredbox.json diff --git a/change/react-native-windows-2020-05-04-12-54-41-publiccustomredbox.json b/change/react-native-windows-2020-05-04-12-54-41-publiccustomredbox.json new file mode 100644 index 00000000000..dc9e8030a2f --- /dev/null +++ b/change/react-native-windows-2020-05-04-12-54-41-publiccustomredbox.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Expose ability for apps to provide their own RedBox implementation", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-05-04T19:54:41.414Z" +} From 519863b26e56f44ea10ce6b0eef81eb80db5e604 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 4 May 2020 14:00:40 -0700 Subject: [PATCH 03/10] minor changes --- vnext/Microsoft.ReactNative/RedBox.cpp | 13 +++++++------ vnext/Microsoft.ReactNative/RedBoxHandler.cpp | 11 +++++------ vnext/Microsoft.ReactNative/RedBoxHandler.h | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index 639c868aca3..0983ca3a93e 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -470,18 +470,19 @@ struct RedBoxErrorFrameInfo : public winrt::implements { RedBoxErrorFrameInfo(Mso::React::ErrorFrameInfo &&errorFrameInfo) : m_frame(std::move(errorFrameInfo)) {} - winrt::hstring File() noexcept { + winrt::hstring File() const noexcept { return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_frame.File).c_str(); } - winrt::hstring Method() noexcept { + winrt::hstring Method() const noexcept { return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_frame.Method).c_str(); } - uint32_t Line() noexcept { + uint32_t Line() const noexcept { return m_frame.Line; } - uint32_t Column() noexcept { + + uint32_t Column() const noexcept { return m_frame.Column; } @@ -492,11 +493,11 @@ struct RedBoxErrorFrameInfo struct RedBoxErrorInfo : public winrt::implements { RedBoxErrorInfo(Mso::React::ErrorInfo &&errorInfo) : m_errorInfo(std::move(errorInfo)) {} - winrt::hstring Message() noexcept { + winrt::hstring Message() const noexcept { return ::Microsoft::Common::Unicode::Utf8ToUtf16(m_errorInfo.Message).c_str(); } - uint32_t Id() noexcept { + uint32_t Id() const noexcept { return m_errorInfo.Id; } diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp index fb7b4c70924..5b8c9a10216 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp @@ -19,13 +19,11 @@ RedBoxHandler::RedBoxHandler(ReactNativeHost const &host) noexcept { m_redBoxHandler = Mso::React::CreateDefaultRedBoxHandler(std::move(wkHost)); } -Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) -{ +Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) { Mso::React::ErrorInfo ei; ei.Id = info.Id(); ei.Message = ::Microsoft::Common::Unicode::Utf16ToUtf8(info.Message()); - for (auto frame : info.Callstack()) - { + for (auto frame : info.Callstack()) { Mso::React::ErrorFrameInfo efi; efi.Method = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.Method()); efi.File = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.File()); @@ -36,8 +34,9 @@ Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) return std::move(ei); } -inline void RedBoxHandler::ShowNewError(IErrorInfo const & info, ErrorType type) noexcept { - m_redBoxHandler->showNewError(std::move(CreateErrorInfo(info)), static_cast(static_cast(type))); +inline void RedBoxHandler::ShowNewError(IErrorInfo const &info, ErrorType type) noexcept { + m_redBoxHandler->showNewError( + std::move(CreateErrorInfo(info)), static_cast(static_cast(type))); } inline bool RedBoxHandler::IsDevSupportEnabled() noexcept { diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.h b/vnext/Microsoft.ReactNative/RedBoxHandler.h index 207bb804afa..d99c81eddf5 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.h +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.h @@ -18,7 +18,8 @@ struct RedBoxHandler : RedBoxHandlerT { bool IsDevSupportEnabled() noexcept; void UpdateError(IErrorInfo const &info) noexcept; void DismissRedBox() noexcept; -private: + + private: std::shared_ptr m_redBoxHandler; }; From 7b7c57cc68520bc37b55caf9d2bc711906e221cd Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 10:58:42 -0700 Subject: [PATCH 04/10] Code review feedback --- .../ReactInstanceSettings.h | 10 +-- .../ReactInstanceSettings.idl | 2 +- vnext/Microsoft.ReactNative/RedBox.cpp | 61 +++++++++---------- vnext/Microsoft.ReactNative/RedBox.h | 4 +- vnext/Microsoft.ReactNative/RedBoxHandler.cpp | 60 ++++++++++-------- vnext/Microsoft.ReactNative/RedBoxHandler.h | 28 +++------ vnext/Microsoft.ReactNative/RedBoxHandler.idl | 21 ++++--- vnext/ReactWindowsCore/DevSettings.h | 2 +- .../{RedBoxHandler.h => IRedBoxHandler.h} | 0 .../Modules/ExceptionsManagerModule.h | 2 +- .../ReactWindowsCore/ReactWindowsCore.vcxproj | 2 +- .../ReactWindowsCore.vcxproj.filters | 2 +- vnext/Scripts/ReactWin32.nuspec | 2 +- 13 files changed, 96 insertions(+), 100 deletions(-) rename vnext/ReactWindowsCore/{RedBoxHandler.h => IRedBoxHandler.h} (100%) diff --git a/vnext/Microsoft.ReactNative/ReactInstanceSettings.h b/vnext/Microsoft.ReactNative/ReactInstanceSettings.h index d6942f4402d..603a1e1e180 100644 --- a/vnext/Microsoft.ReactNative/ReactInstanceSettings.h +++ b/vnext/Microsoft.ReactNative/ReactInstanceSettings.h @@ -78,8 +78,8 @@ struct ReactInstanceSettings : ReactInstanceSettingsT { uint16_t DebuggerPort() noexcept; void DebuggerPort(uint16_t value) noexcept; - RedBox::IRedBoxHandler RedBoxHandler() noexcept; - void RedBoxHandler(RedBox::IRedBoxHandler const &value) noexcept; + IRedBoxHandler RedBoxHandler() noexcept; + void RedBoxHandler(IRedBoxHandler const &value) noexcept; private: hstring m_mainComponentName{}; @@ -100,7 +100,7 @@ struct ReactInstanceSettings : ReactInstanceSettingsT { hstring m_debugBundlePath{}; hstring m_bundleRootPath{}; uint16_t m_debuggerPort{9229}; - RedBox::IRedBoxHandler m_redBoxHandler{nullptr}; + IRedBoxHandler m_redBoxHandler{nullptr}; }; } // namespace winrt::Microsoft::ReactNative::implementation @@ -261,11 +261,11 @@ inline void ReactInstanceSettings::DebuggerPort(uint16_t value) noexcept { m_debuggerPort = value; } -inline RedBox::IRedBoxHandler ReactInstanceSettings::RedBoxHandler() noexcept { +inline IRedBoxHandler ReactInstanceSettings::RedBoxHandler() noexcept { return m_redBoxHandler; } -inline void ReactInstanceSettings::RedBoxHandler(RedBox::IRedBoxHandler const &value) noexcept { +inline void ReactInstanceSettings::RedBoxHandler(IRedBoxHandler const &value) noexcept { m_redBoxHandler = value; } diff --git a/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl b/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl index 42995610f1a..0eb5faf60c6 100644 --- a/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl +++ b/vnext/Microsoft.ReactNative/ReactInstanceSettings.idl @@ -29,6 +29,6 @@ namespace Microsoft.ReactNative { String DebugBundlePath { get; set; }; String BundleRootPath { get; set; }; UInt16 DebuggerPort { get; set; }; - Microsoft.ReactNative.RedBox.IRedBoxHandler RedBoxHandler { get; set; }; + Microsoft.ReactNative.IRedBoxHandler RedBoxHandler { get; set; }; } } diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index 0983ca3a93e..40211c6a4e1 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -349,8 +349,7 @@ struct RedBox : public std::enable_shared_from_this { */ struct DefaultRedBoxHandler : public std::enable_shared_from_this, IRedBoxHandler { DefaultRedBoxHandler(Mso::WeakPtr &&weakReactHost) noexcept - : m_weakReactHost(std::move(weakReactHost)), - m_uiDispatcher(winrt::Windows::ApplicationModel::Core::CoreApplication::MainView().CoreWindow().Dispatcher()) {} + : m_weakReactHost(std::move(weakReactHost)) {} ~DefaultRedBoxHandler() { // Hide any currently showing redboxes @@ -359,12 +358,11 @@ struct DefaultRedBoxHandler : public std::enable_shared_from_thisDismiss(); - } - }); + Mso::DispatchQueue::MainUIQueue().Post([redboxes = std::move(redboxes)]() { + for (const auto redbox : redboxes) { + redbox->Dismiss(); + } + }); } virtual void showNewError(ErrorInfo &&info, ErrorType /*exceptionType*/) override { @@ -403,19 +401,19 @@ struct DefaultRedBoxHandler : public std::enable_shared_from_thisUpdateError(std::move(errorInfo)); - }); + Mso::DispatchQueue::MainUIQueue().Post([redboxCaptured = std::move(redbox), errorInfo = std::move(info)]() { + redboxCaptured->UpdateError(std::move(errorInfo)); + }); } } virtual void dismissRedbox() override { - m_uiDispatcher.TryRunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [&]() { - std::scoped_lock lock{m_lockRedBox}; - if (!m_redboxes.empty()) - m_redboxes[0]->Dismiss(); + Mso::DispatchQueue::MainUIQueue().Post([wkthis = std::weak_ptr(shared_from_this())]() { + if (auto pthis = wkthis.lock()) { + std::scoped_lock lock{pthis->m_lockRedBox}; + if (!pthis->m_redboxes.empty()) + pthis->m_redboxes[0]->Dismiss(); + } }); } @@ -454,8 +452,7 @@ struct DefaultRedBoxHandler : public std::enable_shared_from_thisShowNewJSError(); }); } @@ -463,11 +460,10 @@ struct DefaultRedBoxHandler : public std::enable_shared_from_this> m_redboxes; // Protected by m_lockRedBox const Mso::WeakPtr m_weakReactHost; - const winrt::Windows::UI::Core::CoreDispatcher m_uiDispatcher; }; struct RedBoxErrorFrameInfo - : public winrt::implements { + : public winrt::implements { RedBoxErrorFrameInfo(Mso::React::ErrorFrameInfo &&errorFrameInfo) : m_frame(std::move(errorFrameInfo)) {} winrt::hstring File() const noexcept { @@ -490,7 +486,7 @@ struct RedBoxErrorFrameInfo Mso::React::ErrorFrameInfo m_frame; }; -struct RedBoxErrorInfo : public winrt::implements { +struct RedBoxErrorInfo : public winrt::implements { RedBoxErrorInfo(Mso::React::ErrorInfo &&errorInfo) : m_errorInfo(std::move(errorInfo)) {} winrt::hstring Message() const noexcept { @@ -501,10 +497,10 @@ struct RedBoxErrorInfo : public winrt::implements + winrt::Windows::Foundation::Collections::IVectorView Callstack() noexcept { if (!m_callstack) { - m_callstack = winrt::single_threaded_vector(); + m_callstack = winrt::single_threaded_vector(); for (auto frame : m_errorInfo.Callstack) { m_callstack.Append(winrt::make(std::move(frame))); } @@ -514,30 +510,29 @@ struct RedBoxErrorInfo : public winrt::implements m_callstack{ + winrt::Windows::Foundation::Collections::IVector m_callstack{ nullptr}; Mso::React::ErrorInfo m_errorInfo; }; struct RedBoxHandler : public Mso::React::IRedBoxHandler { - RedBoxHandler(winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) - : m_redBoxHandler(redBoxHandler) {} + RedBoxHandler(winrt::Microsoft::ReactNative::IRedBoxHandler const &redBoxHandler) : m_redBoxHandler(redBoxHandler) {} static_assert( static_cast(Mso::React::ErrorType::JSFatal) == - static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::JavaScriptFatal)); + static_cast(winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptFatal)); static_assert( static_cast(Mso::React::ErrorType::JSSoft) == - static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::JavaScriptSoft)); + static_cast(winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptSoft)); static_assert( static_cast(Mso::React::ErrorType::Native) == - static_cast(winrt::Microsoft::ReactNative::RedBox::ErrorType::Native)); + static_cast(winrt::Microsoft::ReactNative::RedBoxErrorType::Native)); virtual void showNewError(Mso::React::ErrorInfo &&info, Mso::React::ErrorType errorType) override { m_redBoxHandler.ShowNewError( winrt::make(std::move(info)), - static_cast(static_cast(errorType))); + static_cast(static_cast(errorType))); } virtual bool isDevSupportEnabled() override { return m_redBoxHandler.IsDevSupportEnabled(); @@ -551,11 +546,11 @@ struct RedBoxHandler : public Mso::React::IRedBoxHandler { } private: - winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler m_redBoxHandler; + winrt::Microsoft::ReactNative::IRedBoxHandler m_redBoxHandler; }; std::shared_ptr CreateRedBoxHandler( - winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) noexcept { + winrt::Microsoft::ReactNative::IRedBoxHandler const &redBoxHandler) noexcept { return std::make_shared(redBoxHandler); } diff --git a/vnext/Microsoft.ReactNative/RedBox.h b/vnext/Microsoft.ReactNative/RedBox.h index f711b587568..0a14590aaea 100644 --- a/vnext/Microsoft.ReactNative/RedBox.h +++ b/vnext/Microsoft.ReactNative/RedBox.h @@ -2,13 +2,13 @@ // Licensed under the MIT License. #pragma once #include +#include "IRedBoxHandler.h" #include "ReactHost/React.h" -#include "RedBoxHandler.h" namespace Mso::React { std::shared_ptr CreateRedBoxHandler( - winrt::Microsoft::ReactNative::RedBox::IRedBoxHandler const &redBoxHandler) noexcept; + winrt::Microsoft::ReactNative::IRedBoxHandler const &redBoxHandler) noexcept; std::shared_ptr CreateDefaultRedBoxHandler(Mso::WeakPtr &&weakReactHost) noexcept; diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp index 5b8c9a10216..57ba9987e9b 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp @@ -3,27 +3,21 @@ #include "pch.h" #include "RedBoxHandler.h" -#if __has_include("RedBox.RedBoxHandler.g.cpp") -#include "RedBox.RedBoxHandler.g.cpp" +#if __has_include("RedBoxHelper.g.cpp") +#include "RedBoxHelper.g.cpp" #endif #include #include #include -namespace winrt::Microsoft::ReactNative::RedBox::implementation { +namespace winrt::Microsoft::ReactNative::implementation { -RedBoxHandler::RedBoxHandler(ReactNativeHost const &host) noexcept { - auto hostImpl = winrt::get_self(host); - Mso::WeakPtr wkHost(hostImpl->ReactHost()); - m_redBoxHandler = Mso::React::CreateDefaultRedBoxHandler(std::move(wkHost)); -} - -Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) { +Mso::React::ErrorInfo CreateErrorInfo(const IRedBoxErrorInfo &info) { Mso::React::ErrorInfo ei; ei.Id = info.Id(); ei.Message = ::Microsoft::Common::Unicode::Utf16ToUtf8(info.Message()); - for (auto frame : info.Callstack()) { + for (const auto &frame : info.Callstack()) { Mso::React::ErrorFrameInfo efi; efi.Method = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.Method()); efi.File = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.File()); @@ -31,24 +25,40 @@ Mso::React::ErrorInfo CreateErrorInfo(IErrorInfo info) { efi.Column = frame.Column(); ei.Callstack.push_back(std::move(efi)); } - return std::move(ei); + return ei; } -inline void RedBoxHandler::ShowNewError(IErrorInfo const &info, ErrorType type) noexcept { - m_redBoxHandler->showNewError( - std::move(CreateErrorInfo(info)), static_cast(static_cast(type))); -} +struct DefaultRedBoxHandler : winrt::implements { + DefaultRedBoxHandler(winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { + auto hostImpl = winrt::get_self(host); + Mso::WeakPtr wkHost(hostImpl->ReactHost()); + m_redBoxHandler = Mso::React::CreateDefaultRedBoxHandler(std::move(wkHost)); + } -inline bool RedBoxHandler::IsDevSupportEnabled() noexcept { - return m_redBoxHandler->isDevSupportEnabled(); -} + void ShowNewError(IRedBoxErrorInfo const &info, RedBoxErrorType type) noexcept { + m_redBoxHandler->showNewError( + CreateErrorInfo(info), static_cast(static_cast(type))); + } -inline void RedBoxHandler::UpdateError(IErrorInfo const &info) noexcept { - m_redBoxHandler->updateError(std::move(CreateErrorInfo(info))); -} + bool IsDevSupportEnabled() noexcept { + return m_redBoxHandler->isDevSupportEnabled(); + } + + void UpdateError(IRedBoxErrorInfo const &info) noexcept { + m_redBoxHandler->updateError(std::move(CreateErrorInfo(info))); + } + + void DismissRedBox() noexcept { + m_redBoxHandler->dismissRedbox(); + } + + private: + std::shared_ptr m_redBoxHandler; +}; -inline void RedBoxHandler::DismissRedBox() noexcept { - m_redBoxHandler->dismissRedbox(); +IRedBoxHandler RedBoxHelper::CreateDefaultHandler( + winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { + return winrt::make(host); } -} // namespace winrt::Microsoft::ReactNative::RedBox::implementation +} // namespace winrt::Microsoft::ReactNative::implementation diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.h b/vnext/Microsoft.ReactNative/RedBoxHandler.h index d99c81eddf5..e8aa4b1f6ac 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.h +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.h @@ -3,34 +3,24 @@ #pragma once -#include "RedBox.RedBoxHandler.g.h" +#include "RedBoxHelper.g.h" namespace Mso::React { struct IRedBoxHandler; } -namespace winrt::Microsoft::ReactNative::RedBox::implementation { +namespace winrt::Microsoft::ReactNative::implementation { -struct RedBoxHandler : RedBoxHandlerT { - RedBoxHandler(ReactNativeHost const &host) noexcept; +struct RedBoxHelper : RedBoxHelperT { + RedBoxHelper() = default; - void ShowNewError(IErrorInfo const &info, ErrorType type) noexcept; - bool IsDevSupportEnabled() noexcept; - void UpdateError(IErrorInfo const &info) noexcept; - void DismissRedBox() noexcept; - - private: - std::shared_ptr m_redBoxHandler; + static IRedBoxHandler CreateDefaultHandler(winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept; }; -} // namespace winrt::Microsoft::ReactNative::RedBox::implementation - -namespace winrt::Microsoft::ReactNative::RedBox::factory_implementation { - -struct RedBoxHandler : RedBoxHandlerT {}; +} // namespace winrt::Microsoft::ReactNative::implementation -} // namespace winrt::Microsoft::ReactNative::RedBox::factory_implementation +namespace winrt::Microsoft::ReactNative::factory_implementation { -namespace winrt::Microsoft::ReactNative::RedBox::implementation { +struct RedBoxHelper : RedBoxHelperT {}; -} // namespace winrt::Microsoft::ReactNative::RedBox::implementation +} // namespace winrt::Microsoft::ReactNative::factory_implementation diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.idl b/vnext/Microsoft.ReactNative/RedBoxHandler.idl index c4d6085434b..0092086437e 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.idl +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.idl @@ -3,40 +3,41 @@ import "ReactNativeHost.idl"; -namespace Microsoft.ReactNative.RedBox { +namespace Microsoft.ReactNative { - enum ErrorType { + enum RedBoxErrorType { JavaScriptFatal, // A JS Exception was thrown or otherwise fatal error JavaScriptSoft, // An error coming from JS that isn't fatal, such as console.error Native, }; - [webhosthidden] interface IErrorFrameInfo { + [webhosthidden] interface IRedBoxErrorFrameInfo { String File { get; }; String Method { get; }; UInt32 Line { get; }; UInt32 Column { get; }; } - - [webhosthidden] interface IErrorInfo { + + [webhosthidden] interface IRedBoxErrorInfo { String Message { get; }; UInt32 Id { get; }; - IVectorView Callstack { get; }; + IVectorView Callstack { get; }; } [webhosthidden] interface IRedBoxHandler { - void ShowNewError(IErrorInfo info, ErrorType type); + void ShowNewError(IRedBoxErrorInfo info, RedBoxErrorType type); Boolean IsDevSupportEnabled { get; }; - void UpdateError(IErrorInfo info); + void UpdateError(IRedBoxErrorInfo info); void DismissRedBox(); } [webhosthidden] [default_interface] - runtimeclass RedBoxHandler : IRedBoxHandler { - RedBoxHandler(Microsoft.ReactNative.ReactNativeHost host); + runtimeclass RedBoxHelper { + RedBoxHelper(); + static IRedBoxHandler CreateDefaultHandler(Microsoft.ReactNative.ReactNativeHost host); } } diff --git a/vnext/ReactWindowsCore/DevSettings.h b/vnext/ReactWindowsCore/DevSettings.h index 44808a5e4d9..061ea4259c4 100644 --- a/vnext/ReactWindowsCore/DevSettings.h +++ b/vnext/ReactWindowsCore/DevSettings.h @@ -5,7 +5,7 @@ #include "Logging.h" #include "MemoryTracker.h" -#include +#include #include #include #include diff --git a/vnext/ReactWindowsCore/RedBoxHandler.h b/vnext/ReactWindowsCore/IRedBoxHandler.h similarity index 100% rename from vnext/ReactWindowsCore/RedBoxHandler.h rename to vnext/ReactWindowsCore/IRedBoxHandler.h diff --git a/vnext/ReactWindowsCore/Modules/ExceptionsManagerModule.h b/vnext/ReactWindowsCore/Modules/ExceptionsManagerModule.h index be44080f41e..80f314a5918 100644 --- a/vnext/ReactWindowsCore/Modules/ExceptionsManagerModule.h +++ b/vnext/ReactWindowsCore/Modules/ExceptionsManagerModule.h @@ -4,7 +4,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj b/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj index c428d90da22..604ca65aa71 100644 --- a/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj +++ b/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj @@ -157,7 +157,7 @@ - + diff --git a/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj.filters b/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj.filters index ad6ca83f025..9d12f2dde3d 100644 --- a/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj.filters +++ b/vnext/ReactWindowsCore/ReactWindowsCore.vcxproj.filters @@ -242,7 +242,7 @@ Header Files\Pch - + Header Files diff --git a/vnext/Scripts/ReactWin32.nuspec b/vnext/Scripts/ReactWin32.nuspec index a61bbe5631d..c54093c805e 100644 --- a/vnext/Scripts/ReactWin32.nuspec +++ b/vnext/Scripts/ReactWin32.nuspec @@ -34,7 +34,7 @@ - + From f7a51163c2a1514c8d0bc2a40c1ad689491982a8 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 11:17:18 -0700 Subject: [PATCH 05/10] minor fix --- packages/playground/windows/playground.sln | 1 + vnext/ReactWindowsCore/ReactWindowsCore.vcxitems | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/playground/windows/playground.sln b/packages/playground/windows/playground.sln index 6c610df8452..62a9c082eae 100644 --- a/packages/playground/windows/playground.sln +++ b/packages/playground/windows/playground.sln @@ -43,6 +43,7 @@ EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9 + ..\..\..\vnext\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4 ..\..\..\vnext\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9 ..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13 ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{6b6aa847-b32f-41ac-9d3b-48a8cdfa8ade}*SharedItemsImports = 4 diff --git a/vnext/ReactWindowsCore/ReactWindowsCore.vcxitems b/vnext/ReactWindowsCore/ReactWindowsCore.vcxitems index 13e56fc783b..3ad3e577e5b 100644 --- a/vnext/ReactWindowsCore/ReactWindowsCore.vcxitems +++ b/vnext/ReactWindowsCore/ReactWindowsCore.vcxitems @@ -174,7 +174,7 @@ - + From 32d3b51fe5bfeef6878dc144a66fa0071e1c503c Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 11:28:22 -0700 Subject: [PATCH 06/10] format fixes --- packages/scripts/formatFiles.js | 1 + vnext/Microsoft.ReactNative/RedBoxHandler.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/scripts/formatFiles.js b/packages/scripts/formatFiles.js index 86c16d088e0..7bce4725db7 100644 --- a/packages/scripts/formatFiles.js +++ b/packages/scripts/formatFiles.js @@ -35,6 +35,7 @@ function queryNoOpenFiles() { if (opened) { console.error('The following files have incorrect formatting:'); console.error(opened); + console.error('Running `yarn format` from the repo root should fix this.'); process.exit(2); } } diff --git a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp index 57ba9987e9b..945bece5241 100644 --- a/vnext/Microsoft.ReactNative/RedBoxHandler.cpp +++ b/vnext/Microsoft.ReactNative/RedBoxHandler.cpp @@ -56,8 +56,7 @@ struct DefaultRedBoxHandler : winrt::implements m_redBoxHandler; }; -IRedBoxHandler RedBoxHelper::CreateDefaultHandler( - winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { +IRedBoxHandler RedBoxHelper::CreateDefaultHandler(winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { return winrt::make(host); } From 2f6d79e1a85a7c81b01ebe816a61aba9f9ceab2c Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 14:21:04 -0700 Subject: [PATCH 07/10] minor change --- vnext/Microsoft.ReactNative/RedBox.cpp | 2 +- vnext/ReactWindowsCore/IRedBoxHandler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index 4463edf165e..e1529de60b3 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -391,7 +391,7 @@ struct DefaultRedBoxHandler : public std::enable_shared_from_thisOptions().DeveloperSettings.IsDevModeEnabled; } diff --git a/vnext/ReactWindowsCore/IRedBoxHandler.h b/vnext/ReactWindowsCore/IRedBoxHandler.h index aeabb4f9f57..fea578a782b 100644 --- a/vnext/ReactWindowsCore/IRedBoxHandler.h +++ b/vnext/ReactWindowsCore/IRedBoxHandler.h @@ -28,7 +28,7 @@ struct ErrorInfo { struct IRedBoxHandler { virtual void showNewError(ErrorInfo &&, ErrorType) = 0; - virtual bool isDevSupportEnabled() = 0; + virtual bool isDevSupportEnabled() const = 0; virtual void updateError(ErrorInfo &&) = 0; virtual void dismissRedbox() = 0; }; From 710cab96528f692b7dc2bdd16d662509fbbbd82a Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 14:48:57 -0700 Subject: [PATCH 08/10] minor fix --- vnext/Microsoft.ReactNative/RedBox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/RedBox.cpp b/vnext/Microsoft.ReactNative/RedBox.cpp index e1529de60b3..699454c743e 100644 --- a/vnext/Microsoft.ReactNative/RedBox.cpp +++ b/vnext/Microsoft.ReactNative/RedBox.cpp @@ -544,7 +544,7 @@ struct RedBoxHandler : public Mso::React::IRedBoxHandler { winrt::make(std::move(info)), static_cast(static_cast(errorType))); } - virtual bool isDevSupportEnabled() override { + virtual bool isDevSupportEnabled() const override { return m_redBoxHandler.IsDevSupportEnabled(); } virtual void updateError(Mso::React::ErrorInfo &&info) override { From a33bf75ec837a5a02209f07948d5fc08cec64c97 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 8 May 2020 15:41:54 -0700 Subject: [PATCH 09/10] minor fix --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index 8fbabcb20ce..b395b555996 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -51,7 +51,7 @@ #include "V8JSIRuntimeHolder.h" #endif // USE_V8 -#include +#include #include #include "ChakraRuntimeHolder.h" From 7ff9c8a66ea8af50f094c07cefc9148cda33208b Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 11 May 2020 06:49:30 -0700 Subject: [PATCH 10/10] minor fix --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index b395b555996..ce74a02918b 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -87,7 +87,7 @@ struct UwpReactRedBoxHandler : Mso::React::IRedBoxHandler { Microsoft::Common::Unicode::Utf8ToUtf16(ss.str().c_str()), L"RedBox Error"); dlg.ShowAsync(); } - virtual bool isDevSupportEnabled() override { + virtual bool isDevSupportEnabled() const override { return true; } virtual void updateError(Mso::React::ErrorInfo &&) override {}