[Suggestion]: Add note with some CSS selector side effects depending on DOM presence to `Activity` troubleshooting
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
Summary
Docs in Activity troubleshooting section,
My hidden components have unwanted side effects, lists <video>, <audio>, and <iframe> as common examples of side effects, but it does not yet cover the category of CSS selectors.
Some common CSS selectors, such as :has() and :is(), may continue to match after the content is hidden by <Activity>, leading to unexpected residual styles.
Page
https://react.dev/reference/react/Activity#troubleshooting
Details
Description
<Activity mode="hidden"> is designed to preserve DOM nodes (applying display: none), which is an intentional design choice. However, most CSS selectors only check the DOM structure and do not consider whether the element is actually visible.
This aligns with the existing explanation in the documentation:
"since a hidden component's DOM is not destroyed, any side effects from that DOM will persist, even after the component is hidden."
The persistent matching of CSS selectors is the exact same kind of DOM side effect, just occurring at the CSS layer,
But, docs doesn't have specific guidance for this type of CSS side effect on DOM. I have some problem to ask for suggestions:
- Does the
useLayoutEffectcleanup pattern mentioned in the docs for<video>also apply to handling this kind of CSS side effect? - Or is this a known limitation of the
<Activity>design that should be explicitly stated in the documentation so developers are aware of it in advance?
Affected Selectors
:has()
/* ⚠️ Still applies after PageA is hidden by Activity */
body:has([data-has="a"]) .banner { background: red; }
:is() / :where()
/* ⚠️ Hidden elements are still matched, causing adjacent sibling styles to persist */
:is(section[data-sibling="a"]) ~ .footer { color: red; }
:where([data-page="a"]) .title { font-weight: bold; }
Demo
https://github.com/fufuShih/demo-react-activtiy-problem
The demo have two toggle modes (unmount / activity) and two page comps (A / B):
HasDemo: Usesbody:has([data-has="a"]) .bannerto detect if Page A is visible. After switching to Page B, the banner should revert to its default color.SiblingDemo: Uses:is(section[data-sibling="a"]) ~ .footerto detect adjacent sibling elements. After switching to Page B, the footer should revert to its default color.
Both behave normally in unmount mode. However, when switched to activity mode, Page A is hidden by <Activity mode="hidden"> but remains in the DOM, causing both selectors to continue matching and preventing the styles from resetting.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Activity 的故障排除部分和链接的演示仓库开始,结合 :has()、:is() 和 :where() 示例,查看现有的关于持久 DOM 副作用的说明。确认 CSS 选择器匹配的预期指导,然后使用准确的说明和解释该行为的示例更新故障排除文档。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- css, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100