MCPcopy Create free account
hub / github.com/BetaSu/big-react / findHostSubtreeRoot

Function findHostSubtreeRoot

packages/react-reconciler/src/commitWork.ts:113–167  ·  view source on GitHub ↗
(
	finishedWork: FiberNode,
	callback: (hostSubtreeRoot: FiberNode) => void
)

Source from the content-addressed store, hash-verified

111
112// 寻找根host节点,考虑到Fragment,可能存在多个
113function findHostSubtreeRoot(
114 finishedWork: FiberNode,
115 callback: (hostSubtreeRoot: FiberNode) => void
116) {
117 let hostSubtreeRoot = null;
118 let node = finishedWork;
119 while (true) {
120 if (node.tag === HostComponent) {
121 if (hostSubtreeRoot === null) {
122 // 还未发现 root,当前就是
123 hostSubtreeRoot = node;
124 callback(node);
125 }
126 } else if (node.tag === HostText) {
127 if (hostSubtreeRoot === null) {
128 // 还未发现 root,text可以是顶层节点
129 callback(node);
130 }
131 } else if (
132 node.tag === OffscreenComponent &&
133 node.pendingProps.mode === 'hidden' &&
134 node !== finishedWork
135 ) {
136 // 隐藏的OffscreenComponent跳过
137 } else if (node.child !== null) {
138 node.child.return = node;
139 node = node.child;
140 continue;
141 }
142
143 if (node === finishedWork) {
144 return;
145 }
146
147 while (node.sibling === null) {
148 if (node.return === null || node.return === finishedWork) {
149 return;
150 }
151
152 if (hostSubtreeRoot === node) {
153 hostSubtreeRoot = null;
154 }
155
156 node = node.return;
157 }
158
159 // 去兄弟节点寻找,此时当前子树的host root可以移除了
160 if (hostSubtreeRoot === node) {
161 hostSubtreeRoot = null;
162 }
163
164 node.sibling.return = node.return;
165 node = node.sibling;
166 }
167}
168
169function hideOrUnhideAllChildren(finishedWork: FiberNode, isHidden: boolean) {
170 findHostSubtreeRoot(finishedWork, (hostRoot) => {

Callers 1

hideOrUnhideAllChildrenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected