Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit a272a4f

Browse files
os-teslaclaude
andauthored
fix(plugin-kanban): run an authored onCardClick ONCE per card click (#9356)
ObjectKanban handed the host's function to useNavigationOverlay as its onRowClick and then called it again itself. handleClick gives onRowClick full priority -- it calls it and returns -- so for a host supplying onCardClick and no onRowClick, one card click ran that one function twice. Drops the wrapper's second call. Of the two it was the poorer: handleClick forwards onRowClick(record, event), carrying the modifier payload a host needs for Cmd/Ctrl/middle-click, while the deleted call passed the record alone. `onRowClick ?? onCardClick` is untouched, so precedence is unchanged -- what changed is that the loser of that expression no longer also fires, which is the one breaking case and is called out in the changeset. ObjectKanbanSchema.onCardClick therefore declares the second, optional parameter the surviving channel delivers. `event` is `any` rather than HandleClickModifiers: that interface lives in @object-ui/react, which depends on @object-ui/types and is named in no dependency field of it. BaseSchema's own onClick / onChange / onSubmit spell this the same way. Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ Co-authored-by: Claude <noreply@anthropic.com>
1 parent b67b53b commit a272a4f

6 files changed

Lines changed: 398 additions & 23 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
'@object-ui/types': minor
3+
'@object-ui/plugin-kanban': minor
4+
---
5+
6+
An `onCardClick` supplied to an `object-kanban` board runs **once** per card
7+
click instead of twice, and the published declaration of the key grows the
8+
second parameter the surviving call actually delivers (objectui#9341, maintainer
9+
ruling on the card, 2026-09-13).
10+
11+
**This carries a breaking behaviour change** — the `ObjectView` case below. It
12+
ships `minor` because the repo has a single `fixed` group of 40 packages, so a
13+
`major` on either package majors all forty; the scope is stated here rather than
14+
encoded in the bump.
15+
16+
## `@object-ui/plugin-kanban` — one click, one call
17+
18+
`ObjectKanban` handed the host's function to `useNavigationOverlay` as its
19+
`onRowClick` **and** called it again itself on the next line. `handleClick`
20+
gives `onRowClick` full priority — it calls it and returns — so for a host that
21+
supplied `onCardClick` and no `onRowClick`, one card click ran that one function
22+
twice: a duplicate navigation, a duplicate analytics event or a double-open,
23+
depending on what the handler did. The wrapper's second call is gone.
24+
25+
Of the two calls the deleted one was the poorer. `handleClick` forwards
26+
`onRowClick(record, event)`, so a host can implement Cmd/Ctrl/middle-click; the
27+
wrapper's call passed the record only. `onRowClick ?? onCardClick` is untouched,
28+
so which handler wins is exactly what it was.
29+
30+
⚠️ **The breaking case, to check before upgrading.** A board embedded in an
31+
`ObjectView` gets `onRowClick` from that parent, so the parent's handler already
32+
won. What also happened was that the document's own `onCardClick` ran anyway —
33+
once, through the wrapper. It now runs **zero** times there: the winner of
34+
`onRowClick ?? onCardClick` answers the click outright. A host that relied on an
35+
authored `onCardClick` firing alongside a parent `onRowClick` must move that
36+
work into the parent's handler. Pinned as a reading, not left to be discovered,
37+
in `packages/plugin-kanban/src/__tests__/cardClickFiresOnce-9341.test.tsx`.
38+
39+
## `@object-ui/types` — `ObjectKanbanSchema.onCardClick` declares two parameters
40+
41+
```ts
42+
onCardClick?: (card: any, event?: any) => void; // was: (card: any) => void
43+
```
44+
45+
The surviving channel delivers `(record, event)`, so the one-parameter
46+
declaration described only the call that was deleted. Growing an optional second
47+
parameter is source-compatible in both directions — an existing one-argument
48+
handler still type-checks, and code that stores the member in a one-argument
49+
slot still compiles — and that claim is handed to `tsc` rather than asserted, in
50+
the same pin file.
51+
52+
`event` is `any`, not `HandleClickModifiers`: that interface lives in
53+
`@object-ui/react`, which depends on `@object-ui/types` and is named in no
54+
dependency field of it. `BaseSchema`'s own `onClick` / `onChange` / `onSubmit`
55+
already spell this exact situation the same way. What arrives at runtime is the
56+
DOM click event `KanbanImpl` forwards, typed `React.MouseEvent` there.

‎packages/plugin-kanban/src/ObjectKanban.tsx‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,18 @@ export interface ObjectKanbanComponentProps {
252252
/** Loading state propagated from a parent. Respected only when `data` is also provided. */
253253
loading?: boolean;
254254
onRowClick?: (record: any) => void;
255-
onCardClick?: (record: any) => void;
255+
/**
256+
* ⚠️ TWO parameters, and the second one is not decoration: this prop is the
257+
* `onCardClick` arm of `externalClick` below, which is handed to
258+
* `useNavigationOverlay` as its `onRowClick` and invoked as
259+
* `onRowClick(record, event)` — the modifier payload a host needs for
260+
* Cmd/Ctrl/middle-click. Spelled `any` because `packages/types` declares the
261+
* published twin of this key and may not name `HandleClickModifiers` (it lives
262+
* in `@object-ui/react`, which depends on `@object-ui/types`), and the two
263+
* faces must not disagree. `KanbanImpl` types the same channel as
264+
* `React.MouseEvent`, which is what actually arrives.
265+
*/
266+
onCardClick?: (record: any, event?: any) => void;
256267
}
257268

258269
export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({
@@ -1329,9 +1340,24 @@ export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({
13291340
// objectui#8307 — the lane headers count rows that came back, so when
13301341
// the fetch saturated its window they must say `77+`, not `77`.
13311342
countsAreWindowed,
1343+
// ⛔ Calls `handleClick` and NOTHING ELSE. An authored `onCardClick`
1344+
// already travels this one line: it is the `onCardClick` arm of
1345+
// `externalClick` above, which is `handleClick`'s `onRowClick`, and
1346+
// that arm has FULL PRIORITY inside the hook — it is called and the
1347+
// hook returns. A second `onCardClick?.(card)` here therefore ran the
1348+
// SAME function again, twice per card click (objectui#9341, measured
1349+
// 2 by objectui#9338's pin before it was relaxed).
1350+
//
1351+
// Of the two calls the DELETED one was the poorer: `handleClick`
1352+
// forwards `onRowClick(record, event)`, so the host can implement
1353+
// Cmd/Ctrl/middle-click, while the second call passed the record
1354+
// only. Dropping it also leaves `onRowClick ?? onCardClick` untouched
1355+
// — a board inside an `ObjectView` still gives the parent's handler
1356+
// priority, and now gives it OUTRIGHT rather than also running the
1357+
// authored one. `ObjectGallery` has written exactly this shape, with
1358+
// no second call, all along.
13321359
onCardClick: (card: any, event?: any) => {
13331360
navigation.handleClick(card, event);
1334-
onCardClick?.(card);
13351361
},
13361362
onCardMove: handleCardMove,
13371363
}}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* One card click runs an authored `onCardClick` EXACTLY ONCE, and the call it
11+
* survives as carries the modifier event (objectui#9341, maintainer ruling on
12+
* the card, 2026-09-13).
13+
*
14+
* ## The defect
15+
*
16+
* `ObjectKanban` handed the same function to `useNavigationOverlay` as its
17+
* `onRowClick` and then called it again itself:
18+
*
19+
* const externalClick = onRowClick ?? onCardClick;
20+
* const navigation = useNavigationOverlay({ …, onRowClick: externalClick });
21+
* …
22+
* onCardClick: (card, event) => {
23+
* navigation.handleClick(card, event);
24+
* onCardClick?.(card); // ⛔ the second call
25+
* }
26+
*
27+
* `handleClick` gives `onRowClick` FULL PRIORITY — it calls it and RETURNS — so
28+
* for a host that supplies `onCardClick` and no `onRowClick`, that one function
29+
* is both the value of `externalClick` and the one the next line calls. One
30+
* click, two calls. Measured 2 by objectui#9338's pin, which relaxed its own
31+
* control to "it RAN" so that this repair would not redden a file that is not
32+
* about it; that control is tightened back to the exact count in the same diff
33+
* as this file.
34+
*
35+
* ## The ruling, and why the two calls are NOT interchangeable
36+
*
37+
* RULING: drop the wrapper's second call. `externalClick` keeps its
38+
* `onCardClick` arm.
39+
*
40+
* `handleClick` forwards `onRowClick(record, event)`, so a host can implement
41+
* Cmd/Ctrl/middle-click; the wrapper's second call passed the record ONLY. The
42+
* surviving channel is therefore the RICHER one, which is leg 2's subject — and
43+
* the reason the published `ObjectKanbanSchema.onCardClick` declaration grows a
44+
* second optional parameter in this same change.
45+
*
46+
* The same shape one surface over is already the ruling's spelling:
47+
* `ObjectGallery` (`packages/plugin-list/src/ObjectGallery.tsx`) writes
48+
* `onRowClick: props.onRowClick ?? props.onCardClick` into the identical hook
49+
* and has NO second call.
50+
*
51+
* ## ⚠️ The consequence the card's text did not state — measured in leg 3
52+
*
53+
* The ruling's rationale says precedence is left alone, so a board inside an
54+
* `ObjectView` "behaves exactly as today". That is true of the PRECEDENCE
55+
* EXPRESSION and FALSE of the authored handler's call count: when a parent
56+
* supplies `onRowClick` AND the document carries `onCardClick`, the authored
57+
* one ran ONCE before this change (the wrapper called it) and runs ZERO times
58+
* after it — the parent's handler wins OUTRIGHT, which is what
59+
* `onRowClick ?? onCardClick` has always said and what nothing enforced. Leg 3
60+
* pins that reading rather than leaving it to be discovered.
61+
*
62+
* ## Every control here can fire
63+
*
64+
* A count of 1 is only a reading if the instrument can report something else.
65+
* Leg 1 carries the sibling `onCardMove` spy at 0 on the SAME render, so the 1
66+
* is about this key and not a recorder that counts every key once; leg 4 drives
67+
* the same handler TWICE and reads 2, so the counter demonstrably moves.
68+
*
69+
* ⚠️ No leg here depends on a throw. React 19 REPORTS a handler error out of
70+
* the dispatch rather than rethrowing it, so an `expect(...).toThrow()` leg on
71+
* this path could never fire.
72+
*/
73+
74+
import { describe, it, expect, vi } from 'vitest';
75+
import React from 'react';
76+
import { render, waitFor } from '@testing-library/react';
77+
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
78+
import type { ObjectKanbanSchema } from '@object-ui/types';
79+
import '../index';
80+
81+
/** Every props object the board implementation was rendered with, in order. */
82+
const recorded = vi.hoisted(() => ({ impl: [] as Array<Record<string, unknown>> }));
83+
84+
// The lazy board chunk is a prop recorder: the question is how many times the
85+
// handler the board was HANDED runs the authored one, not what the board draws.
86+
vi.mock('../KanbanImpl', () => ({
87+
default: (props: Record<string, unknown>) => {
88+
recorded.impl.push(props);
89+
return null;
90+
},
91+
}));
92+
93+
const STATIC_COLUMNS = [{ id: 'todo', title: 'To Do', cards: [{ id: '1', title: 'One' }] }];
94+
95+
/**
96+
* Author a document on the PRODUCTION path — `SchemaRenderer` resolves the
97+
* registry key and spreads every non-metadata schema key as a React prop — and
98+
* return the props the board implementation was handed last.
99+
*/
100+
async function boardPropsFor(schemaKeys: Record<string, unknown>) {
101+
const before = recorded.impl.length;
102+
const { unmount } = render(
103+
<SchemaRendererProvider dataSource={undefined}>
104+
<SchemaRenderer
105+
schema={
106+
{
107+
type: 'object-kanban',
108+
columns: STATIC_COLUMNS,
109+
...schemaKeys,
110+
} as never
111+
}
112+
/>
113+
</SchemaRendererProvider>,
114+
);
115+
await waitFor(() => expect(recorded.impl.length).toBeGreaterThan(before));
116+
const received = recorded.impl[recorded.impl.length - 1];
117+
unmount();
118+
return received;
119+
}
120+
121+
/** The handler the board implementation was handed, driven as a card click. */
122+
type BoardClick = (card: unknown, event?: unknown) => void;
123+
124+
describe('objectui#9341 — an authored `onCardClick` runs ONCE per card click', () => {
125+
it('⭐ ONE click, ONE call — with the sibling `onCardMove` spy at 0 on the same render', async () => {
126+
const onCardClick = vi.fn();
127+
const onCardMove = vi.fn();
128+
const card = { id: '1', title: 'One' };
129+
130+
// ONE document, ONE render. The sibling key is the firing control: a
131+
// recorder that counted every authored handler once would show 1 here too,
132+
// and `onCardMove` reaches nothing on this arm (objectui#7804), so a 0
133+
// beside the 1 is what makes the 1 a reading about THIS key.
134+
const props = await boardPropsFor({ onCardClick, onCardMove });
135+
(props.onCardClick as BoardClick)(card);
136+
137+
expect(
138+
{ cardClick: onCardClick.mock.calls.length, cardMove: onCardMove.mock.calls.length },
139+
'the authored `onCardClick` must run exactly once per card click',
140+
).toEqual({ cardClick: 1, cardMove: 0 });
141+
});
142+
143+
it('⭐ the surviving call carries the MODIFIER EVENT — the whole reason it is the one kept', async () => {
144+
const onCardClick = vi.fn();
145+
const card = { id: '1', title: 'One' };
146+
// What `KanbanImpl` forwards is the DOM click event
147+
// (`onClick={(e) => onCardClick?.(card, e)}`); only the three modifier
148+
// fields are ever read, so a structural stand-in measures the channel.
149+
const event = { metaKey: true, ctrlKey: false, button: 0 };
150+
151+
const props = await boardPropsFor({ onCardClick });
152+
(props.onCardClick as BoardClick)(card, event);
153+
154+
expect(
155+
onCardClick.mock.calls.map((args) => ({ arity: args.length, record: args[0], event: args[1] })),
156+
'the kept channel is `handleClick`’s `onRowClick(record, event)` — the dropped one passed the record only',
157+
).toEqual([{ arity: 2, record: card, event }]);
158+
});
159+
160+
it('⚠️ a parent `onRowClick` wins OUTRIGHT — the authored `onCardClick` no longer also runs', async () => {
161+
const onRowClick = vi.fn();
162+
const onCardClick = vi.fn();
163+
const card = { id: '1', title: 'One' };
164+
165+
// Both reach `ObjectKanban` as React props on this path — `SchemaRenderer`
166+
// spreads every non-metadata key and `ObjectKanbanRenderer` forwards its
167+
// rest — which is the shape an `ObjectView`-embedded board has, with the
168+
// parent supplying `onRowClick`.
169+
const props = await boardPropsFor({ onRowClick, onCardClick });
170+
(props.onCardClick as BoardClick)(card);
171+
172+
// ⛔ NOT a regression smuggled in: `externalClick = onRowClick ?? onCardClick`
173+
// is untouched by this card and has always said the parent's handler wins.
174+
// What changed is that the loser no longer ALSO fires.
175+
expect(
176+
{ rowClick: onRowClick.mock.calls.length, cardClick: onCardClick.mock.calls.length },
177+
'precedence is `onRowClick ?? onCardClick`; exactly one handler answers one click',
178+
).toEqual({ rowClick: 1, cardClick: 0 });
179+
});
180+
181+
it('CONTROL — the counter moves: two clicks read 2', async () => {
182+
const onCardClick = vi.fn();
183+
const card = { id: '1', title: 'One' };
184+
185+
const props = await boardPropsFor({ onCardClick });
186+
(props.onCardClick as BoardClick)(card);
187+
(props.onCardClick as BoardClick)(card);
188+
189+
expect(onCardClick.mock.calls.length, 'a count leg whose count cannot move measures nothing').toBe(2);
190+
});
191+
});
192+
193+
/* ── The published face, judged by `tsc -p tsconfig.test.json` ───────────── */
194+
195+
/**
196+
* ⭐ The published-surface half of this card, MEASURED rather than asserted in
197+
* prose. `ObjectKanbanSchema.onCardClick` grew a second optional parameter
198+
* because the surviving channel delivers `(record, event)`; the prediction
199+
* offered with the ruling was that such a widening is source-compatible. These
200+
* four lines are that prediction handed to `tsc`, and the last one is the
201+
* control that keeps the other three from being vacuously true.
202+
*
203+
* ⛔ `event` is `any`, not `HandleClickModifiers`: that interface lives in
204+
* `@object-ui/react`, which depends on `@object-ui/types` and is named in no
205+
* dependency field of it — `check:phantom-deps` rejects the import and it would
206+
* close a cycle. `BaseSchema`'s own `onClick` / `onChange` / `onSubmit`
207+
* already spell this exact situation the same way.
208+
*/
209+
type Equal<A, B> =
210+
(<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
211+
type Expect<T extends true> = T;
212+
type Assignable<From, To> = [From] extends [To] ? true : false;
213+
type CardClick = NonNullable<ObjectKanbanSchema['onCardClick']>;
214+
215+
export type assertion9341PublishedSignatureIsSourceCompatible = [
216+
/** WIDENING direction: a host's existing one-argument handler still fits. */
217+
Expect<Assignable<(card: any) => void, CardClick>>,
218+
/** The reverse: code that stores the member in a one-argument slot still compiles. */
219+
Expect<Assignable<CardClick, (card: any) => void>>,
220+
/** The arity the channel actually delivers is now declared. */
221+
Expect<Assignable<CardClick, (card: any, event?: any) => void>>,
222+
/** CONTROL — `Assignable` can answer `false`: a REQUIRED second parameter does not fit. */
223+
Expect<Equal<Assignable<(card: any, event: any) => void, (card: any) => void>, false>>,
224+
];

0 commit comments

Comments
 (0)