Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracted definition and access to public instances to a separate module in Fabric #26291

Conversation

rubennorte
Copy link
Contributor

Summary

The current definition of Instance in Fabric has 2 fields:

  • node: reference to the native node in the shadow tree.
  • canonical: public instance provided to users via refs.

We're currently using canonical not only as the public instance, but also to store internal properties that Fabric needs to access in different parts of the codebase. Those properties are, in fact, available through refs as well, which breaks encapsulation.

This PR splits that into 2 separate fields, leaving the definition of instance as:

  • node: reference to the native node in the shadow tree.
  • publicInstance: public instance provided to users via refs.
  • internals: collection of properties that are required by Fabric itself, given references to the instance.

This also migrates all the current usages of canonical to use the right property depending on the use case.

To improve encapsulation (and in preparation for the implementation of this proposal to bring some DOM APIs to public instances in React Native), this also moves the creation of and the access to the public instance to a separate module. In a following diff, that module will be moved into the react-native repository and we'll access it through ReactNativePrivateInterface.

How did you test this change?

Existing unit tests.

NOTE: This includes the changes in #26290. I'll rebase this onto main when that is merged.

…in the Fabric version of GlobalResponderHandler
@react-sizebot
Copy link

react-sizebot commented Mar 3, 2023

Comparing: b72ed69...b2a5c00

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 155.25 kB 155.25 kB = 48.98 kB 48.98 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 157.24 kB 157.24 kB = 49.64 kB 49.64 kB
facebook-www/ReactDOM-prod.classic.js = 532.50 kB 532.50 kB = 94.85 kB 94.85 kB
facebook-www/ReactDOM-prod.modern.js = 516.42 kB 516.42 kB = 92.45 kB 92.45 kB
react-native/shims/ReactNativeTypes.js = 7.19 kB 6.98 kB = 2.02 kB 1.96 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
react-native/shims/ReactNativeTypes.js = 7.19 kB 6.98 kB = 2.02 kB 1.96 kB

Generated by 🚫 dangerJS against b2a5c00

@rubennorte rubennorte force-pushed the extract-react-fabric-public-instance-handling-to-module branch from 75e7db1 to 752e093 Compare March 3, 2023 14:22
@rubennorte rubennorte marked this pull request as ready for review March 3, 2023 14:24
@rubennorte rubennorte requested review from mdvacca and fkgozali March 3, 2023 14:25
@rubennorte rubennorte force-pushed the extract-react-fabric-public-instance-handling-to-module branch 2 times, most recently from 02238bc to 53f270a Compare March 3, 2023 17:43
@@ -45,26 +45,6 @@ export function mountSafeCallback_NOT_REALLY_SAFE(
};
}

export function throwOnStylesProp(component: any, props: any) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused :)

@rubennorte rubennorte force-pushed the extract-react-fabric-public-instance-handling-to-module branch 3 times, most recently from d06a621 to 5887cde Compare March 3, 2023 18:22
@rubennorte rubennorte force-pushed the extract-react-fabric-public-instance-handling-to-module branch from 5887cde to b2a5c00 Compare March 3, 2023 18:24
@rubennorte
Copy link
Contributor Author

I realized I didn't migrate some logic in dispatchCommand and other methods correctly. Will fix and publish a new version soon.

@rubennorte rubennorte marked this pull request as draft March 3, 2023 22:53
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
return componentOrHandle;

// For compatibility with Paper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: avoid codename "Paper", use "legacy renderer"

Copy link
Contributor

@fkgozali fkgozali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems reasonable to me, added a few nits/questions.

fromOrToStateNode && fromOrToStateNode.canonical._internalInstanceHandle
);

if (isFabric) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this safe removal because this handler file is solely handling fabric? no mixed case?

nativeTag: number,
viewConfig: ViewConfig,
currentProps: Props,
internalInstanceHandle: Object,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a bit redundant name with internal prefix?

instance.internals.internalInstanceHandle

what about instance.internals.instanceHandle?

publicInstance: ReactFabricHostComponent,
// We define this as an object instead of as separate fields to simplify
// making copies of instance where `internals` don't change.
internals: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the convention is - should this one be prefixed by _ ?

@rubennorte rubennorte closed this Mar 6, 2023
@rubennorte rubennorte deleted the extract-react-fabric-public-instance-handling-to-module branch March 6, 2023 10:50
@rubennorte
Copy link
Contributor Author

Sorry I accidentally deleted the branch when restructuring my repo. I'll create another PR with these changes.

rubennorte added a commit to rubennorte/react-native that referenced this pull request Mar 22, 2023
Summary:
I'm doing some preparations to implement this proposal to bring some DOM APIs to React Native refs: react-native-community/discussions-and-proposals#607

To make it easier to iterate on the proposal, and to improve the separation of concerns between React and React Native, I'm moving the definition of `ReactFabricHostComponent` (the public instance provided by React when using refs on host conmponents) to the `react-native` package.

I already did some steps in the React repository to simplify this:
* Removing unused imperative events that caused increased coupling: facebook/react#26282
* Extracting the definition of the public instance to a separate module: facebook/react#26291

In this case, in order to be able to move the definition from React to React Native, we need to:
1. Create the definition in React Native and export it through `ReactNativePrivateInterface`.
2. Update React to use that definition instead of the one in its own module.

This diff implements the first step.

`ReactNativeAttributePayload` is required by this definition and by the one for Paper that still exists in React. I moved it here so we only define it where we use it when we remove Paper. Paper will access it through `ReactNativePrivateInterface` as well. That will also allow us to remove a few other fields in that interface.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D43772356

fbshipit-source-id: 0540fb9c665a9daa4d978926e0d01081f8541ffe
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Mar 22, 2023
Summary:
Pull Request resolved: #36570

I'm doing some preparations to implement this proposal to bring some DOM APIs to React Native refs: react-native-community/discussions-and-proposals#607

To make it easier to iterate on the proposal, and to improve the separation of concerns between React and React Native, I'm moving the definition of `ReactFabricHostComponent` (the public instance provided by React when using refs on host conmponents) to the `react-native` package.

I already did some steps in the React repository to simplify this:
* Removing unused imperative events that caused increased coupling: facebook/react#26282
* Extracting the definition of the public instance to a separate module: facebook/react#26291

In this case, in order to be able to move the definition from React to React Native, we need to:
1. Create the definition in React Native and export it through `ReactNativePrivateInterface`.
2. Update React to use that definition instead of the one in its own module.

This diff implements the first step.

`ReactNativeAttributePayload` is required by this definition and by the one for Paper that still exists in React. I moved it here so we only define it where we use it when we remove Paper. Paper will access it through `ReactNativePrivateInterface` as well. That will also allow us to remove a few other fields in that interface.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: yungsters

Differential Revision: D43772356

fbshipit-source-id: 78dac152f415f19316ec90887127bf9861fe3110
jeongshin pushed a commit to jeongshin/react-native that referenced this pull request May 7, 2023
Summary:
Pull Request resolved: facebook#36570

I'm doing some preparations to implement this proposal to bring some DOM APIs to React Native refs: react-native-community/discussions-and-proposals#607

To make it easier to iterate on the proposal, and to improve the separation of concerns between React and React Native, I'm moving the definition of `ReactFabricHostComponent` (the public instance provided by React when using refs on host conmponents) to the `react-native` package.

I already did some steps in the React repository to simplify this:
* Removing unused imperative events that caused increased coupling: facebook/react#26282
* Extracting the definition of the public instance to a separate module: facebook/react#26291

In this case, in order to be able to move the definition from React to React Native, we need to:
1. Create the definition in React Native and export it through `ReactNativePrivateInterface`.
2. Update React to use that definition instead of the one in its own module.

This diff implements the first step.

`ReactNativeAttributePayload` is required by this definition and by the one for Paper that still exists in React. I moved it here so we only define it where we use it when we remove Paper. Paper will access it through `ReactNativePrivateInterface` as well. That will also allow us to remove a few other fields in that interface.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: yungsters

Differential Revision: D43772356

fbshipit-source-id: 78dac152f415f19316ec90887127bf9861fe3110
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Pull Request resolved: facebook#36570

I'm doing some preparations to implement this proposal to bring some DOM APIs to React Native refs: react-native-community/discussions-and-proposals#607

To make it easier to iterate on the proposal, and to improve the separation of concerns between React and React Native, I'm moving the definition of `ReactFabricHostComponent` (the public instance provided by React when using refs on host conmponents) to the `react-native` package.

I already did some steps in the React repository to simplify this:
* Removing unused imperative events that caused increased coupling: facebook/react#26282
* Extracting the definition of the public instance to a separate module: facebook/react#26291

In this case, in order to be able to move the definition from React to React Native, we need to:
1. Create the definition in React Native and export it through `ReactNativePrivateInterface`.
2. Update React to use that definition instead of the one in its own module.

This diff implements the first step.

`ReactNativeAttributePayload` is required by this definition and by the one for Paper that still exists in React. I moved it here so we only define it where we use it when we remove Paper. Paper will access it through `ReactNativePrivateInterface` as well. That will also allow us to remove a few other fields in that interface.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: yungsters

Differential Revision: D43772356

fbshipit-source-id: 78dac152f415f19316ec90887127bf9861fe3110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants