Repository navigation
Conversation
setProgress 的 updater 函数内嵌 setActiveFun()(父 state 更新)—— React 要求 updater 必须是纯函数:StrictMode 与中断/重放的并发渲染 可能重复调用 updater,导致轮播跳标签双触发(当前被 next.config.js 的 reactStrictMode: false 和幂等的 next-name 计算掩盖,任何未来 改为索引推进的修改都会双跳)。 改为纯 updater(推进/归零)+ 独立 effect 在 progress >= 101 时 调用 activeFunRef.current()。setActiveFun 存 ref:父组件传的 inline 闭包每次渲染都是新引用,放在 effect deps 里导致 interval 频繁重建。
|
@zjncs is attempting to deploy a commit to the codersett's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Timer.tsx:15-30callssetActiveFun()(parent state update) inside asetProgressupdater:Two React-contract violations:
reactStrictMode: falseand an idempotent next-name computation; any future non-idempotent change (e.g., advancing an index) double-skips tabs.setActiveFunis a fresh inline closure every parent render and sits in the effect deps, so the interval is torn down/recreated on each parent re-render.Fix
useEffectonprogresssetActiveFunin a ref to stop the interval churnVerification
Component structure verified: the updater now only computes the next progress value; the advance callback fires from a dedicated effect exactly once per cycle completion.
Risk
None — behavior is identical for the current (StrictMode-off, idempotent) configuration; the fix makes it correct for the general case.