Skip to content

Commit 8e649bc

Browse files
committed
feat: 使用 startTransition 优化 Modal 和 Explore 页面状态更新
1 parent 3b7bdb8 commit 8e649bc

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/components/Modal.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect, useState } from "react";
3+
import { startTransition, useEffect, useState } from "react";
44
import { X } from "lucide-react";
55

66
interface ModalProps {
@@ -30,13 +30,15 @@ export function Modal({
3030
// Handle visibility transitions and initial sync
3131
useEffect(() => {
3232
if (isOpen) {
33-
setIsVisible(true);
34-
setIsClosing(false);
35-
setCachedChildren(children);
36-
setCachedTitle(title);
33+
startTransition(() => {
34+
setIsVisible(true);
35+
setIsClosing(false);
36+
setCachedChildren(children);
37+
setCachedTitle(title);
38+
});
3739
} else if (isVisible && !isClosing) {
3840
// Start closing animation if we are currently visible and not already closing
39-
setIsClosing(true);
41+
startTransition(() => setIsClosing(true));
4042
}
4143
}, [isOpen, isVisible, isClosing, children, title]);
4244

app/explore/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3+
import { forwardRef, startTransition, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
44
import { Area, AreaChart, CartesianGrid, ComposedChart, ReferenceLine, ResponsiveContainer, Scatter, Tooltip, XAxis, YAxis } from "recharts";
55
import { formatCompactNumber, formatNumberWithCommas } from "@/lib/utils";
66

@@ -210,7 +210,7 @@ function useLerpYDomain(
210210
// Sync domain when target changes or animation is disabled
211211
useEffect(() => {
212212
if (!targetDomain || !enabled) {
213-
setCurrentDomain(targetDomain);
213+
startTransition(() => setCurrentDomain(targetDomain));
214214
}
215215
}, [targetDomain, enabled]);
216216

0 commit comments

Comments
 (0)