diff --git a/components/ChainConnect/ChainsGroup.tsx b/components/ChainConnect/ChainsGroup.tsx index 96007db..6feaa50 100644 --- a/components/ChainConnect/ChainsGroup.tsx +++ b/components/ChainConnect/ChainsGroup.tsx @@ -1,7 +1,7 @@ import { ChainInfo } from "@/context/ChainsContext/types"; +import { useEffect, useRef, useState } from "react"; import { CommandGroup } from "../ui/command"; import ChainItem from "./ChainItem"; -import { useRef } from "react"; interface ChainsGroupProps { readonly chains: readonly ChainInfo[]; @@ -11,6 +11,16 @@ interface ChainsGroupProps { export default function ChainsGroup({ chains, heading, emptyMsg }: ChainsGroupProps) { const containerRef = useRef(null); + const [numChainsToRender, setNumChainsToRender] = useState(10); + + useEffect(() => { + // Unblock the main thread + setTimeout(() => { + if (numChainsToRender < chains.length) { + setNumChainsToRender((prev) => prev + 10); + } + }, 0); + }, [chains.length, numChainsToRender]); return ( {chains.length ? (
- {chains.map((chain) => ( + {chains.slice(0, numChainsToRender).map((chain) => ( ([]); - useLayoutEffect(() => { - const newRecentChains = getRecentChainsFromStorage(chains); - setRecentChains(newRecentChains); + useEffect(() => { + // Unblock the main thread + setTimeout(() => { + const newRecentChains = getRecentChainsFromStorage(chains); + setRecentChains(newRecentChains); + }, 0); }, [chains]); return ( diff --git a/components/ChainConnect/CustomChainForm.tsx b/components/ChainConnect/CustomChainForm.tsx index 5d6c9c3..8458272 100644 --- a/components/ChainConnect/CustomChainForm.tsx +++ b/components/ChainConnect/CustomChainForm.tsx @@ -3,6 +3,7 @@ import { setNewConnection } from "@/context/ChainsContext/helpers"; import { RegistryAsset } from "@/types/chainRegistry"; import { zodResolver } from "@hookform/resolvers/zod"; import dynamic from "next/dynamic"; +import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import * as z from "zod"; import { Button } from "../ui/button"; @@ -21,6 +22,14 @@ const JsonEditor = dynamic(() => import("../inputs/JsonEditor"), { ssr: false }) export default function CustomChainForm() { const { chain, chains, newConnection, chainsDispatch } = useChains(); + const [showAssetsEditor, setShowAssetsEditor] = useState(false); + + useEffect(() => { + // Unblock the main thread + setTimeout(() => { + setShowAssetsEditor(true); + }, 0); + }, []); const formSchema = z .object({ @@ -246,25 +255,27 @@ export default function CustomChainForm() { )} /> - ( - - Assets - -
- { - field.onChange("text" in newMsgContent ? newMsgContent.text ?? "{}" : "{}"); - }} - /> -
-
- -
- )} - /> + {showAssetsEditor ? ( + ( + + Assets + +
+ { + field.onChange("text" in newMsgContent ? newMsgContent.text ?? "{}" : "{}"); + }} + /> +
+
+ +
+ )} + /> + ) : null} diff --git a/components/inputs/JsonEditor.tsx b/components/inputs/JsonEditor.tsx index 1986c57..fe59ff5 100644 --- a/components/inputs/JsonEditor.tsx +++ b/components/inputs/JsonEditor.tsx @@ -28,9 +28,9 @@ export default function JsonEditor({ label, ...editorProps }: JsonEditorProps) { const refEditor = useRef(null); useEffect(() => { - if (!refContainer.current) return; - - refEditor.current = new VanillaJsonEditor({ target: refContainer.current, props: {} }); + if (refContainer.current) { + refEditor.current = new VanillaJsonEditor({ target: refContainer.current, props: {} }); + } return () => { if (refEditor.current) {