react-native-windows 0.71.40 → 0.71.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -548,6 +548,9 @@ void ReactInstanceWin::Initialize() noexcept {
548
548
  auto omitNetCxxPropName = ReactPropertyBagHelper::GetName(nullptr, L"OmitNetworkingCxxModules");
549
549
  auto omitNetCxxPropValue = m_options.Properties.Get(omitNetCxxPropName);
550
550
  devSettings->omitNetworkingCxxModules = winrt::unbox_value_or(omitNetCxxPropValue, false);
551
+ auto useWebSocketTurboModulePropName = ReactPropertyBagHelper::GetName(nullptr, L"UseWebSocketTurboModule");
552
+ auto useWebSocketTurboModulePropValue = m_options.Properties.Get(useWebSocketTurboModulePropName);
553
+ devSettings->useWebSocketTurboModule = winrt::unbox_value_or(useWebSocketTurboModulePropValue, false);
551
554
  auto bundleRootPath = devSettings->bundleRootPath;
552
555
  auto instanceWrapper = facebook::react::CreateReactInstance(
553
556
  std::shared_ptr<facebook::react::Instance>(strongThis->m_instance.Load()),
@@ -10,11 +10,11 @@
10
10
  -->
11
11
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
12
  <PropertyGroup>
13
- <ReactNativeWindowsVersion>0.71.40</ReactNativeWindowsVersion>
13
+ <ReactNativeWindowsVersion>0.71.42</ReactNativeWindowsVersion>
14
14
  <ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
15
15
  <ReactNativeWindowsMinor>71</ReactNativeWindowsMinor>
16
- <ReactNativeWindowsPatch>40</ReactNativeWindowsPatch>
16
+ <ReactNativeWindowsPatch>42</ReactNativeWindowsPatch>
17
17
  <ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
18
- <ReactNativeWindowsCommitId>75b42021dbf4734610a01134b86399210b2b62ed</ReactNativeWindowsCommitId>
18
+ <ReactNativeWindowsCommitId>d755604625a3cf4b704edb607e823f0f7367ebb5</ReactNativeWindowsCommitId>
19
19
  </PropertyGroup>
20
20
  </Project>
@@ -102,6 +102,9 @@ struct DevSettings {
102
102
 
103
103
  // Transitory. Used to indicate whether or not to load networking types in the default Cxx module registry.
104
104
  bool omitNetworkingCxxModules{false};
105
+
106
+ // OC:8368383 - Memory leak under investigation.
107
+ bool useWebSocketTurboModule{false};
105
108
  };
106
109
 
107
110
  } // namespace react
@@ -52,6 +52,9 @@ using Microsoft::React::Networking::IWebSocketResource;
52
52
 
53
53
  constexpr char s_moduleName[] = "WebSocketModule";
54
54
  constexpr wchar_t s_moduleNameW[] = L"WebSocketModule";
55
+ constexpr wchar_t s_proxyNameW[] = L"WebSocketModule.Proxy";
56
+ constexpr wchar_t s_sharedStateNameW[] = L"WebSocketModule.SharedState";
57
+ constexpr wchar_t s_contentHandlerNameW[] = L"BlobModule.ContentHandler";
55
58
 
56
59
  msrn::ReactModuleProvider s_moduleProvider = msrn::MakeTurboModuleProvider<Microsoft::React::WebSocketTurboModule>();
57
60
 
@@ -119,7 +122,7 @@ GetOrCreateWebSocket(int64_t id, string &&url, weak_ptr<WebSocketModule::SharedS
119
122
  auto args = msrn::JSValueObject{{"id", id}, {"type", isBinary ? "binary" : "text"}};
120
123
  shared_ptr<Microsoft::React::IWebSocketModuleContentHandler> contentHandler;
121
124
  auto propId = ReactPropertyId<ReactNonAbiValue<weak_ptr<Microsoft::React::IWebSocketModuleContentHandler>>>{
122
- L"BlobModule.ContentHandler"};
125
+ s_contentHandlerNameW};
123
126
  if (auto prop = propBag.Get(propId))
124
127
  contentHandler = prop.Value().lock();
125
128
 
@@ -171,11 +174,11 @@ WebSocketModule::WebSocketModule(winrt::Windows::Foundation::IInspectable const
171
174
 
172
175
  auto propBag = ReactPropertyBag{m_sharedState->InspectableProps.try_as<IReactPropertyBag>()};
173
176
 
174
- auto proxyPropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IWebSocketModuleProxy>>>{L"WebSocketModule.Proxy"};
177
+ auto proxyPropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IWebSocketModuleProxy>>>{s_proxyNameW};
175
178
  auto proxy = weak_ptr<IWebSocketModuleProxy>{m_proxy};
176
179
  propBag.Set(proxyPropId, std::move(proxy));
177
180
 
178
- auto statePropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<SharedState>>>{L"WebSocketModule.SharedState"};
181
+ auto statePropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<SharedState>>>{s_sharedStateNameW};
179
182
  auto state = weak_ptr<SharedState>{m_sharedState};
180
183
  propBag.Set(statePropId, std::move(state));
181
184
  }
@@ -309,10 +312,9 @@ vector<facebook::xplat::module::CxxModule::Method> WebSocketModule::getMethods()
309
312
  WebSocketModuleProxy::WebSocketModuleProxy(IInspectable const &inspectableProperties) noexcept
310
313
  : m_inspectableProps{inspectableProperties} {}
311
314
 
312
- void WebSocketModuleProxy::SendBinary(std::string &&base64String, int64_t id) noexcept /*override*/ {
315
+ void WebSocketModuleProxy::SendBinary(string &&base64String, int64_t id) noexcept /*override*/ {
313
316
  auto propBag = ReactPropertyBag{m_inspectableProps.try_as<IReactPropertyBag>()};
314
- auto sharedPropId =
315
- ReactPropertyId<ReactNonAbiValue<weak_ptr<WebSocketModule::SharedState>>>{L"WebSocketModule.SharedState"};
317
+ auto sharedPropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<WebSocketModule::SharedState>>>{s_sharedStateNameW};
316
318
  auto state = propBag.Get(sharedPropId).Value();
317
319
 
318
320
  weak_ptr weakWs = GetOrCreateWebSocket(id, {}, std::move(state));
@@ -353,8 +355,7 @@ shared_ptr<IWebSocketResource> WebSocketTurboModule::CreateResource(int64_t id,
353
355
  rc->SetOnMessage([id, context = m_context](size_t length, const string &message, bool isBinary) {
354
356
  auto args = msrn::JSValueObject{{"id", id}, {"type", isBinary ? "binary" : "text"}};
355
357
  shared_ptr<IWebSocketModuleContentHandler> contentHandler;
356
- auto propId =
357
- ReactPropertyId<ReactNonAbiValue<weak_ptr<IWebSocketModuleContentHandler>>>{L"BlobModule.ContentHandler"};
358
+ auto propId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IWebSocketModuleContentHandler>>>{s_contentHandlerNameW};
358
359
  auto propBag = context.Properties();
359
360
  if (auto prop = propBag.Get(propId))
360
361
  contentHandler = prop.Value().lock();
@@ -396,6 +397,11 @@ shared_ptr<IWebSocketResource> WebSocketTurboModule::CreateResource(int64_t id,
396
397
 
397
398
  void WebSocketTurboModule::Initialize(msrn::ReactContext const &reactContext) noexcept {
398
399
  m_context = reactContext.Handle();
400
+ m_proxy = std::make_shared<WebSocketTurboModuleProxy>(m_resourceMap);
401
+
402
+ auto proxyPropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IWebSocketModuleProxy>>>{s_proxyNameW};
403
+ auto proxy = weak_ptr<IWebSocketModuleProxy>{m_proxy};
404
+ m_context.Properties().Set(proxyPropId, std::move(proxy));
399
405
  }
400
406
 
401
407
  void WebSocketTurboModule::Connect(
@@ -487,6 +493,29 @@ void WebSocketTurboModule::RemoveListeners(double /*count*/) noexcept {}
487
493
 
488
494
  #pragma endregion WebSocketTurboModule
489
495
 
496
+ #pragma region WebSocketTurboModuleProxy
497
+
498
+ WebSocketTurboModuleProxy::WebSocketTurboModuleProxy(
499
+ std::unordered_map<double, shared_ptr<IWebSocketResource>> &resourceMap) noexcept
500
+ : m_resourceMap{resourceMap} {}
501
+
502
+ #pragma endregion WebSocketTurboModuleProxy
503
+
504
+ void WebSocketTurboModuleProxy::SendBinary(string &&base64String, int64_t id) noexcept /*override*/
505
+ {
506
+ auto rcItr = m_resourceMap.find(static_cast<double>(id));
507
+ if (rcItr == m_resourceMap.cend()) {
508
+ return;
509
+ }
510
+
511
+ weak_ptr<IWebSocketResource> weakRc = (*rcItr).second;
512
+ if (auto rc = weakRc.lock()) {
513
+ rc->SendBinary(std::move(base64String));
514
+ }
515
+ }
516
+
517
+ #pragma region WebSocketTurboModule
518
+
490
519
  /*extern*/ const char *GetWebSocketModuleName() noexcept {
491
520
  return s_moduleName;
492
521
  }
@@ -10,6 +10,20 @@
10
10
 
11
11
  namespace Microsoft::React {
12
12
 
13
+ class WebSocketTurboModuleProxy final : public IWebSocketModuleProxy {
14
+ std::unordered_map<double, std::shared_ptr<Networking::IWebSocketResource>> &m_resourceMap;
15
+
16
+ public:
17
+ WebSocketTurboModuleProxy(
18
+ std::unordered_map<double, std::shared_ptr<Networking::IWebSocketResource>> &resourceMap) noexcept;
19
+
20
+ #pragma region IWebSocketModuleProxy
21
+
22
+ void SendBinary(std::string &&base64String, int64_t id) noexcept override;
23
+
24
+ #pragma endregion
25
+ };
26
+
13
27
  REACT_MODULE(WebSocketTurboModule, L"WebSocketModule")
14
28
  struct WebSocketTurboModule {
15
29
  using ModuleSpec = ReactNativeSpecs::WebSocketModuleSpec;
@@ -47,6 +61,11 @@ struct WebSocketTurboModule {
47
61
 
48
62
  winrt::Microsoft::ReactNative::ReactContext m_context;
49
63
  std::unordered_map<double, std::shared_ptr<Networking::IWebSocketResource>> m_resourceMap;
64
+
65
+ /// <summary>
66
+ /// Exposes a subset of the module's methods.
67
+ /// </summary>
68
+ std::shared_ptr<IWebSocketModuleProxy> m_proxy;
50
69
  };
51
70
 
52
71
  } // namespace Microsoft::React
@@ -556,14 +556,18 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
556
556
  // If this code is enabled, we will have unused module instances.
557
557
  // Also, MSRN has a different property bag mechanism incompatible with this method's transitionalProps variable.
558
558
  #if (defined(_MSC_VER) && !defined(WINRT))
559
- // Applications using the Windows ABI feature should loade the networking TurboModule variants instead.
560
- if (!m_devSettings->omitNetworkingCxxModules) {
559
+
560
+ // OC:8368383 - Memory leak under investigation.
561
+ if (!m_devSettings->useWebSocketTurboModule) {
561
562
  modules.push_back(std::make_unique<CxxNativeModule>(
562
563
  m_innerInstance,
563
564
  Microsoft::React::GetWebSocketModuleName(),
564
565
  [transitionalProps]() { return Microsoft::React::CreateWebSocketModule(transitionalProps); },
565
566
  nativeQueue));
567
+ }
566
568
 
569
+ // Applications using the Windows ABI feature should loade the networking TurboModule variants instead.
570
+ if (!m_devSettings->omitNetworkingCxxModules) {
567
571
  // Use in case the host app provides its a non-Blob-compatilbe HTTP module.
568
572
  if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) {
569
573
  modules.push_back(std::make_unique<CxxNativeModule>(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.71.40",
3
+ "version": "0.71.42",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",