From 11dd82bbb1814ac4d2fa9d381372e325daba2558 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Tue, 12 Dec 2023 22:07:59 -0500 Subject: [PATCH] fix(utils/react): support react 18, add getReactRoot --- src/utils/react.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/react.ts b/src/utils/react.ts index 04b2c6ff..5c5e6451 100644 --- a/src/utils/react.ts +++ b/src/utils/react.ts @@ -58,13 +58,25 @@ export function wrapReactClass(node: any, prop: any = 'type') { return node[prop]; } else { const cls = node[prop]; - const wrappedCls = class extends cls { static __DECKY_WRAPPED = true; }; + const wrappedCls = class extends cls { + static __DECKY_WRAPPED = true; + }; return (node[prop] = wrappedCls); } } +export function getReactRoot(o: HTMLElement | Element | Node) { + return ( + o[Object.keys(o).find((k) => k.startsWith('__reactContainer$')) as string] || + o['_reactRootContainer']?._internalRoot?.current + ); +} + export function getReactInstance(o: HTMLElement | Element | Node) { - return o[Object.keys(o).find((k) => k.startsWith('__reactInternalInstance')) as string]; + return ( + o[Object.keys(o).find((k) => k.startsWith('__reactFiber')) as string] || + o[Object.keys(o).find((k) => k.startsWith('__reactInternalInstance')) as string] + ); } // Based on https://github.com/GooseMod/GooseMod/blob/9ef146515a9e59ed4e25665ed365fd72fc0dcf23/src/util/react.js#L20