From 4fa43d00bddb7582cf872fe7f3a06a4ba271c3ee Mon Sep 17 00:00:00 2001 From: kujtimprenkuSQA Date: Mon, 23 Oct 2023 12:32:34 +0200 Subject: [PATCH 1/3] Make sure createRoot is run only once in modal-ui. --- packages/modal-ui/src/lib/modal.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/modal-ui/src/lib/modal.tsx b/packages/modal-ui/src/lib/modal.tsx index 404143a6e..8e8550581 100644 --- a/packages/modal-ui/src/lib/modal.tsx +++ b/packages/modal-ui/src/lib/modal.tsx @@ -1,4 +1,5 @@ import React from "react"; +import type { Root } from "react-dom/client"; import { createRoot } from "react-dom/client"; import type { WalletSelector } from "@near-wallet-selector/core"; @@ -10,6 +11,7 @@ import type { ModalEvents } from "./modal.types"; const MODAL_ELEMENT_ID = "near-wallet-selector-modal"; let modalInstance: WalletSelectorModal | null = null; +let root: Root | null = null; /** * Initiates a modal instance @@ -21,18 +23,19 @@ export const setupModal = ( selector: WalletSelector, options: ModalOptions ): WalletSelectorModal => { - const el = document.createElement("div"); - el.id = MODAL_ELEMENT_ID; - if (!document.getElementById(MODAL_ELEMENT_ID)) { - document.body.appendChild(el); + if (!root) { + const body = document.body; + const container = document.createElement("div"); + container.id = MODAL_ELEMENT_ID; + body.appendChild(container); + + root = createRoot(container); } - const container = document.getElementById(MODAL_ELEMENT_ID); - const root = createRoot(container!); const emitter = new EventEmitter(); const render = (visible = false) => { - root.render( + root!.render( Date: Mon, 23 Oct 2023 12:38:23 +0200 Subject: [PATCH 2/3] Make sure createRoot is run only once in account-export. --- packages/account-export/src/lib/index.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/account-export/src/lib/index.tsx b/packages/account-export/src/lib/index.tsx index ac70d97fd..9e9ab5ca3 100644 --- a/packages/account-export/src/lib/index.tsx +++ b/packages/account-export/src/lib/index.tsx @@ -1,4 +1,5 @@ import React from "react"; +import type { Root } from "react-dom/client"; import { createRoot } from "react-dom/client"; import type { WalletSelector } from "@near-wallet-selector/core"; @@ -9,22 +10,23 @@ import { ExportSelector } from "./components/ExportSelector"; const MODAL_ELEMENT_ID = "near-wallet-selector-modal"; let importModalInstance: WalletSelectorModal | null = null; +let root: Root | null = null; export const setupExportSelectorModal = ( selector: WalletSelector, options: ExportSelectorOptions ): WalletSelectorModal => { - const el = document.createElement("div"); - el.id = MODAL_ELEMENT_ID; - if (!document.getElementById(MODAL_ELEMENT_ID)) { - document.body.appendChild(el); - } + if (!root) { + const body = document.body; + const container = document.createElement("div"); + container.id = MODAL_ELEMENT_ID; + body.appendChild(container); - const container = document.getElementById(MODAL_ELEMENT_ID); - const root = createRoot(container!); + root = createRoot(container); + } const render = (visible: boolean) => { - root.render( + root!.render( Date: Mon, 23 Oct 2023 12:47:49 +0200 Subject: [PATCH 3/3] Log success message only once. --- scripts/update-package-json.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update-package-json.js b/scripts/update-package-json.js index d1c6a3f6f..dd4971e51 100644 --- a/scripts/update-package-json.js +++ b/scripts/update-package-json.js @@ -18,7 +18,6 @@ async function updatePackageJSONTypeField(packageName) { if (packageJson.types) { packageJson.types = fixPath(packageJson.types); await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); - console.log(`Updated package.json for ${packageName}`); } else { console.log(`No 'types' field found in package.json for ${packageName}`); } @@ -35,6 +34,8 @@ async function updateAllPackagesTypeField() { for (const packageName of packageNames) { await updatePackageJSONTypeField(packageName); } + console.log(`Successfully updated types path in package.json for all packages`); + } catch (error) { console.error('Error reading packages directory:', error); }