Skip to content

Commit

Permalink
Fix FashRefresh when not using WebDebugger (#7927)
Browse files Browse the repository at this point in the history
  • Loading branch information
acoates-ms committed Jun 3, 2021
1 parent d2047c9 commit ad1302b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix FashRefresh when not using WebDebugger",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion vnext/Shared/DevSupportManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ std::pair<std::string, bool> GetJavaScriptFromServer(
const uint16_t sourceBundlePort,
const std::string &jsBundleName,
const std::string &platform,
bool dev,
bool hot,
bool inlineSourceMap) {
auto bundleUrl = facebook::react::DevServerHelper::get_BundleUrl(
sourceBundleHost, sourceBundlePort, jsBundleName, platform, true /*dev*/, false /*hot*/, inlineSourceMap);
sourceBundleHost, sourceBundlePort, jsBundleName, platform, dev, hot, inlineSourceMap);
try {
return GetJavaScriptFromServerAsync(bundleUrl).get();
} catch (winrt::hresult_error const &e) {
Expand Down
2 changes: 2 additions & 0 deletions vnext/Shared/DevSupportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ std::pair<std::string, bool> GetJavaScriptFromServer(
const uint16_t sourceBundlePort,
const std::string &jsBundleName,
const std::string &platform,
bool dev,
bool hot,
bool inlineSourceMap);

class DevSupportManager final : public facebook::react::IDevSupportManager {
Expand Down
27 changes: 18 additions & 9 deletions vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace fs = std::filesystem;
// forward declaration.
namespace facebook::react::tracing {
void initializeETW();
void initializeJSHooks(facebook::jsi::Runtime &runtime);
void initializeJSHooks(facebook::jsi::Runtime &runtime, bool isProfiling);
} // namespace facebook::react::tracing

namespace {
Expand Down Expand Up @@ -155,11 +155,6 @@ namespace facebook {
namespace react {

namespace {
void runtimeInstaller([[maybe_unused]] jsi::Runtime &runtime) {
#ifdef ENABLE_JS_SYSTRACE_TO_ETW
facebook::react::tracing::initializeJSHooks(runtime);
#endif
}

class OJSIExecutorFactory : public JSExecutorFactory {
public:
Expand Down Expand Up @@ -192,24 +187,34 @@ class OJSIExecutorFactory : public JSExecutorFactory {
}

return std::make_unique<JSIExecutor>(
runtimeHolder_->getRuntime(), std::move(delegate), JSIExecutor::defaultTimeoutInvoker, runtimeInstaller);
runtimeHolder_->getRuntime(),
std::move(delegate),
JSIExecutor::defaultTimeoutInvoker,
[isProfiling = isProfilingEnabled_]([[maybe_unused]] jsi::Runtime &runtime) {
#ifdef ENABLE_JS_SYSTRACE_TO_ETW
facebook::react::tracing::initializeJSHooks(runtime, isProfiling);
#endif
});
}

OJSIExecutorFactory(
std::shared_ptr<jsi::RuntimeHolderLazyInit> runtimeHolder,
NativeLoggingHook loggingHook,
std::shared_ptr<TurboModuleRegistry> turboModuleRegistry,
bool isProfilingEnabled,
std::shared_ptr<CallInvoker> jsCallInvoker) noexcept
: runtimeHolder_{std::move(runtimeHolder)},
loggingHook_{std::move(loggingHook)},
turboModuleRegistry_{std::move(turboModuleRegistry)},
jsCallInvoker_{std::move(jsCallInvoker)} {}
jsCallInvoker_{std::move(jsCallInvoker)},
isProfilingEnabled_{isProfilingEnabled} {}

private:
std::shared_ptr<jsi::RuntimeHolderLazyInit> runtimeHolder_;
std::shared_ptr<TurboModuleRegistry> turboModuleRegistry_;
std::shared_ptr<CallInvoker> jsCallInvoker_;
NativeLoggingHook loggingHook_;
bool isProfilingEnabled_;
};

} // namespace
Expand Down Expand Up @@ -347,6 +352,7 @@ InstanceImpl::InstanceImpl(
m_devSettings->jsiRuntimeHolder,
m_devSettings->loggingCallback,
m_turboModuleRegistry,
!m_devSettings->useFastRefresh,
m_innerInstance->getJSCallInvoker());
} else if (m_devSettings->jsiEngineOverride != JSIEngineOverride::Default) {
switch (m_devSettings->jsiEngineOverride) {
Expand Down Expand Up @@ -393,6 +399,7 @@ InstanceImpl::InstanceImpl(
m_devSettings->jsiRuntimeHolder,
m_devSettings->loggingCallback,
m_turboModuleRegistry,
!m_devSettings->useFastRefresh,
m_innerInstance->getJSCallInvoker());
} else {
// We use the older non-JSI ChakraExecutor pipeline as a fallback as of
Expand Down Expand Up @@ -474,6 +481,8 @@ void InstanceImpl::loadBundleInternal(std::string &&jsBundleRelativePath, bool s
m_devSettings->sourceBundlePort,
m_devSettings->debugBundlePath.empty() ? jsBundleRelativePath : m_devSettings->debugBundlePath,
m_devSettings->platformName,
true /* dev */,
m_devSettings->useFastRefresh,
m_devSettings->inlineSourceMap);

if (!success) {
Expand Down Expand Up @@ -566,7 +575,7 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
m_devSettings->debugBundlePath,
m_devSettings->platformName,
true /*dev*/,
false /*hot*/,
m_devSettings->useFastRefresh,
m_devSettings->inlineSourceMap)
: std::string();
modules.push_back(std::make_unique<CxxNativeModule>(
Expand Down
4 changes: 2 additions & 2 deletions vnext/Shared/tracing/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ void counterJSHook(uint64_t tag, const std::string &profile_name, int value) {
TraceLoggingInt64(value, "value"));
}

void initializeJSHooks(jsi::Runtime &runtime) {
void initializeJSHooks(jsi::Runtime &runtime, bool isProfiling) {
// TODO:: Assess the performance impact of hooking up the JS trace events. Especially when the tracing is not enabled.
// If significant, this should be put under flag based on devsettings

runtime.global().setProperty(runtime, "__RCTProfileIsProfiling", true);
runtime.global().setProperty(runtime, "__RCTProfileIsProfiling", isProfiling);

runtime.global().setProperty(
runtime,
Expand Down

0 comments on commit ad1302b

Please sign in to comment.