优化渲染节点功能,使用 ref 文件渲染大量节点
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Box, Drawer, alpha, useTheme } from "@mui/material";
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Box, Drawer, alpha, useMediaQuery, useTheme } from "@mui/material";
|
||||
|
||||
import type { AgentModel } from "@/lib/chatStream";
|
||||
import { AgentComposer } from "./AgentComposer";
|
||||
@@ -27,6 +33,7 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const theme = useTheme();
|
||||
const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
|
||||
|
||||
const {
|
||||
speechState,
|
||||
@@ -158,6 +165,32 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
|
||||
};
|
||||
}, [isResizing]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const body = document.body;
|
||||
const html = document.documentElement;
|
||||
const previousBodyPaddingRight = body.style.paddingRight;
|
||||
const previousBodyTransition = body.style.transition;
|
||||
const previousBodyBoxSizing = body.style.boxSizing;
|
||||
const previousHtmlBoxSizing = html.style.boxSizing;
|
||||
const reservedWidth = open && isDesktop ? `${width}px` : "0px";
|
||||
|
||||
body.style.boxSizing = "border-box";
|
||||
html.style.boxSizing = "border-box";
|
||||
body.style.paddingRight = reservedWidth;
|
||||
body.style.transition = isResizing
|
||||
? previousBodyTransition
|
||||
: [previousBodyTransition, "padding-right 240ms cubic-bezier(0.2, 0.8, 0.2, 1)"]
|
||||
.filter(Boolean)
|
||||
.join(", ");
|
||||
|
||||
return () => {
|
||||
body.style.paddingRight = previousBodyPaddingRight;
|
||||
body.style.transition = previousBodyTransition;
|
||||
body.style.boxSizing = previousBodyBoxSizing;
|
||||
html.style.boxSizing = previousHtmlBoxSizing;
|
||||
};
|
||||
}, [isDesktop, isResizing, open, width]);
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
anchor="right"
|
||||
|
||||
Reference in New Issue
Block a user