From 26610aeaa807857b2226848270cd302d110cbff7 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:16:40 +0200 Subject: [PATCH] fix a react safety issue --- .../components/ModConfView/libs.ts | 38 ++++++++++++------- src/native/IsolatedEval/index.ts | 3 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/activitys/ModConfActivity/components/ModConfView/libs.ts b/src/activitys/ModConfActivity/components/ModConfView/libs.ts index 8dc720fd..cb32d3a8 100644 --- a/src/activitys/ModConfActivity/components/ModConfView/libs.ts +++ b/src/activitys/ModConfActivity/components/ModConfView/libs.ts @@ -29,21 +29,23 @@ import { IsolatedFunctionBlockError } from "@Native/IsolatedEval/IsolatedFunctio import { Terminal } from "@Native/Terminal"; import { useFetch } from "@Hooks/useFetch"; -export const libraries = { - react: { - ...require("react"), - createElement(type: any, props: any, ...children: any[]) { - switch (type) { - // prevents webview url change - case "a": - return React.createElement(Anchor, props, ...children); - case "iframe": - throw new IsolatedFunctionBlockError("iframe"); - default: - return React.createElement(type, props, ...children); - } - }, +export const InternalReact = { + ...require("react"), + createElement(type: any, props: any, ...children: any[]) { + switch (type) { + // prevents webview url change + case "a": + return React.createElement(Anchor, props, ...children); + case "iframe": + throw new IsolatedFunctionBlockError("iframe"); + default: + return React.createElement(type, props, ...children); + } }, +}; + +export const libraries = { + react: InternalReact, "@mui/material": require("@mui/material"), @@ -106,4 +108,12 @@ export const libraries = { }, modfs: require("modfs"), "default-composer": require("default-composer"), + "usehooks-ts": { + ...require("usehooks-ts"), + useLocalStorage: undefined, + useScript: undefined, + useSessionStorage: undefined, + useDocumentTitle: undefined, + useDarkMode: undefined, + }, }; diff --git a/src/native/IsolatedEval/index.ts b/src/native/IsolatedEval/index.ts index 0e0f8f3b..406ef5e0 100644 --- a/src/native/IsolatedEval/index.ts +++ b/src/native/IsolatedEval/index.ts @@ -21,6 +21,7 @@ import { IsoDocument } from "./IsoDocument"; import { IsoXMLSerializer } from "./IsoXMLSerializer"; import { IsolatedEvalError } from "./IsolatedEvalError"; import { IsolatedFunctionBlockError } from "./IsolatedFunctionBlockError"; +import { InternalReact } from "@Activitys/ModConfActivity/components/ModConfView/libs"; type IsoModule = { exports: { @@ -71,7 +72,7 @@ class IsolatedEval { BuildConfig: BuildConfig, Build: Build, Native: Native, - React: React, + React: InternalReact, setInterval: setInterval, clearInterval: clearInterval, clearTimeout: clearTimeout,