Skip to content

Commit

Permalink
Merge pull request #4806 from NickGerleman/0.62-stable
Browse files Browse the repository at this point in the history
Cherry-Pick More Changes into 0.62-stable
  • Loading branch information
NickGerleman authored May 7, 2020
2 parents ac3c3d9 + 5221441 commit 7a3ad04
Show file tree
Hide file tree
Showing 21 changed files with 288 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Ensure InitializeCore is run before app code",
"packageName": "@office-iss/react-native-win32",
"email": "acoates@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-06T21:33:58.938Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Removed the ref count work around from classes derived from ReactApplications",
"packageName": "react-native-windows",
"email": "vmorozov@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-30T15:22:39.524Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Promote awaitable DispatchQueue callback to member field",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-05T02:05:45.427Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Treat yes the same as y in template overwrite prompt",
"packageName": "react-native-windows",
"email": "acoates@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-05T15:23:01.596Z"
}
8 changes: 8 additions & 0 deletions change/react-native-windows-2020-05-06-05-03-56-no-fh4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Disable CxxFrameHandler4",
"packageName": "react-native-windows",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-06T12:03:56.512Z"
}
8 changes: 8 additions & 0 deletions change/react-native-windows-2020-05-06-14-34-01-fixfast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Ensure InitializeCore is run before app code",
"packageName": "react-native-windows",
"email": "acoates@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-06T21:34:00.993Z"
}
13 changes: 10 additions & 3 deletions packages/E2ETest/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');
const {
getModulesRunBeforeMainModule,
reactNativePlatformResolver,
} = require('react-native-windows/metro-react-native-platform');

const rnwPath = path.resolve(__dirname, '../../vnext');

Expand All @@ -19,9 +23,9 @@ module.exports = {
],

resolver: {
resolveRequest: require('react-native-windows/metro-react-native-platform').reactNativePlatformResolver(
{ windows: 'react-native-windows' }
),
resolveRequest: reactNativePlatformResolver({
windows: 'react-native-windows',
}),
extraNodeModules: {
// Redirect metro to rnwPath instead of node_modules/react-native-windows, since metro doesn't like symlinks
'react-native-windows': rnwPath,
Expand All @@ -34,6 +38,9 @@ module.exports = {
),
]),
},
serializer: {
getModulesRunBeforeMainModule,
},
transformer: {
// The cli defaults this to a full path to react-native, which bypasses the reactNativePlatformResolver above
// Hopefully we can fix the default in the future
Expand Down
13 changes: 10 additions & 3 deletions packages/microsoft-reactnative-sampleapps/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');
const {
getModulesRunBeforeMainModule,
reactNativePlatformResolver,
} = require('react-native-windows/metro-react-native-platform');

const rnwPath = path.resolve(__dirname, '../../vnext');

Expand All @@ -19,9 +23,9 @@ module.exports = {
],

resolver: {
resolveRequest: require('react-native-windows/metro-react-native-platform').reactNativePlatformResolver(
{windows: 'react-native-windows'},
),
resolveRequest: reactNativePlatformResolver({
windows: 'react-native-windows',
}),
extraNodeModules: {
// Redirect metro to rnwPath instead of node_modules/react-native-windows, since metro doesn't like symlinks
'react-native-windows': rnwPath,
Expand All @@ -36,6 +40,9 @@ module.exports = {
),
]),
},
serializer: {
getModulesRunBeforeMainModule,
},
transformer: {
// The cli defaults this to a full path to react-native, which bypasses the reactNativePlatformResolver above
// Hopefully we can fix the default in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ App::App() noexcept {
PackageProviders().Append(winrt::SampleLibraryCS::ReactPackageProvider());

InitializeComponent();

// This works around a cpp/winrt bug with composable/aggregable types tracked
// by 22116519
AddRef();
m_inner.as<::IUnknown>()->Release();
}

} // namespace winrt::SampleAppCpp::implementation
13 changes: 10 additions & 3 deletions packages/playground/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
const fs = require('fs');
const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');
const {
getModulesRunBeforeMainModule,
reactNativePlatformResolver,
} = require('react-native-windows/metro-react-native-platform');

const rnwPath = fs.realpathSync(
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
Expand All @@ -22,9 +26,9 @@ module.exports = {
],

resolver: {
resolveRequest: require('react-native-windows/metro-react-native-platform').reactNativePlatformResolver(
{windows: 'react-native-windows'},
),
resolveRequest: reactNativePlatformResolver({
windows: 'react-native-windows',
}),
extraNodeModules: {
// Redirect react-native-windows to avoid symlink (metro doesn't like symlinks)
'react-native-windows': rnwPath,
Expand All @@ -36,6 +40,9 @@ module.exports = {
),
]),
},
serializer: {
getModulesRunBeforeMainModule,
},
transformer: {
// The cli defaults this to a full path to react-native, which bypasses the reactNativePlatformResolver above
// Hopefully we can fix the default in the future
Expand Down
47 changes: 46 additions & 1 deletion packages/react-native-win32/metro-react-native-platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,49 @@ function reactNativePlatformResolver(platformImplementations) {
};
}

module.exports = {reactNativePlatformResolver};
/**
* The CLI will get a more complete implementation of this in https://github.com/react-native-community/cli/pull/1115
* but until then, use a solution that supports having react-native-win32 and/or react-native-windows and/or react-native-macos
*/
const getModulesRunBeforeMainModule = () => {
const options = {
paths: [process.cwd()],
};
const modules = [
require.resolve('react-native/Libraries/Core/InitializeCore', options),
];

try {
modules.push(
require.resolve(
'@office-iss/react-native-win32/Libraries/Core/InitializeCore',
options,
),
);
} catch {}

try {
modules.push(
require.resolve(
'react-native-windows/Libraries/Core/InitializeCore',
options,
),
);
} catch {}

try {
modules.push(
require.resolve(
'react-native-macos/Libraries/Core/InitializeCore',
options,
),
);
} catch {}

return modules;
};

module.exports = {
getModulesRunBeforeMainModule,
reactNativePlatformResolver,
};
13 changes: 10 additions & 3 deletions packages/react-native-win32/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*/
const fs = require('fs');
const path = require('path');
const {
getModulesRunBeforeMainModule,
reactNativePlatformResolver,
} = require('./metro-react-native-platform');

module.exports = {
// WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately
Expand All @@ -12,9 +16,12 @@ module.exports = {
],

resolver: {
resolveRequest: require('./metro-react-native-platform').reactNativePlatformResolver(
{win32: '@office-iss/react-native-win32'},
),
resolveRequest: reactNativePlatformResolver({
win32: '@office-iss/react-native-win32',
}),
},
serializer: {
getModulesRunBeforeMainModule,
},
transformer: {
// The cli defaults this to a full path to react-native, which bypasses the reactNativePlatformResolver above
Expand Down
15 changes: 13 additions & 2 deletions vnext/Microsoft.ReactNative/ReactApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pch.h"
#include "ReactApplication.h"
#include "ReactApplication.g.cpp"

#include "Modules/LinkingManagerModule.h"
#include "ReactNativeHost.h"

Expand All @@ -23,7 +24,17 @@ using namespace Windows::UI::Xaml::Navigation;

namespace winrt::Microsoft::ReactNative::implementation {

ReactApplication::ReactApplication() noexcept {
ReactApplication::ReactApplication() = default;

ReactApplication::ReactApplication(IInspectable const &outer) noexcept : ReactApplication{} {
// The factory is usually called in the base generated class. We call it here to pass correct
// 'outer' interface to enable inheritance from the ReactApplication class in user code.
impl::call_factory<Windows::UI::Xaml::Application, Windows::UI::Xaml::IApplicationFactory>(
[&](Windows::UI::Xaml::IApplicationFactory const &f) {
[[maybe_unused]] auto winrt_impl_discarded =
f.CreateInstance(outer ? outer : static_cast<IInspectable const &>(*this), this->m_inner);
});

Suspending({this, &ReactApplication::OnSuspending});

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
Expand Down Expand Up @@ -112,7 +123,7 @@ void ReactApplication::OnActivated(IActivatedEventArgs const &e) {
}

void ReactApplication::OnLaunched(LaunchActivatedEventArgs const &e) {
Super::OnLaunched(e);
base_type::OnLaunched(e);
// auto args = std::wstring(e.Arguments().c_str());
this->OnCreate(e);
}
Expand Down
59 changes: 55 additions & 4 deletions vnext/Microsoft.ReactNative/ReactApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,59 @@
#pragma once

#include "ReactApplication.g.h"
#include <CppWinRTIncludes.h>
#include "ReactNativeHost.h"

namespace winrt::Microsoft::ReactNative::implementation {

struct ReactApplication : ReactApplicationT<ReactApplication> {
using Super = ReactApplicationT<ReactApplication>;
// NoDefaultCtorReactApplication_base is a copy of the generated ReactApplication_base
// without the default constructor where it calls a factory for the base type.
// This is done to fix the aggregation issue in types inheriting from the ReactApplication.
// We call the factory in the ReactApplication constructor where we can pass correct
// 'outer' interface.
//
// This class must match the generated ReactApplication_base.
// It must be updated if the shape of generated ReactApplication_base is changed in future.
// The only difference is that this class has no default constructor.
template <typename D, typename... I>
struct __declspec(empty_bases) NoDefaultCtorReactApplication_base : implements<
D,
Microsoft::ReactNative::ReactApplication,
composable,
composing,
Windows::UI::Xaml::IApplicationOverrides,
Windows::UI::Xaml::IApplicationOverrides2,
I...>,
impl::require<
D,
Windows::UI::Xaml::IApplication,
Windows::UI::Xaml::IApplication2,
Windows::UI::Xaml::IApplication3>,
impl::base<D, Windows::UI::Xaml::Application>,
Windows::UI::Xaml::IApplicationOverridesT<D>,
Windows::UI::Xaml::IApplicationOverrides2T<D> {
using base_type = NoDefaultCtorReactApplication_base;
using class_type = Microsoft::ReactNative::ReactApplication;
using implements_type = typename NoDefaultCtorReactApplication_base::implements_type;
using implements_type::implements_type;
using composable_base = Windows::UI::Xaml::Application;

hstring GetRuntimeClassName() const {
return L"Microsoft.ReactNative.ReactApplication";
}

protected:
using dispatch = impl::
dispatch_to_overridable<D, Windows::UI::Xaml::IApplicationOverrides, Windows::UI::Xaml::IApplicationOverrides2>;
auto overridable() noexcept {
return dispatch::overridable(static_cast<D &>(*this));
}
};

struct ReactApplication : NoDefaultCtorReactApplication_base<ReactApplication> {
public: // ReactApplication ABI API
ReactApplication() noexcept;
ReactApplication();
ReactApplication(IInspectable const &outer) noexcept;

ReactNative::ReactInstanceSettings InstanceSettings() noexcept;
void InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept;
Expand Down Expand Up @@ -57,6 +101,13 @@ struct ReactApplication : ReactApplicationT<ReactApplication> {

namespace winrt::Microsoft::ReactNative::factory_implementation {

struct ReactApplication : ReactApplicationT<ReactApplication, implementation::ReactApplication> {};
// Override the CreateInstance method to pass baseInterface to the ReactApplication constructor
// to support correct COM aggregation that is need to inherit from the ReactApplication.
struct ReactApplication : ReactApplicationT<ReactApplication, implementation::ReactApplication> {
auto CreateInstance(IInspectable const &baseInterface, IInspectable &innerInterface) {
return impl::composable_factory<implementation::ReactApplication>::template CreateInstance<
Microsoft::ReactNative::ReactApplication>(baseInterface, innerInterface, baseInterface);
}
};

} // namespace winrt::Microsoft::ReactNative::factory_implementation
13 changes: 13 additions & 0 deletions vnext/PropertySheets/React.Cpp.props
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@
</ClCompile>
</ItemDefinitionGroup>

<!--
#4804: CxxFrameHandler4 leads to generated code that incompatible with VS
2015 and 2017. Disable it until consumers are updated or on an ABI-safe API
-->
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/d2FH4- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<AdditionalOptions>/d2:-FH4- %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>

<ItemDefinitionGroup Condition="'$(ConfigurationType)' == 'Application' OR '$(ConfigurationType)' == 'DynamicLibrary'">
<Link>
<SubSystem>Console</SubSystem>
Expand Down
6 changes: 4 additions & 2 deletions vnext/ReactWindowsCore/WinRTWebSocketResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ namespace

void await_suspend(std::experimental::coroutine_handle<> resume)
{
m_queue.Post([context = resume.address()]() noexcept
m_callback = [context = resume.address()]() noexcept
{
std::experimental::coroutine_handle<>::from_address(context)();
});
};
m_queue.Post(std::move(m_callback));
}

private:
Mso::DispatchQueue m_queue;
Mso::VoidFunctor m_callback;
};

return awaitable{ queue };
Expand Down
Loading

0 comments on commit 7a3ad04

Please sign in to comment.