feat: 增加 saveScrollPositionIgnoreNodeIds 属性以支持忽略特定元素的滚动位置缓存 #349
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-activation进行组件状态保持时,saveScrollPosition功能会自动保存和恢复页面中所有可滚动元素的滚动位置。哪怕滚动元素在KeepAlive包裹之外,但在某些业务场景中,我们需要对特定的元素进行例外处理,比如:解决方案
新增
saveScrollPositionIgnoreNodeIds属性,允许指定要忽略滚动位置缓存的元素ID列表。主要修改内容
1. 类型定义更新 (
index.d.ts)2. 核心逻辑修改 (
src/core/KeepAlive.js)eject方法中接收新的saveScrollPositionIgnoreNodeIds属性saveScrollPosition函数3. 滚动位置保存函数增强 (
src/helpers/saveScrollPosition.js)options参数支持,包含ignoreNodeIds配置4. 文档更新 (
README.md&README_CN.md)使用示例