Skip to content

Commit

Permalink
[RNMobile] Prevent calling the registerComponent callback multiple ti…
Browse files Browse the repository at this point in the history
…mes (#32985)

* Prevent calling pre-render WP hook multiple times

* Use class component for app registry
  • Loading branch information
fluiddot authored Jul 15, 2021
1 parent db76f67 commit a7ba291
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions packages/element/src/react-platform.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,34 @@ import { applyFilters, doAction } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { cloneElement } from './react';
import { Component, cloneElement } from './react';

const render = ( element, id ) =>
AppRegistry.registerComponent( id, () => ( propsFromParent ) => {
const parentProps = omit( propsFromParent || {}, [ 'rootTag' ] );
const render = ( element, id ) => {
class App extends Component {
constructor() {
super( ...arguments );

doAction( 'native.pre-render', parentProps );
const parentProps = omit( this.props || {}, [ 'rootTag' ] );

const filteredProps = applyFilters(
'native.block_editor_props',
parentProps
);
doAction( 'native.pre-render', parentProps );

doAction( 'native.render', filteredProps );
this.filteredProps = applyFilters(
'native.block_editor_props',
parentProps
);
}

return cloneElement( element, filteredProps );
} );
componentDidMount() {
doAction( 'native.render', this.filteredProps );
}

render() {
return cloneElement( element, this.filteredProps );
}
}

AppRegistry.registerComponent( id, () => App );
};

/**
* Render a given element on Native.
Expand Down

0 comments on commit a7ba291

Please sign in to comment.