[sync] feat(x): support destroyOnHidden on Think and ThoughtChain (#1985) - #166
Merged
Conversation
Expose destroyOnHidden on Think and on ThoughtChain items, defaulting to true so collapsed content keeps being destroyed. Setting it to false keeps the content node mounted and only hides it, preserving streaming output and inner component state across a collapse. Sync ant-design/x#1985. close #145
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.
背景
同步上游 ant-design/x#1985(merge commit
818b6e05999886ce11b9b79ebf111a38aca09d95)。为 Think 与 ThoughtChain 暴露
destroyOnHidden,让使用方决定折叠时内容是被销毁还是保留在 DOM 中。与上游实现的差异(重点)
上游 React 侧是把标志透传给 rc-motion 的
removeOnLeave。Vue 侧没有对应能力,因此改为:destroyOnHidden: true(默认)— 保持原有Transition+ 条件渲染,折叠后节点被销毁destroyOnHidden: false— 用withDirectives(node, [[vShow, expanded]])让节点常驻、仅display: noneTransition与v-show组合是 Vue 官方支持的用法,vShow指令会复用 vnode 上的 transition 钩子,因此原有的 height/opacity 折叠动画不受影响,onAfterLeave仍会清空 height/opacity。另外,默认路径下不会构造内容 vnode(
slots.default不被调用),与改动前行为完全一致,避免折叠状态下的无谓渲染。实现范围
Think.tsx:新增destroyOnHiddenprop,默认truethought-chain/Node.tsx:读取item.destroyOnHidden ?? trueinterface.ts补类型与@default truedemo/destroy-on-hidden.vue各一个验收标准
destroyOnHidden=false时 DOM 与内部状态跨折叠保留onAfterLeave)vp check/vp test— 本地环境无 Node 运行时,未执行,需在 CI 或有 Node 的环境确认关于测试
单测刻意避开了 transition 时序(jsdom 下 leave 依赖 rAF/transitionend),改为断言「折叠后仍是同一个 DOM 节点、且折叠前写入 input 的值仍在」,这正是
destroyOnHidden=false要保证的语义,且不受动画完成时机影响。Ref #149
close #145