I have tried testing to see if JsWinRT would work with RNW 0.64
Compilation Issues
(1) react-native-patched
no longer exists so include paths in WinRTTurboModule.vcxproj
so include paths should point to various folders under react-native
instead of $(ReactNativeWindowsDir)build\$(ReactPlatform)\$(Configuration)\ReactCommon\react-native-patched
.
Given <ReactCommonDir>$(ReactNativeWindowsDir)..\react-native\ReactCommon\</ReactCommonDir>
<AdditionalIncludeDirectories>
$(ReactCommonDir)jsi;
$(ReactCommonDir)callinvoker;
$(ReactCommonDir)react\nativemodule\core;
$(GeneratedFilesDir);
%(AdditionalIncludeDirectories);
</AdditionalIncludeDirectories>
(2) base.h refers to TurboModule/Core/TurboModule.h
but this should now just be ReactCommon\TurboModule.h
assuming the include paths in (1)
(3) dllmain.cpp refers to TurboModule/Core/TurboModule.cpp
but this should now be ReactCommon\TurboModule.cpp
assuming the include paths in (1)
(4) The patch for TurboModuleManager.cpp should change slightly as turbomodule/samples/SampleTurboCxxModule.h
changed to ReactCommon/SampleTurboCxxModule.h
but per vmoroz's comment, we should really be using AddTurboModuleProvider to expose the WinRTTurboModule with a ReactPackagedProvider which supports auto-linking too. To accomplish a WinRTTurboModule.vcxproj should add dependency on Microsoft.ReactNative.Uwp.CppLib.props+targets, remove jsi.cpp and turbomodule.cpp from dllmain.cpp and WinRTTurboModule.def should export DllMain, DllCanUnloadNow, and DllGetActivationFactory, and define a ReactPackageProvider like a normal Native Module. A WinRTTurboModule.h should be added that forward declares WinRTTurboModule so it can be used with AddTurboModuleProvider and CreateWinRTTurboModule should be deleted along with patching of TurboModuleManager.cpp. It would also be advisable to a WinRTTurboModule.vcxproj.filters to hide files added by Microsoft.ReactNative.Cxx.vcxitems. Some additional fixes like removing CppWinRTGenerateWindowsMetadata=false are likely necessary.
(5) Other minor issues that will need to be addressed for the sample project like changing metro.config.js's reference to blackList to blockList to be something like the following:
const exclusionList = require('metro-config/src/defaults/exclusionList');
module.exports = {
resolver: {
blocklist: exclusionList([
new RegExp(
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
),
/.*\.ProjectImports\.zip/,
]),
},
Functional Issues
- Constructor calls appear to fail with
Constructor call for HostObjectGetTrap() is not supported.
. This appears to be a regression due to ChakraRuntime.cpp changes in microsoft/react-native-windows#5710 that added exceptions if trying to retrieve a constructor from the HostObject. Thankfully, the naïve fix of commenting out the two throw-if statements (in ChakraRuntime::HostObjectGetTrap and ChakraRuntime::HostObjectSetTrap) fixes the issue (and I can see the telemetry logged with Windows.Foundation.Diagnostics.LoggingChannel())
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraRuntime::ThrowNativeExceptionOverride(const char * errorMessage) Line 589 C++
> Microsoft.ReactNative.dll!Microsoft::JSI::ChakraApi::ThrowNativeException(const char * errorMessage) Line 83 C++
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraRuntime::HostFunctionCall::__l2::<lambda>() Line 678 C++
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraRuntime::HandleCallbackExceptions<void * <lambda>(void)>(Microsoft::JSI::ChakraRuntime::HostFunctionCall::__l2::void * <lambda>(void) lambda) Line 297 C++
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraRuntime::HostFunctionCall(void * __formal, bool isConstructCall, void * * args, unsigned short argCount, void * callbackState) Line 689 C++
Chakra.dll!
...
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraApi::CallFunction(void * function, Microsoft::JSI::ChakraApi::Span<void *> args) Line 416 C++
Microsoft.ReactNative.dll!Microsoft::JSI::ChakraRuntime::call(const facebook::jsi::Function & func, const facebook::jsi::Value & jsThis, const facebook::jsi::Value * args, unsigned __int64 count) Line 540 C++
Microsoft.ReactNative.dll!facebook::jsi::Function::call(facebook::jsi::Runtime & runtime, const facebook::jsi::Value * args, unsigned __int64 count) Line 228 C++
Microsoft.ReactNative.dll!facebook::jsi::Function::call(facebook::jsi::Runtime & runtime, std::initializer_list<facebook::jsi::Value> args) Line 233 C++
Microsoft.ReactNative.dll!facebook::jsi::Function::call<std::string const &,std::string const &,facebook::jsi::Value>(facebook::jsi::Runtime & runtime, const std::string & <args_0>, const std::string & <args_1>, facebook::jsi::Value && <args_2>) Line 241 C++
Microsoft.ReactNative.dll!facebook::react::JSIExecutor::callFunction::__l6::<lambda>() Line 231 C++
...
<I will add on to this list if I discover more during testing, but I am as of yet blocked on the first issue discovered..>
"react": "17.0.1",
"react-native": "0.64.0-rc.3",
"react-native-windows": "0.64.0-preview.12"