Skip to content

Commit 09cc7d1

Browse files
Merge pull request #460 from preactjs/inspect-signal-hook
2 parents 987e81f + 0a06da9 commit 09cc7d1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/adapter/shared/hooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ export function inspectHooks<T extends SharedVNode>(
332332
c.constructor.call(dummy, dummy.props, dummy.context);
333333
}
334334
}
335+
336+
// Signals need this, otherwise they end up in an incosnistent state
337+
const diffedHook = options.diffed;
338+
if (diffedHook) diffedHook(vnode as any);
335339
} catch (error) {
336340
// We don't care about any errors here. We only need
337341
// the hook call sites

test-e2e/tests/inspect-signal.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,32 @@ test("Dectect signal subscriptions", async ({ page }) => {
105105

106106
await page.locator("p:has-text('count: 10, double: 20')").waitFor();
107107
});
108+
109+
// https://github.com/preactjs/preact-devtools/issues/456
110+
test("Don't crash when signal hook is updated", async ({ page }) => {
111+
test.skip(
112+
process.env.PREACT_VERSION !== "10",
113+
"Signals are not supported in v11 yet.",
114+
);
115+
const { devtools } = await gotoTest(page, "signals");
116+
117+
await devtools.click(locateTreeItem("Counter"));
118+
await devtools.waitForSelector('[data-testid="props-row"]');
119+
120+
await devtools.click(
121+
'[data-testid="Hooks"] form [data-testid="props-row"]:first-child button',
122+
);
123+
124+
await devtools.waitForSelector(
125+
'[data-testid="Hooks"] [data-testid="prop-value"]:has-text("ƒ Signal (0)")',
126+
);
127+
128+
await page.click("button:has-text('Add')");
129+
await page.click("button:has-text('Add')");
130+
131+
await devtools.click(locateTreeItem("Display"));
132+
await expect(devtools.locator('[data-testid="Hooks"]')).toHaveCount(0);
133+
134+
await devtools.click(locateTreeItem("Counter"));
135+
await expect(devtools.locator('[data-testid="Hooks"]')).toHaveCount(1);
136+
});

0 commit comments

Comments
 (0)