Skip to content

Commit 1036aa4

Browse files
author
Bertan Ari
committed
test(modes): relax over-strict Profiler assertion in McpServerRestriction Test 3
`<Profiler onRender>` fires whenever the Profiler boundary commits, which happens whenever its parent re-renders — even when every child inside bails out via React.memo. The `=== 0` assertion in Test 3 part (b) therefore measured the Profiler's own commit cadence rather than the child's render work. Relax to `<= 1` and document the caveat in the test's JSDoc. The real anti-flicker guarantee is verified by Test 2 (DOM-node identity preserved across an equivalent `mcpServers` heartbeat). No production code changed.
1 parent 74703b6 commit 1036aa4

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎webview-ui/src/components/modes/__tests__/McpServerRestriction.spec.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ describe("McpServerRestriction subcomponent — flicker regressions", () => {
287287
* React.memo + the stable `customMode`/`onCommit` props.
288288
*
289289
* Fake timers prevent the debounced flush from firing during the test.
290+
*
291+
* NOTE on (b): we assert `<= 1` rather than `=== 0`. `<Profiler onRender>`
292+
* fires whenever the Profiler boundary commits, which happens whenever its
293+
* parent re-renders — even when every child inside bails out via
294+
* React.memo. So an equivalent-heartbeat rerender of the parent `Tree` will
295+
* still produce one Profiler callback with `phase: "update"` and ~0
296+
* `actualDuration`, regardless of memo. The real anti-flicker guarantee is
297+
* verified by Test 2 (DOM-node identity preserved across heartbeat); here
298+
* we just bound the child's render work to at most one commit.
290299
*/
291300
it("Test 3: profiler — 1 commit per click, 0 commits on equivalent mcpServers heartbeat", () => {
292301
vitest.useFakeTimers()
@@ -322,7 +331,11 @@ describe("McpServerRestriction subcomponent — flicker regressions", () => {
322331
// which is what a properly-memoized parent would do.
323332
rerender(<Tree servers={mcpServers} />)
324333
const afterHeartbeatCommits = onRender.mock.calls.length
325-
expect(afterHeartbeatCommits - afterClickCommits).toBe(0)
334+
// See JSDoc NOTE on (b): Profiler commits with its parent even when
335+
// React.memo bails out, so this delta is 1 (the Profiler callback itself),
336+
// not 0. The child's render work is still bounded — Test 2 proves the
337+
// server-list DOM node is preserved across the heartbeat.
338+
expect(afterHeartbeatCommits - afterClickCommits).toBeLessThanOrEqual(1)
326339
} finally {
327340
vitest.useRealTimers()
328341
}

0 commit comments

Comments
 (0)