react-native-windows 0.0.0-canary.781 → 0.0.0-canary.783

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.
@@ -14,6 +14,7 @@
14
14
  #include <ReactPropertyBag.h>
15
15
  #include <Utils/Helpers.h>
16
16
  #include <dispatchQueue/dispatchQueue.h>
17
+ #include <eventWaitHandle/eventWaitHandle.h>
17
18
  #include <react/renderer/core/LayoutConstraints.h>
18
19
  #include <react/renderer/core/LayoutContext.h>
19
20
  #include <winrt/Microsoft.ReactNative.Composition.h>
@@ -64,21 +65,24 @@ void CompositionReactViewInstance::InitRootView(
64
65
  .Get(winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIDispatcherProperty())
65
66
  .try_as<IReactDispatcher>();
66
67
 
67
- PostInUIQueue([context{std::move(context)}, viewOptions{std::move(viewOptions)}](
68
- winrt::com_ptr<winrt::Microsoft::ReactNative::implementation::CompositionRootView>
69
- &rootControl) mutable noexcept {
68
+ assert(m_uiDispatcher.HasThreadAccess());
69
+ if (auto rootControl = m_weakRootControl.get()) {
70
70
  rootControl->InitRootView(std::move(context), std::move(viewOptions));
71
- });
71
+ }
72
72
  }
73
73
 
74
74
  void CompositionReactViewInstance::UpdateRootView() noexcept {
75
- PostInUIQueue([](winrt::com_ptr<winrt::Microsoft::ReactNative::implementation::CompositionRootView>
76
- &rootControl) mutable noexcept { rootControl->UpdateRootView(); });
75
+ assert(m_uiDispatcher.HasThreadAccess());
76
+ if (auto rootControl = m_weakRootControl.get()) {
77
+ rootControl->UpdateRootView();
78
+ }
77
79
  }
78
80
 
79
81
  void CompositionReactViewInstance::UninitRootView() noexcept {
80
- PostInUIQueue([](winrt::com_ptr<winrt::Microsoft::ReactNative::implementation::CompositionRootView>
81
- &rootControl) mutable noexcept { rootControl->UninitRootView(); });
82
+ assert(m_uiDispatcher.HasThreadAccess());
83
+ if (auto rootControl = m_weakRootControl.get()) {
84
+ rootControl->UninitRootView();
85
+ }
82
86
  }
83
87
 
84
88
  //===========================================================================
@@ -355,6 +359,13 @@ void CompositionRootView::UninitRootView() noexcept {
355
359
 
356
360
  m_context.CallJSFunction(L"ReactFabric", L"unmountComponentAtNode", GetTag());
357
361
 
362
+ // This is needed to ensure that the unmount JS logic is completed before the the instance is shutdown during
363
+ // instance destruction. Aligns with similar code in ReactInstanceWin::DetachRootView for paper Future: Instead this
364
+ // method should return a Promise, which should be resolved when the JS logic is complete.
365
+ Mso::ManualResetEvent mre;
366
+ m_context.JSDispatcher().Post([&]() { mre.Set(); });
367
+ mre.Wait();
368
+
358
369
  // Paper version gives the JS thread time to finish executing - Is this needed?
359
370
  // m_jsMessageThread.Load()->runOnQueueSync([]() {});
360
371
  }
@@ -4,6 +4,7 @@
4
4
  #include "pch.h"
5
5
  #include "CompositionUIService.h"
6
6
  #include "Composition.CompositionUIService.g.cpp"
7
+ #include <QuirkSettings.h>
7
8
 
8
9
  #include <ReactPropertyBag.h>
9
10
 
@@ -18,6 +19,11 @@ void CompositionUIService::SetCompositionContext(
18
19
  IReactPropertyBag const &properties,
19
20
  ICompositionContext const &compositionContext) noexcept {
20
21
  ReactPropertyBag(properties).Set(CompositionContextPropertyId(), compositionContext);
22
+ // Default to using Bridgeless mode when using fabric
23
+ /*
24
+ winrt::Microsoft::ReactNative::implementation::QuirkSettings::SetIsBridgeless(
25
+ ReactPropertyBag(properties), !!compositionContext);
26
+ */
21
27
  }
22
28
 
23
29
  ICompositionContext CompositionUIService::GetCompositionContext(const IReactPropertyBag &properties) noexcept {
@@ -87,6 +87,12 @@ winrt::Microsoft::ReactNative::ReactPropertyId<bool> IsBridgelessProperty() noex
87
87
  return properties.Get(IsBridgelessProperty()).value_or(false);
88
88
  }
89
89
 
90
+ /*static*/ void QuirkSettings::SetIsBridgeless(
91
+ const winrt::Microsoft::ReactNative::ReactPropertyBag &properties,
92
+ bool value) noexcept {
93
+ properties.Set(IsBridgelessProperty(), value);
94
+ }
95
+
90
96
  #pragma region IDL interface
91
97
 
92
98
  /*static*/ void QuirkSettings::SetMatchAndroidAndIOSStretchBehavior(
@@ -40,6 +40,7 @@ struct QuirkSettings : QuirkSettingsT<QuirkSettings> {
40
40
  winrt::Microsoft::ReactNative::ReactPropertyBag properties) noexcept;
41
41
 
42
42
  static bool GetIsBridgeless(winrt::Microsoft::ReactNative::ReactPropertyBag properties) noexcept;
43
+ static void SetIsBridgeless(const winrt::Microsoft::ReactNative::ReactPropertyBag &properties, bool value) noexcept;
43
44
 
44
45
  #pragma region Public API - part of IDL interface
45
46
  static void SetMatchAndroidAndIOSStretchBehavior(
@@ -529,6 +529,28 @@ std::shared_ptr<facebook::react::DevSettings> ReactInstanceWin::CreateDevSetting
529
529
  return devSettings;
530
530
  }
531
531
 
532
+ Mso::DispatchQueueSettings CreateDispatchQueueSettings(
533
+ const winrt::Microsoft::ReactNative::IReactNotificationService &service) {
534
+ Mso::DispatchQueueSettings queueSettings{};
535
+ queueSettings.TaskStarting = [service](Mso::DispatchQueue const &) noexcept {
536
+ service.SendNotification(
537
+ winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherTaskStartingEventName(), nullptr, nullptr);
538
+ };
539
+ queueSettings.IdleWaitStarting = [service](Mso::DispatchQueue const &) noexcept {
540
+ service.SendNotification(
541
+ winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherIdleWaitStartingEventName(),
542
+ nullptr,
543
+ nullptr);
544
+ };
545
+ queueSettings.IdleWaitCompleted = [service](Mso::DispatchQueue const &) noexcept {
546
+ service.SendNotification(
547
+ winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherIdleWaitCompletedEventName(),
548
+ nullptr,
549
+ nullptr);
550
+ };
551
+ return queueSettings;
552
+ }
553
+
532
554
  #ifdef USE_FABRIC
533
555
  void ReactInstanceWin::InitializeBridgeless() noexcept {
534
556
  InitUIQueue();
@@ -550,12 +572,15 @@ void ReactInstanceWin::InitializeBridgeless() noexcept {
550
572
  // null moduleProvider since native modules are not supported in bridgeless
551
573
  LoadModules(devSettings, nullptr, m_options.TurboModuleProvider);
552
574
 
553
- auto jsDispatchQueue = Mso::DispatchQueue::MakeLooperQueue();
575
+ auto jsDispatchQueue =
576
+ Mso::DispatchQueue::MakeLooperQueue(CreateDispatchQueueSettings(m_reactContext->Notifications()));
554
577
  auto jsDispatcher =
555
578
  winrt::make<winrt::Microsoft::ReactNative::implementation::ReactDispatcher>(Mso::Copy(jsDispatchQueue));
556
579
  m_options.Properties.Set(ReactDispatcherHelper::JSDispatcherProperty(), jsDispatcher);
557
580
  m_jsMessageThread.Exchange(std::make_shared<Mso::React::MessageDispatchQueue>(
558
- jsDispatchQueue, nullptr /*errorHandler*/, nullptr /*whenQuitPromise*/));
581
+ jsDispatchQueue,
582
+ Mso::MakeWeakMemberFunctor(this, &ReactInstanceWin::OnError),
583
+ Mso::Copy(m_whenDestroyed)));
559
584
 
560
585
  auto timerRegistry = ::Microsoft::ReactNative::TimerRegistry::CreateTimerRegistry(
561
586
  m_options.Properties.Get(ReactDispatcherHelper::UIDispatcherProperty()).try_as<IReactDispatcher>());
@@ -911,14 +936,7 @@ void ReactInstanceWin::LoadJSBundlesBridgeless(std::shared_ptr<facebook::react::
911
936
  [weakThis = Mso::WeakPtr{this},
912
937
  loadCallbackGuard = Mso::MakeMoveOnCopyWrapper(LoadedCallbackGuard{*this})]() noexcept {
913
938
  if (auto strongThis = weakThis.GetStrongPtr()) {
914
- auto instance = strongThis->m_instance.LoadWithLock();
915
- auto instanceWrapper = strongThis->m_instanceWrapper.LoadWithLock();
916
- if (!instance || !instanceWrapper) {
917
- return;
918
- }
919
-
920
939
  try {
921
- instanceWrapper->loadBundleSync(Mso::Copy(strongThis->JavaScriptBundleFile()));
922
940
  if (strongThis->State() != ReactInstanceState::HasError) {
923
941
  strongThis->OnReactInstanceLoaded(Mso::ErrorCode{});
924
942
  }
@@ -973,6 +991,25 @@ Mso::Future<void> ReactInstanceWin::Destroy() noexcept {
973
991
  m_jsDispatchQueue.Exchange(nullptr);
974
992
  }
975
993
 
994
+ #ifdef USE_FABRIC
995
+ if (m_bridgelessReactInstance) {
996
+ if (auto jsMessageThread = m_jsMessageThread.Exchange(nullptr)) {
997
+ jsMessageThread->runOnQueueSync([&]() noexcept {
998
+ {
999
+ // Release the JSI runtime
1000
+ std::scoped_lock lock{m_mutex};
1001
+
1002
+ this->m_jsiRuntimeHolder = nullptr;
1003
+ this->m_jsiRuntime = nullptr;
1004
+ }
1005
+ this->m_bridgelessReactInstance = nullptr;
1006
+ jsMessageThread->quitSynchronous();
1007
+ });
1008
+ }
1009
+ m_jsDispatchQueue.Exchange(nullptr);
1010
+ }
1011
+ #endif
1012
+
976
1013
  return m_whenDestroyedResult;
977
1014
  }
978
1015
 
@@ -987,26 +1024,8 @@ ReactInstanceState ReactInstanceWin::State() const noexcept {
987
1024
  void ReactInstanceWin::InitJSMessageThread() noexcept {
988
1025
  m_instance.Exchange(std::make_shared<facebook::react::Instance>());
989
1026
 
990
- winrt::Microsoft::ReactNative::IReactNotificationService service = m_reactContext->Notifications();
991
- Mso::DispatchQueueSettings queueSettings{};
992
- queueSettings.TaskStarting = [service](Mso::DispatchQueue const &) noexcept {
993
- service.SendNotification(
994
- winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherTaskStartingEventName(), nullptr, nullptr);
995
- };
996
- queueSettings.IdleWaitStarting = [service](Mso::DispatchQueue const &) noexcept {
997
- service.SendNotification(
998
- winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherIdleWaitStartingEventName(),
999
- nullptr,
1000
- nullptr);
1001
- };
1002
- queueSettings.IdleWaitCompleted = [service](Mso::DispatchQueue const &) noexcept {
1003
- service.SendNotification(
1004
- winrt::Microsoft::ReactNative::ReactDispatcherHelper::JSDispatcherIdleWaitCompletedEventName(),
1005
- nullptr,
1006
- nullptr);
1007
- };
1008
1027
  auto scheduler = Mso::MakeJSCallInvokerScheduler(
1009
- queueSettings,
1028
+ CreateDispatchQueueSettings(m_reactContext->Notifications()),
1010
1029
  m_instance.Load()->getJSCallInvoker(),
1011
1030
  Mso::MakeWeakMemberFunctor(this, &ReactInstanceWin::OnError),
1012
1031
  Mso::Copy(m_whenDestroyed));
@@ -1201,6 +1220,7 @@ void ReactInstanceWin::OnJSError(facebook::react::MapBuffer errorMap) noexcept {
1201
1220
  m_state = ReactInstanceState::HasError;
1202
1221
  AbandonJSCallQueue();
1203
1222
 
1223
+ OnReactInstanceLoaded(errorCode);
1204
1224
  if (m_redboxHandler && m_redboxHandler->isDevSupportEnabled()) {
1205
1225
  m_redboxHandler->showNewError(std::move(errorInfo), isFatal ? ErrorType::JSFatal : ErrorType::JSSoft);
1206
1226
  }
@@ -10,11 +10,11 @@
10
10
  -->
11
11
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
12
  <PropertyGroup>
13
- <ReactNativeWindowsVersion>0.0.0-canary.781</ReactNativeWindowsVersion>
13
+ <ReactNativeWindowsVersion>0.0.0-canary.783</ReactNativeWindowsVersion>
14
14
  <ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
15
15
  <ReactNativeWindowsMinor>0</ReactNativeWindowsMinor>
16
16
  <ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
17
17
  <ReactNativeWindowsCanary>true</ReactNativeWindowsCanary>
18
- <ReactNativeWindowsCommitId>18c8372dd35888db23ca1fca8b3b088860fe8f6e</ReactNativeWindowsCommitId>
18
+ <ReactNativeWindowsCommitId>c3f4edf2ba3f926a04c9a7573e155dfc573bc792</ReactNativeWindowsCommitId>
19
19
  </PropertyGroup>
20
20
  </Project>
@@ -160,8 +160,16 @@ bool OriginPolicyHttpFilter::CaseInsensitiveComparer::operator()(const wstring &
160
160
  return s_simpleCorsMethods.find(request.Method().ToString().c_str()) != s_simpleCorsMethods.cend();
161
161
  }
162
162
 
163
- /*static*/ Uri OriginPolicyHttpFilter::GetOrigin(Uri const &uri) noexcept {
164
- return Uri{uri.SchemeName() + L"://" + uri.Host() + L":" + to_hstring(uri.Port())};
163
+ /*static*/ const hstring OriginPolicyHttpFilter::GetOrigin(Uri const &uri) noexcept {
164
+ auto const &scheme = uri.SchemeName();
165
+ auto port = uri.Port();
166
+
167
+ hstring result = scheme + L"://" + uri.Host();
168
+ if (!(port == 80 && scheme == L"http") && !(port == 443 && scheme == L"https")) {
169
+ result = result + L":" + to_hstring(port);
170
+ }
171
+
172
+ return result;
165
173
  }
166
174
 
167
175
  /*static*/ bool OriginPolicyHttpFilter::AreSafeRequestHeaders(
@@ -683,7 +691,7 @@ ResponseOperation OriginPolicyHttpFilter::SendPreflightAsync(HttpRequestMessage
683
691
  }
684
692
 
685
693
  preflightRequest.Headers().Insert(L"Access-Control-Request-Headers", headerNames);
686
- preflightRequest.Headers().Insert(L"Origin", s_origin.AbsoluteCanonicalUri());
694
+ preflightRequest.Headers().Insert(L"Origin", GetOrigin(s_origin));
687
695
  preflightRequest.Headers().Insert(L"Sec-Fetch-Mode", L"CORS");
688
696
 
689
697
  co_return {co_await m_innerFilter.SendRequestAsync(preflightRequest)};
@@ -769,7 +777,7 @@ ResponseOperation OriginPolicyHttpFilter::SendRequestAsync(HttpRequestMessage co
769
777
 
770
778
  if (originPolicy == OriginPolicy::SimpleCrossOriginResourceSharing ||
771
779
  originPolicy == OriginPolicy::CrossOriginResourceSharing) {
772
- coRequest.Headers().Insert(L"Origin", s_origin.AbsoluteCanonicalUri());
780
+ coRequest.Headers().Insert(L"Origin", GetOrigin(s_origin));
773
781
  }
774
782
 
775
783
  auto response = co_await m_innerFilter.SendRequestAsync(coRequest);
@@ -58,7 +58,7 @@ class OriginPolicyHttpFilter
58
58
  winrt::Windows::Foundation::Uri const &u1,
59
59
  winrt::Windows::Foundation::Uri const &u2) noexcept;
60
60
 
61
- static winrt::Windows::Foundation::Uri GetOrigin(winrt::Windows::Foundation::Uri const &uri) noexcept;
61
+ static const winrt::hstring GetOrigin(winrt::Windows::Foundation::Uri const &uri) noexcept;
62
62
 
63
63
  static bool IsSimpleCorsRequest(winrt::Windows::Web::Http::HttpRequestMessage const &request) noexcept;
64
64
 
@@ -302,6 +302,7 @@
302
302
  <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Modules\PlatformConstantsWinModule.cpp" />
303
303
  <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Modules\ExceptionsManager.cpp" />
304
304
  <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Modules\SourceCode.cpp" />
305
+ <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Modules\Timing.cpp" />
305
306
  </ItemGroup>
306
307
  <ItemGroup>
307
308
  <Filter Include="Source Files">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.0.0-canary.781",
3
+ "version": "0.0.0-canary.783",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",