Skip to content

Commit

Permalink
Lazy load Fabric renderer in Fantom (#48261)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

This avoids initializing the renderer if the caller doesn't invoke any of the methods that use it.

Differential Revision: D67199972
  • Loading branch information
rubennorte authored and facebook-github-bot committed Dec 13, 2024
1 parent 139ad79 commit 3b63871
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/react-native-fantom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ import type {
import type {MixedElement} from 'react';

import getFantomRenderedOutput from './getFantomRenderedOutput';
import ReactFabric from 'react-native/Libraries/Renderer/shims/ReactFabric';

let globalSurfaceIdCounter = 1;

const nativeRuntimeScheduler = global.nativeRuntimeScheduler;
const schedulerPriorityImmediate =
nativeRuntimeScheduler.unstable_ImmediatePriority;

let ReactFabric = null;
function getReactFabric() {
if (ReactFabric == null) {
ReactFabric =
require('react-native/Libraries/Renderer/shims/ReactFabric').default;
}
return ReactFabric;
}

class Root {
#surfaceId: number;
#hasRendered: boolean = false;
Expand All @@ -38,7 +46,7 @@ class Root {
this.#hasRendered = true;
}

ReactFabric.render(element, this.#surfaceId, () => {}, true);
getReactFabric().render(element, this.#surfaceId, () => {}, true);
}

getMountingLogs(): Array<string> {
Expand Down

0 comments on commit 3b63871

Please sign in to comment.