优化渲染节点功能,使用 ref 文件渲染大量节点
Build Push and Deploy / docker-image (push) Successful in 7s
Build Push and Deploy / deploy-fallback-log (push) Has been skipped

This commit is contained in:
2026-05-18 16:15:38 +08:00
parent 39ee9a02e5
commit e4424b87d1
5 changed files with 140 additions and 76 deletions
+35 -2
View File
@@ -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"