fix(message): 修复 StrictMode 下消息入场动画残留固定高度导致折叠卡死#144
Open
SsparKluo wants to merge 1 commit into
Open
Conversation
…ght under StrictMode Dev mode wraps the app in StrictMode, which double-invokes effects (mount -> cleanup -> mount). The previous cleanup only set a `cancelled` flag and cleared the inline height, but never actually cancelled the WAAPI animation, so the first animation kept running in the background. On finish it wrote the final height (260px) back into the DOM, while the .then clear was skipped because `cancelled` was true -- leaving the user bubble pinned at a fixed height after expand. Now hold the animation controls and truly stop() it on cleanup, and clear the inline height regardless of cancellation state. Also clears on both resolve and reject (motion rejects finished on cancel).
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.
问题
开发模式(React StrictMode)下,如果用户消息处于折叠状态且其对应的流式响应尚未结束,展开折叠气泡后 content 溢出、输入区域消失。查看 HTML 可见
style="height: 260px"(即折叠预览高度)锁死在消息 wrapper 上,重新切回 tab 后因组件重建而正常。生产构建(stripped StrictMode)无此问题,deploy/cloudflare 正常运行。
根因
useEntryGrowAnimation用motion/minianimate播放入场动画(0 → scrollHeight)。React StrictMode 在开发模式会双重调用useLayoutEffect:height=\'0px\',启动 WAAPI 动画。cancelled=true+ 清height+ 调用finish()(标记isEntryGrowComplete),但没有真正cancel()掉 WAAPI 动画。isEntryGrowComplete已为 true,effect 提前 return,不再处理动画。onfinish将height:260px写回 DOM。.then中因cancelled=true跳过清空 → 高度固化。修复
animate()返回的controls,cleanup 中调用controls.stop()真正终止后台动画。clear()函数统一负责清空height/clipPath,不依赖cancelled标志。controls.then(clear)同时覆盖 resolve(正常结束)和 reject(被 cancel 时 motion 的 finished promise 会 reject)两种情况。stop()+clear()+finish(),确保在任何卸载路径下 DOM 都被还原。验证
style.height正确还原,布局正常。