From 6f924700ba5da60e8465b24184b7c864c1d7a488 Mon Sep 17 00:00:00 2001 From: zombiej Date: Mon, 25 Apr 2022 10:34:45 +0800 Subject: [PATCH] fix: render compile warning --- src/React/render.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/React/render.ts b/src/React/render.ts index 34a749d3..ae6817eb 100644 --- a/src/React/render.ts +++ b/src/React/render.ts @@ -2,34 +2,32 @@ import type * as React from 'react'; import * as ReactDOM from 'react-dom'; import type { Root } from 'react-dom/client'; -type CreateRoot = (container: ContainerType) => Root; - -type InternalReactDOM = typeof ReactDOM & { +// Let compiler not to search module usage +const fullClone = { + ...ReactDOM, +} as typeof ReactDOM & { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: { usingClientEntryPoint?: boolean; }; createRoot?: CreateRoot; }; -const { - version, - render: reactRender, - unmountComponentAtNode, -} = ReactDOM as InternalReactDOM; +type CreateRoot = (container: ContainerType) => Root; + +const { version, render: reactRender, unmountComponentAtNode } = fullClone; let createRoot: CreateRoot; try { const mainVersion = Number((version || '').split('.')[0]); if (mainVersion >= 18) { - ({ createRoot } = ReactDOM as InternalReactDOM); + ({ createRoot } = fullClone); } } catch (e) { // Do nothing; } function toggleWarning(skip: boolean) { - const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = - ReactDOM as InternalReactDOM; + const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone; if ( __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED &&