diff --git a/change/react-native-windows-2020-03-27-11-52-38-dd.json b/change/react-native-windows-2020-03-27-11-52-38-dd.json new file mode 100644 index 00000000000..5a5e620a47f --- /dev/null +++ b/change/react-native-windows-2020-03-27-11-52-38-dd.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Fix direct debugging", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-03-27T18:52:38.219Z" +} \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp index 373fc4c9641..6494964c877 100644 --- a/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +++ b/vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp @@ -171,6 +171,7 @@ void ReactInstanceWin::Initialize() noexcept { devSettings->debuggerPort = m_options.DeveloperSettings.DebuggerPort; devSettings->debuggerRuntimeName = m_options.DeveloperSettings.DebuggerRuntimeName; devSettings->useWebDebugger = m_options.DeveloperSettings.UseWebDebugger; + devSettings->useFastRefresh = m_options.DeveloperSettings.UseFastRefresh; // devSettings->memoryTracker = GetMemoryTracker(); devSettings->bundleRootPath = m_options.BundleRootPath.empty() ? "ms-appx:///Bundle/" : m_options.BundleRootPath; @@ -313,7 +314,22 @@ void ReactInstanceWin::LoadJSBundles() noexcept { // The OnReactInstanceLoaded internally only accepts the first call and ignores others. // - if (!m_options.DeveloperSettings.UseWebDebugger) { + if (m_options.DeveloperSettings.UseWebDebugger || m_options.DeveloperSettings.UseFastRefresh) { + // Getting bundle from the packager, so do everything async. + auto instanceWrapper = m_instanceWrapper.LoadWithLock(); + instanceWrapper->loadBundle(Mso::Copy(m_options.Identity)); + + m_jsMessageThread.Load()->runOnQueue([ + weakThis = Mso::WeakPtr{this}, + loadCallbackGuard = Mso::MakeMoveOnCopyWrapper(LoadedCallbackGuard{*this}) + ]() noexcept { + if (auto strongThis = weakThis.GetStrongPtr()) { + if (strongThis->State() != ReactInstanceState::HasError) { + strongThis->OnReactInstanceLoaded(Mso::ErrorCode{}); + } + } + }); + } else { m_jsMessageThread.Load()->runOnQueue([ weakThis = Mso::WeakPtr{this}, loadCallbackGuard = Mso::MakeMoveOnCopyWrapper(LoadedCallbackGuard{*this}) @@ -339,21 +355,6 @@ void ReactInstanceWin::LoadJSBundles() noexcept { strongThis->OnReactInstanceLoaded(Mso::ErrorCode{}); } }); - } else { - // Web Debugging - auto instanceWrapper = m_instanceWrapper.LoadWithLock(); - instanceWrapper->loadBundle(Mso::Copy(m_options.Identity)); - - m_jsMessageThread.Load()->runOnQueue([ - weakThis = Mso::WeakPtr{this}, - loadCallbackGuard = Mso::MakeMoveOnCopyWrapper(LoadedCallbackGuard{*this}) - ]() noexcept { - if (auto strongThis = weakThis.GetStrongPtr()) { - if (strongThis->State() != ReactInstanceState::HasError) { - strongThis->OnReactInstanceLoaded(Mso::ErrorCode{}); - } - } - }); } } diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index fc6be64b0c0..0574a0762d3 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -519,6 +519,7 @@ void ReactRootControl::ShowDeveloperMenu() noexcept { winrt::auto_revoke, [this](auto const & /*sender*/, winrt::RoutedEventArgs const & /*args*/) noexcept { DismissDeveloperMenu(); m_useWebDebugger = !m_useWebDebugger; + m_directDebugging = false; // Remote debugging is incompatible with direct debugging ReloadHost(); }); @@ -527,11 +528,12 @@ void ReactRootControl::ShowDeveloperMenu() noexcept { winrt::auto_revoke, [this](auto const & /*sender*/, winrt::RoutedEventArgs const & /*args*/) noexcept { DismissDeveloperMenu(); m_directDebugging = !m_directDebugging; + m_useWebDebugger = false; // Remote debugging is incompatible with direct debugging ReloadHost(); }); breakOnNextLineText.Text(m_breakOnNextLine ? L"Disable Break on First Line" : L"Enable Break on First Line"); - m_breakOnNextLineRevoker = directDebugButton.Click( + m_breakOnNextLineRevoker = breakOnNextLineButton.Click( winrt::auto_revoke, [this](auto const & /*sender*/, winrt::RoutedEventArgs const & /*args*/) noexcept { DismissDeveloperMenu(); m_breakOnNextLine = !m_breakOnNextLine; diff --git a/vnext/ReactWindowsCore/DevSettings.h b/vnext/ReactWindowsCore/DevSettings.h index 28ed1f70887..44808a5e4d9 100644 --- a/vnext/ReactWindowsCore/DevSettings.h +++ b/vnext/ReactWindowsCore/DevSettings.h @@ -81,6 +81,8 @@ struct DevSettings { /// is loaded. bool useWebDebugger{false}; + bool useFastRefresh{false}; + // Enables ChakraCore console redirection to debugger bool debuggerConsoleRedirection{false}; diff --git a/vnext/Shared/OInstance.cpp b/vnext/Shared/OInstance.cpp index 0e617ef27df..35b3552dfff 100644 --- a/vnext/Shared/OInstance.cpp +++ b/vnext/Shared/OInstance.cpp @@ -510,7 +510,7 @@ void InstanceImpl::loadBundleInternal(std::string &&jsBundleRelativePath, bool s m_devSettings->errorCallback(e.what()); return; } - } else if (m_devSettings->liveReloadCallback != nullptr) { + } else if (m_devSettings->liveReloadCallback != nullptr || m_devSettings->useFastRefresh) { auto jsBundleString = m_devManager->GetJavaScriptFromServer( m_devSettings->debugHost, jsBundleRelativePath, m_devSettings->platformName);