Skip to content

Commit 710ab60

Browse files
Fix error when reordering filtered nodes
1 parent 34b9027 commit 710ab60

File tree

1 file changed

+56
-58
lines changed

1 file changed

+56
-58
lines changed

src/adapter/shared/traverse.ts

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export function shouldFilter<T extends SharedVNode>(
113113
return true;
114114
}
115115

116+
// TODO: Add a virtual root node to be able to filter the actual
117+
// ones. Currently we have a workaround on the extension side
118+
// that filters it there, but we should really do it here to be
119+
// consistent with all other filters.
120+
116121
if (vnode.type === config.Fragment && filters.type.has("fragment")) {
117122
const parent = bindings.getVNodeParent(vnode);
118123
// Only filter non-root nodes
@@ -121,6 +126,12 @@ export function shouldFilter<T extends SharedVNode>(
121126
return false;
122127
} else if (bindings.isElement(vnode) && filters.type.has("dom")) {
123128
return true;
129+
} else if (filters.type.has("hoc")) {
130+
const name = bindings.getDisplayName(vnode, config);
131+
132+
if (name.indexOf("(") > -1 && !name.startsWith("ForwardRef")) {
133+
return true;
134+
}
124135
}
125136

126137
if (filters.regex.length > 0) {
@@ -169,72 +180,59 @@ function mount<T extends SharedVNode>(
169180
const root = bindings.isRoot(vnode, config);
170181

171182
const skip = shouldFilter(vnode, filters, config, bindings);
172-
173-
if (root || !skip) {
174-
record: {
175-
let name = bindings.getDisplayName(vnode, config);
176-
177-
if (filters.type.has("hoc")) {
178-
const hocName = getHocName(name);
179-
180-
// Filter out HOC-Components
181-
if (hocName) {
182-
if (name.startsWith("ForwardRef")) {
183-
hocs = [...hocs, hocName];
184-
const idx = name.indexOf("(");
185-
name = name.slice(idx + 1, -1) || "Anonymous";
186-
} else {
187-
hocs = [...hocs, hocName];
188-
break record;
189-
}
190-
}
183+
let name = bindings.getDisplayName(vnode, config);
184+
185+
if (filters.type.has("hoc")) {
186+
const hocName = getHocName(name);
187+
if (hocName) {
188+
hocs = [...hocs, hocName];
189+
if (name.startsWith("ForwardRef")) {
190+
const idx = name.indexOf("(");
191+
name = name.slice(idx + 1, -1) || "Anonymous";
191192
}
193+
}
194+
}
192195

193-
const id = getOrCreateVNodeId(ids, vnode);
194-
if (bindings.isRoot(vnode, config)) {
195-
commit.operations.push(MsgTypes.ADD_ROOT, id);
196-
}
196+
if (root || !skip) {
197+
const id = getOrCreateVNodeId(ids, vnode);
198+
if (bindings.isRoot(vnode, config)) {
199+
commit.operations.push(MsgTypes.ADD_ROOT, id);
200+
}
197201

198-
if (!timings.start.has(id)) {
199-
timings.start.set(id, timingsByVNode.start.get(vnode) || 0);
200-
}
201-
if (!timings.end.has(id)) {
202-
timings.end.set(id, timingsByVNode.end.get(vnode) || 0);
203-
}
202+
if (!timings.start.has(id)) {
203+
timings.start.set(id, timingsByVNode.start.get(vnode) || 0);
204+
}
205+
if (!timings.end.has(id)) {
206+
timings.end.set(id, timingsByVNode.end.get(vnode) || 0);
207+
}
204208

205-
commit.operations.push(
206-
MsgTypes.ADD_VNODE,
207-
id,
208-
getDevtoolsType(vnode, bindings), // Type
209-
ancestorId,
210-
9999, // owner
211-
getStringId(commit.strings, name),
212-
vnode.key ? getStringId(commit.strings, vnode.key) : 0,
213-
// Multiply, because operations array only supports integers
214-
// and would otherwise cut off floats
215-
(timings.start.get(id) || 0) * 1000,
216-
(timings.end.get(id) || 0) * 1000,
217-
);
209+
commit.operations.push(
210+
MsgTypes.ADD_VNODE,
211+
id,
212+
getDevtoolsType(vnode, bindings), // Type
213+
ancestorId,
214+
9999, // owner
215+
getStringId(commit.strings, name),
216+
vnode.key ? getStringId(commit.strings, vnode.key) : 0,
217+
// Multiply, because operations array only supports integers
218+
// and would otherwise cut off floats
219+
(timings.start.get(id) || 0) * 1000,
220+
(timings.end.get(id) || 0) * 1000,
221+
);
218222

219-
if (hocs.length > 0) {
220-
addHocs(commit, id, hocs);
221-
hocs = [];
222-
}
223+
if (hocs.length > 0) {
224+
addHocs(commit, id, hocs);
225+
hocs = [];
226+
}
223227

224-
// Capture render reason (mount here)
225-
if (profiler.isProfiling && profiler.captureRenderReasons) {
226-
commit.operations.push(
227-
MsgTypes.RENDER_REASON,
228-
id,
229-
RenderReason.MOUNT,
230-
0,
231-
);
232-
}
228+
// Capture render reason (mount here)
229+
if (profiler.isProfiling && profiler.captureRenderReasons) {
230+
commit.operations.push(MsgTypes.RENDER_REASON, id, RenderReason.MOUNT, 0);
231+
}
233232

234-
updateHighlight(profiler, vnode, bindings);
233+
updateHighlight(profiler, vnode, bindings);
235234

236-
ancestorId = id;
237-
}
235+
ancestorId = id;
238236
}
239237

240238
if (skip && !bindings.isComponent(vnode)) {

0 commit comments

Comments
 (0)