Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix Already passed to createRoot() warning #982

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/account-export/src/lib/index.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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(
<ExportSelector
selector={selector}
options={options}
Expand Down
17 changes: 10 additions & 7 deletions packages/modal-ui/src/lib/modal.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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
Expand All @@ -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<ModalEvents>();

const render = (visible = false) => {
root.render(
root!.render(
<Modal
selector={selector}
options={options}
Expand Down
3 changes: 2 additions & 1 deletion scripts/update-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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);
}
Expand Down