Skip to content

Commit 89ef26e

Browse files
committed
Fix ImageZoom, Vencord Notifications & ReactErrorDecoder
1 parent 9a3c66a commit 89ef26e

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/api/Notifications/Notifications.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import { Settings } from "@api/Settings";
2020
import { Queue } from "@utils/Queue";
21-
import { ReactDOM } from "@webpack/common";
21+
import { createRoot } from "@webpack/common";
2222
import type { ReactNode } from "react";
2323
import type { Root } from "react-dom/client";
2424

@@ -35,7 +35,7 @@ function getRoot() {
3535
const container = document.createElement("div");
3636
container.id = "vc-notification-container";
3737
document.body.append(container);
38-
reactRoot = ReactDOM.createRoot(container);
38+
reactRoot = createRoot(container);
3939
}
4040
return reactRoot;
4141
}

src/plugins/consoleShortcuts/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function makeShortcuts() {
136136
});
137137
}
138138

139-
const root = Common.ReactDOM.createRoot(doc.body.appendChild(document.createElement("div")));
139+
const root = Common.createRoot(doc.body.appendChild(document.createElement("div")));
140140
root.render(Common.React.createElement(component, props));
141141

142142
doc.addEventListener("close", () => root.unmount(), { once: true });

src/plugins/imageZoom/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { debounce } from "@shared/debounce";
2323
import { Devs } from "@utils/constants";
2424
import { Logger } from "@utils/Logger";
2525
import definePlugin, { OptionType } from "@utils/types";
26-
import { Menu, ReactDOM } from "@webpack/common";
26+
import { createRoot, Menu } from "@webpack/common";
2727
import { JSX } from "react";
2828
import type { Root } from "react-dom/client";
2929

@@ -242,7 +242,7 @@ export default definePlugin({
242242
if (instance.props.id === ELEMENT_ID) {
243243
if (!this.currentMagnifierElement) {
244244
this.currentMagnifierElement = <Magnifier size={settings.store.size} zoom={settings.store.zoom} instance={instance} />;
245-
this.root = ReactDOM.createRoot(this.element!);
245+
this.root = createRoot(this.element!);
246246
this.root.render(this.currentMagnifierElement);
247247
}
248248
}

src/plugins/reactErrorDecoder/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ import { Devs } from "@utils/constants";
2020
import definePlugin from "@utils/types";
2121
import { React } from "@webpack/common";
2222

23-
let ERROR_CODES: any;
23+
let ERROR_CODES: Record<string, string> | undefined;
2424

2525
export default definePlugin({
2626
name: "ReactErrorDecoder",
2727
description: 'Replaces "Minifed React Error" with the actual error.',
2828
authors: [Devs.Cyn, Devs.maisymoe],
2929
patches: [
3030
{
31-
find: '"https://reactjs.org/docs/error-decoder.html?invariant="',
31+
find: "React has blocked a javascript: URL as a security precaution.",
3232
replacement: {
33-
match: /(function .\(.\)){(for\(var .="https:\/\/reactjs\.org\/docs\/error-decoder\.html\?invariant="\+.,.=1;.<arguments\.length;.\+\+\).\+="&args\[\]="\+encodeURIComponent\(arguments\[.\]\);return"Minified React error #"\+.\+"; visit "\+.\+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.")}/,
34-
replace: (_, func, original) =>
35-
`${func}{var decoded=$self.decodeError.apply(null, arguments);if(decoded)return decoded;${original}}`,
36-
},
37-
},
33+
match: /"https:\/\/react.dev\/errors\/"\+\i;/,
34+
replace: "$&const vcDecodedError=$self.decodeError(...arguments);if(vcDecodedError)return vcDecodedError;"
35+
}
36+
}
3837
],
3938

4039
async start() {
@@ -56,5 +55,5 @@ export default definePlugin({
5655
index++;
5756
return arg;
5857
});
59-
},
58+
}
6059
});

src/webpack/common/react.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
// eslint-disable-next-line path-alias/no-relative
20-
import { findByPropsLazy, waitFor } from "../webpack";
20+
import { findByCodeLazy, findByPropsLazy, waitFor } from "../webpack";
2121

2222
export let React: typeof import("react");
2323
export let useState: typeof React.useState;
@@ -28,7 +28,9 @@ export let useRef: typeof React.useRef;
2828
export let useReducer: typeof React.useReducer;
2929
export let useCallback: typeof React.useCallback;
3030

31-
export const ReactDOM: typeof import("react-dom") & typeof import("react-dom/client") = findByPropsLazy("createPortal");
31+
export const ReactDOM: typeof import("react-dom") = findByPropsLazy("createPortal");
32+
// 299 is an error code used in createRoot and createPortal
33+
export const createRoot: typeof import("react-dom/client").createRoot = findByCodeLazy("(299));", ".onRecoverableError");
3234

3335
waitFor("useState", m => {
3436
React = m;

0 commit comments

Comments
 (0)