Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose InlineSourceMap property #9566

Merged
8 commits merged into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Expose InlineSourceMap property",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions packages/playground/windows/playground/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void MainPage::OnLoadClick(
host.InstanceSettings().DebuggerBreakOnNextLine(x_BreakOnFirstLineCheckBox().IsChecked().GetBoolean());
host.InstanceSettings().UseFastRefresh(x_UseFastRefreshCheckBox().IsChecked().GetBoolean());
host.InstanceSettings().DebuggerPort(static_cast<uint16_t>(std::stoi(std::wstring(x_DebuggerPort().Text()))));
host.InstanceSettings().InlineSourceMap(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InlineSourceMap

Why is it needed? The 'true' is the default, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true is default. I used this for testing and can revert. Initially planned to add a checkbox in Playground but the top bar is already too wide and wouldn't accommodate it.

host.InstanceSettings().JSIEngineOverride(
static_cast<Microsoft::ReactNative::JSIEngine>(x_JsEngine().SelectedIndex()));
if (!m_bundlerHostname.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct ReactContextStub : implements<ReactContextStub, IReactContext> {
VerifyElseCrashSz(false, "Not implemented");
}

bool InlineSourceMap() noexcept {
VerifyElseCrashSz(false, "Not implemented");
}

hstring JavaScriptBundleFile() noexcept {
VerifyElseCrashSz(false, "Not implemented");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ struct ReactContextMock : implements<ReactContextMock, IReactContext> {
VerifyElseCrashSz(false, "Not implemented");
}

bool InlineSourceMap() noexcept {
VerifyElseCrashSz(false, "Not implemented");
}

hstring JavaScriptBundleFile() noexcept {
VerifyElseCrashSz(false, "Not implemented");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class ReactSettingsSnapshot : IReactSettingsSnapshot
public string SourceBundleHost => throw new NotImplementedException();

public ushort SourceBundlePort => throw new NotImplementedException();

public bool InlineSourceMap => throw new NotImplementedException();
}

class ReactContextMock : IReactContext
Expand Down
4 changes: 4 additions & 0 deletions vnext/Microsoft.ReactNative/IReactContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ uint16_t ReactSettingsSnapshot::SourceBundlePort() const noexcept {
return m_settings->SourceBundlePort();
}

bool ReactSettingsSnapshot::InlineSourceMap() const noexcept {
return m_settings->InlineSourceMap();
}

hstring ReactSettingsSnapshot::JavaScriptBundleFile() const noexcept {
return winrt::to_hstring(m_settings->JavaScriptBundleFile());
}
Expand Down
5 changes: 3 additions & 2 deletions vnext/Microsoft.ReactNative/IReactContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ReactSettingsSnapshot : winrt::implements<ReactSettingsSnapshot, IReactSe
hstring BundleRootPath() const noexcept;
hstring SourceBundleHost() const noexcept;
uint16_t SourceBundlePort() const noexcept;
bool InlineSourceMap() const noexcept;
hstring JavaScriptBundleFile() const noexcept;

public:
Expand Down Expand Up @@ -57,8 +58,8 @@ struct ReactContext : winrt::implements<ReactContext, IReactContext> {
JSValueArgWriter const &paramsArgWriter) noexcept;

public: // IReactContext
// Not part of the public ABI interface
// Internal accessor for within the Microsoft.ReactNative dll to allow calling into internal methods
// Not part of the public ABI interface
// Internal accessor for within the Microsoft.ReactNative dll to allow calling into internal methods
tudorms marked this conversation as resolved.
Show resolved Hide resolved
Mso::React::IReactContext &GetInner() const noexcept;

private:
Expand Down
6 changes: 6 additions & 0 deletions vnext/Microsoft.ReactNative/IReactContext.idl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ namespace Microsoft.ReactNative
"that will be used to load the bundle from.")
UInt16 SourceBundlePort { get; };

DOC_STRING(
"A read-only snapshot of the @ReactInstanceSettings.InlineSourceMap property value "
"at the time when the React instance was created.\n"
"If set, the bundle URL will request the source maps inline (it will improve debugging experience, but for very large bundles it could have a significant performance hit)")
tudorms marked this conversation as resolved.
Show resolved Hide resolved
Boolean InlineSourceMap { get; };

DOC_STRING(
"A read-only snapshot of the @ReactInstanceSettings.JavaScriptBundleFile property value "
"at the time when the React instance was created.\n"
Expand Down
2 changes: 2 additions & 0 deletions vnext/Microsoft.ReactNative/ReactHost/React.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct IReactSettingsSnapshot : IUnknown {
virtual std::string BundleRootPath() const noexcept = 0;
virtual std::string SourceBundleHost() const noexcept = 0;
virtual uint16_t SourceBundlePort() const noexcept = 0;
virtual bool InlineSourceMap() const noexcept = 0;
virtual std::string JavaScriptBundleFile() const noexcept = 0;
virtual bool UseDeveloperSupport() const noexcept = 0;
virtual JSIEngine JsiEngine() const noexcept = 0;
Expand Down Expand Up @@ -149,6 +150,7 @@ struct ReactDevOptions {
//! Specify a value for a component, or leave empty to use the default.
std::string SourceBundleHost; // Host domain (without port) for the bundler server. Default: "localhost".
uint16_t SourceBundlePort{0}; // Host port for the bundler server. Default: "8081".
bool InlineSourceMap{true}; // Request the source map inline
std::string SourceBundleName; // Bundle name without any extension (e.g. "index.win32"). Default: "index.{PLATFORM}"
std::string SourceBundleExtension; // Bundle name extension. Default: ".bundle".

Expand Down
7 changes: 7 additions & 0 deletions vnext/Microsoft.ReactNative/ReactHost/ReactContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ uint16_t ReactSettingsSnapshot::SourceBundlePort() const noexcept {
return 0;
}

bool ReactSettingsSnapshot::InlineSourceMap() const noexcept {
if (auto instance = m_reactInstance.GetStrongPtr()) {
return instance->InlineSourceMap();
}
return 0;
Copy link
Collaborator

@NickGerleman NickGerleman Feb 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0;
return false;
``` #Resolved

}

std::string ReactSettingsSnapshot::JavaScriptBundleFile() const noexcept {
if (auto instance = m_reactInstance.GetStrongPtr()) {
return instance->JavaScriptBundleFile();
Expand Down
1 change: 1 addition & 0 deletions vnext/Microsoft.ReactNative/ReactHost/ReactContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ReactSettingsSnapshot final : public Mso::UnknownObject<IReactSettingsSnap
std::string BundleRootPath() const noexcept override;
std::string SourceBundleHost() const noexcept override;
uint16_t SourceBundlePort() const noexcept override;
bool InlineSourceMap() const noexcept override;
std::string JavaScriptBundleFile() const noexcept override;
bool UseDeveloperSupport() const noexcept override;
JSIEngine JsiEngine() const noexcept override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ void ReactInstanceWin::Initialize() noexcept {
devSettings->useJITCompilation = m_options.EnableJITCompilation;
devSettings->sourceBundleHost = SourceBundleHost();
devSettings->sourceBundlePort = SourceBundlePort();
devSettings->inlineSourceMap = InlineSourceMap();
devSettings->debugBundlePath = DebugBundlePath();
devSettings->liveReloadCallback = GetLiveReloadCallback();
devSettings->errorCallback = GetErrorCallback();
Expand Down Expand Up @@ -407,7 +408,6 @@ void ReactInstanceWin::Initialize() noexcept {
case JSIEngine::Hermes:
devSettings->jsiRuntimeHolder =
std::make_shared<facebook::react::HermesRuntimeHolder>(devSettings, m_jsMessageThread.Load());
devSettings->inlineSourceMap = false;
break;
case JSIEngine::V8:
#if defined(USE_V8)
Expand Down Expand Up @@ -1021,6 +1021,10 @@ uint16_t ReactInstanceWin::SourceBundlePort() const noexcept {
: facebook::react::DevServerHelper::DefaultPackagerPort;
}

bool ReactInstanceWin::InlineSourceMap() const noexcept {
return m_options.DeveloperSettings.InlineSourceMap;
}

JSIEngine ReactInstanceWin::JsiEngine() const noexcept {
return m_options.JsiEngine();
}
Expand Down
1 change: 1 addition & 0 deletions vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ReactInstanceWin final : public Mso::ActiveObject<IReactInstanceInternal>
std::string BundleRootPath() const noexcept;
std::string SourceBundleHost() const noexcept;
uint16_t SourceBundlePort() const noexcept;
bool InlineSourceMap() const noexcept;
std::string JavaScriptBundleFile() const noexcept;
bool UseDeveloperSupport() const noexcept;
JSIEngine JsiEngine() const noexcept;
Expand Down
12 changes: 12 additions & 0 deletions vnext/Microsoft.ReactNative/ReactInstanceSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ struct ReactInstanceSettings : ReactInstanceSettingsT<ReactInstanceSettings> {
uint16_t SourceBundlePort() noexcept;
void SourceBundlePort(uint16_t value) noexcept;

bool InlineSourceMap() noexcept;
void InlineSourceMap(bool value) noexcept;

JSIEngine JSIEngineOverride() noexcept;
void JSIEngineOverride(JSIEngine value) noexcept;

Expand Down Expand Up @@ -174,6 +177,7 @@ struct ReactInstanceSettings : ReactInstanceSettingsT<ReactInstanceSettings> {
hstring m_sourceBundleHost{};
hstring m_debuggerRuntimeName{};
uint16_t m_sourceBundlePort{0};
bool m_inlineSourceMap{true};
tudorms marked this conversation as resolved.
Show resolved Hide resolved
LogHandler m_nativeLogger{nullptr};

#if USE_HERMES
Expand Down Expand Up @@ -308,6 +312,14 @@ inline void ReactInstanceSettings::SourceBundlePort(uint16_t value) noexcept {
m_sourceBundlePort = value;
}

inline bool ReactInstanceSettings::InlineSourceMap() noexcept {
return m_inlineSourceMap;
}

inline void ReactInstanceSettings::InlineSourceMap(bool value) noexcept {
m_inlineSourceMap = value;
}

inline JSIEngine ReactInstanceSettings::JSIEngineOverride() noexcept {
return m_jSIEngineOverride;
}
Expand Down
6 changes: 6 additions & 0 deletions vnext/Microsoft.ReactNative/ReactInstanceSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ namespace Microsoft.ReactNative
DOC_DEFAULT("8081")
UInt16 SourceBundlePort { get; set; };

DOC_STRING(
"When using a @.UseFastRefresh, @.UseLiveReload, or @.UseWebDebugger this controls whether the bundle URL requests inline source maps."
tudorms marked this conversation as resolved.
Show resolved Hide resolved
"If set, the bundle URL will request the source maps inline (it will improve debugging experience, but for very large bundles it could have a significant performance hit)")
tudorms marked this conversation as resolved.
Show resolved Hide resolved
DOC_DEFAULT("true")
Boolean InlineSourceMap { get; set; };
tudorms marked this conversation as resolved.
Show resolved Hide resolved

DOC_STRING(
"The @JSIEngine override to be used with the React instance.\n"
"In order for the override to work, Microsoft.ReactNative must be compiled with support of that engine. "
Expand Down
1 change: 1 addition & 0 deletions vnext/Microsoft.ReactNative/ReactNativeHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ IAsyncAction ReactNativeHost::ReloadInstance() noexcept {
}
reactOptions.DeveloperSettings.SourceBundleHost = to_string(m_instanceSettings.SourceBundleHost());
reactOptions.DeveloperSettings.SourceBundlePort = m_instanceSettings.SourceBundlePort();
reactOptions.DeveloperSettings.InlineSourceMap = m_instanceSettings.InlineSourceMap();

reactOptions.ByteCodeFileUri = to_string(m_instanceSettings.ByteCodeFileUri());
reactOptions.EnableByteCodeCaching = m_instanceSettings.EnableByteCodeCaching();
Expand Down