Skip to content

Commit 11e2a2f

Browse files
Merge pull request #353 from preactjs/placeholder-highlight
Fix highlight error if child is a placeholder
2 parents c28c050 + 4eec414 commit 11e2a2f

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/adapter/shared/traverse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ function updateHighlight<T extends SharedVNode>(
4848
bindings: PreactBindings<T>,
4949
) {
5050
if (profiler.highlightUpdates && bindings.isComponent(vnode)) {
51-
const stack: any[] = [vnode];
51+
const stack: Array<T | null | undefined> = [vnode];
5252
let item;
5353
let dom;
5454
while ((item = stack.shift()) !== undefined) {
55+
// Account for placholders/holes
56+
if (item === null) continue;
57+
5558
if (!bindings.isComponent(item)) {
5659
dom = bindings.getDom(item);
5760
break;

test-e2e/fixtures/apps/holes.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { h, render } from "preact";
2+
import { useState } from "preact/hooks";
3+
4+
function Foo(props) {
5+
return props.children;
6+
}
7+
8+
function App() {
9+
const [v, set] = useState(0);
10+
11+
return (
12+
<Foo>
13+
{v % 2 === 0 && "Not a placeholder"}
14+
<button onClick={() => set(v + 1)}>Increment</button>
15+
</Foo>
16+
);
17+
}
18+
19+
render(<App />, document.getElementById("app"));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
newTestPage,
3+
click,
4+
clickTab,
5+
waitForSelector,
6+
} from "../../test-utils";
7+
import { expect } from "chai";
8+
import { clickSelector } from "pentf/browser_utils";
9+
10+
export const description = "Check if highlight updates is rendered";
11+
12+
export async function run(config: any) {
13+
const { page, devtools } = await newTestPage(config, "holes");
14+
await waitForSelector(page, "button");
15+
16+
await clickTab(devtools, "SETTINGS");
17+
await click(devtools, '[data-testId="toggle-highlight-updates"]');
18+
19+
const errors: string[] = [];
20+
page.on("pageerror", err => errors.push(err.toString()));
21+
22+
await clickSelector(page, "button");
23+
await clickSelector(page, "button");
24+
25+
expect(errors).to.deep.equal([]);
26+
}

0 commit comments

Comments
 (0)