This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the "empty props" type in React */
|
||||
import type { Node, NodePathMap } from "godot"
|
||||
import { Callable, type Node, type NodePathMap } from "godot"
|
||||
import * as React from "react"
|
||||
import * as Reconciler from "./Reconciler.js"
|
||||
|
||||
@@ -21,10 +21,11 @@ export const renderComponent: {
|
||||
component: React.FC<{}>,
|
||||
props?: Record<string, unknown>,
|
||||
): void => {
|
||||
const reconciler = Reconciler.make()
|
||||
if (!(container as any)._reactReconciler)
|
||||
(container as any)._reactReconciler = Reconciler.make()
|
||||
|
||||
if (!(container as any)._rootContainer)
|
||||
(container as any)._rootContainer = (reconciler as any).createContainer(
|
||||
if (!(container as any)._reactContainer) {
|
||||
(container as any)._reactContainer = (container as any)._reactReconciler.createContainer(
|
||||
container,
|
||||
ConcurrentRoot,
|
||||
null,
|
||||
@@ -34,9 +35,23 @@ export const renderComponent: {
|
||||
console.error,
|
||||
)
|
||||
|
||||
reconciler.updateContainer(
|
||||
const cleanup = Callable.create(container, function(this) {
|
||||
(container as any)._reactReconciler.updateContainer(
|
||||
null,
|
||||
(container as any)._reactContainer,
|
||||
null,
|
||||
)
|
||||
delete (container as any)._reactReconciler
|
||||
delete (container as any)._reactContainer
|
||||
|
||||
container.tree_exiting.disconnect(cleanup)
|
||||
})
|
||||
container.tree_exiting.connect(cleanup)
|
||||
}
|
||||
|
||||
(container as any)._reactReconciler.updateContainer(
|
||||
React.createElement(component, props),
|
||||
(container as any)._rootContainer,
|
||||
(container as any)._reactContainer,
|
||||
null,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user