Skip to content

Commit

Permalink
fix a react safety issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Aug 29, 2024
1 parent 6e5b2fe commit 26610ae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/activitys/ModConfActivity/components/ModConfView/libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand Down Expand Up @@ -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,
},
};
3 changes: 2 additions & 1 deletion src/native/IsolatedEval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -71,7 +72,7 @@ class IsolatedEval<T = any> {
BuildConfig: BuildConfig,
Build: Build,
Native: Native,
React: React,
React: InternalReact,
setInterval: setInterval,
clearInterval: clearInterval,
clearTimeout: clearTimeout,
Expand Down

0 comments on commit 26610ae

Please sign in to comment.