Skip to content

Commit

Permalink
Remove Paper-only code from Fabric builds of Microsoft.ReactNative (#…
Browse files Browse the repository at this point in the history
…14289)

## Description

Removes most of the Paper-only code from Fabric builds of Microsoft.ReactNative. This is only a first pass - there may be more that needs to be removed (or stuff that needs to be put back in).

### Type of Change
- Bug fix (non-breaking change which fixes an issue)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)

### Why
Besides nearly doubling the size of the binary files, all of the Paper-only code is functionally useless in Fabric builds, which at worse is dead weight, and at best is confusing to developers.

Resolves #13405

### What
Updated project files to not load/compile paper-only modules. Updated modules that are used by both to correctly only include the Paper or Fabric code they need.

## Screenshots

None, but here are some preliminary binary size numbers for x64 release:

| File | Paper | Fabric (Before) | Fabric (After) |
|:-|:-:|:-:|:-:|
| Microsoft.ReactNative.dll | 4.02 MB | 8.32 MB | 6.47 MB (🔻1.85 MB / 22% ) |
| Microsoft.ReactNative.winmd | 64.0 KB | 121.0 KB | 92.0KB (🔻29 KB / 24%) |

## Testing
Verified all existing tests still pass and fabric apps work.

## Changelog
Should this change be included in the release notes: _yes_

Remove Paper-only code from Fabric builds of Microsoft.ReactNative
  • Loading branch information
jonthysell authored Jan 22, 2025
1 parent 6620dc0 commit 3cba4c4
Show file tree
Hide file tree
Showing 31 changed files with 236 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Remove Paper-only code from Fabric builds of Microsoft.ReactNative",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 0 additions & 3 deletions vnext/Desktop/React.Windows.Desktop.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@
-->
<PreprocessorDefinitions>CORE_ABI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<Midl>
<PreprocessorDefinitions Condition="'$(UseFabric)' == 'true'">USE_FABRIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
</ItemDefinitionGroup>
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\ReactCommunity.cpp.props" />
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative.Cxx/ReactContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct ReactContext {
m_handle.EmitJSEvent(eventEmitterName, eventName, MakeJSValueWriter(std::forward<TArgs>(args)...));
}

#if !defined(CORE_ABI) && !defined(__APPLE__) && !defined(CXXUNITTESTS)
#if !defined(CORE_ABI) && !defined(USE_FABRIC) && !defined(__APPLE__) && !defined(CXXUNITTESTS)
// Dispatch eventName event to the view.
// args are either function arguments or a single lambda with 'IJSValueWriter const&' argument.
template <class... TArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <IReactContext.h>
#include <React.h>
#include <Views/DevMenu.h>
#include <Views/ShadowNodeBase.h>
#include <windows.h>
#include <windowsx.h>
#include <winrt/Windows.UI.Core.h>
Expand Down
4 changes: 2 additions & 2 deletions vnext/Microsoft.ReactNative/IReactContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "pch.h"
#include "IReactContext.h"
#include "DynamicWriter.h"
#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
#include "XamlUIService.h"
#endif

Expand Down Expand Up @@ -121,7 +121,7 @@ LoadingState ReactContext::LoadingState() noexcept {
};
}

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
// Deprecated: Use XamlUIService directly.
void ReactContext::DispatchEvent(
xaml::FrameworkElement const &view,
Expand Down
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/IReactContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct ReactContext : winrt::implements<ReactContext, IReactContext> {
IInspectable JSRuntime() noexcept;
LoadingState LoadingState() noexcept;

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
void DispatchEvent(
xaml::FrameworkElement const &view,
hstring const &eventName,
Expand Down
4 changes: 2 additions & 2 deletions vnext/Microsoft.ReactNative/IReactContext.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "IJSValueWriter.idl"; // The import is to be deprecated with IReactContex
import "IReactNotificationService.idl";
import "IReactPropertyBag.idl";

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
#include "NamespaceRedirect.h" // The include is to be deprecated with IReactContext::DispatchEvent
#endif

Expand Down Expand Up @@ -185,7 +185,7 @@ namespace Microsoft.ReactNative
"It is an experimental property that may be removed or changed in a future version.")
Object JSRuntime { get; };

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
[deprecated("Use @XamlUIService.DispatchEvent instead", deprecate, 1)]
DOC_STRING("Deprecated property. Use @XamlUIService.DispatchEvent instead. It will be removed in a future version.")
void DispatchEvent(XAML_NAMESPACE.FrameworkElement view, String eventName, JSValueArgWriter eventDataArgWriter);
Expand Down
6 changes: 3 additions & 3 deletions vnext/Microsoft.ReactNative/IReactPackageBuilder.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import "IReactContext.idl";
import "IReactModuleBuilder.idl";
#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
import "IViewManager.idl";
#endif

Expand All @@ -14,7 +14,7 @@ namespace Microsoft.ReactNative
DOC_STRING("Provides information about a custom native module. See @IReactModuleBuilder.")
delegate Object ReactModuleProvider(IReactModuleBuilder moduleBuilder);

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
DOC_STRING("Provides information about a custom view manager. See @IViewManager.")
delegate IViewManager ReactViewManagerProvider();
#endif
Expand All @@ -32,7 +32,7 @@ namespace Microsoft.ReactNative
"NOTE: TurboModules using JSI directly will not run correctly while using @ReactInstanceSettings.UseWebDebugger")
void AddTurboModule(String moduleName, ReactModuleProvider moduleProvider);

#ifndef CORE_ABI
#if !defined(CORE_ABI) && !defined(USE_FABRIC)
DOC_STRING("Adds a custom view manager. See @ReactViewManagerProvider.")
void AddViewManager(String viewManagerName, ReactViewManagerProvider viewManagerProvider);
#endif
Expand Down
Loading

0 comments on commit 3cba4c4

Please sign in to comment.