Repository navigation
Commit 7ac1e3c
authored
Keep row actions menu open when table actions callback changes identity (#3364)
The Firefox run on the audit log merge to main failed `Silo IP pools` on
all three attempts, each time in `clickRowAction` on the menu item, with
Chrome and Safari passing:
https://github.com/oxidecomputer/console/actions/runs/33767277998/attempts/1
I could not repro locally with the code as-is, but I can make it happen
by adding a delay in the mock API (see below). `SiloIpPoolsTab` fetches
the silo's pools twice: the paginated list that the table renders, and a
second `useQuery` for all of them, which the "Make default" confirm
modal uses to find the existing default for the same IP version and type
so it can warn that it will be replaced. `makeActions` depends on that
second result. The sequence in the test:
1. The test unlinks a pool, and the mutation's `onSuccess` invalidates
both the paginated list and the all-pools list.
2. The test waits for the unlinked row to disappear, which happens as
soon as the paginated refetch lands, and then opens the next row's menu.
3. If the all-pools refetch has already landed by then, nothing happens.
If it lands after the menu is open, it gives `makeActions` a new
identity.
4. `useColsWithActions` builds a new actions column with a new inline
`cell` closure.
5.
[`flexRender`](https://github.com/TanStack/table/blob/ab2819c/packages/react-table/src/index.tsx#L18-L27)
renders a function `cell` as a component, so a new function is a new
element type and React remounts the whole cell.
6. The open menu is unmounted along with the cell and comes back closed,
so the menu item Playwright was about to click is gone.
To confirm this, I added a 150ms delay to the mock all-pools response so
it lands right around the time the test opens the menu. On main, the e2e
test fails 5 out of 42 runs on Firefox with exactly the CI error,
detached menu item and all, at the same line. With the fix and the same
delay, it passes 24 out of 24. A longer delay like 1.5s makes the test
pass again on main because Playwright opens the menu and clicks before
the refetch lands, which is also why the test has been fine locally.
With the 1.5s delay and a throwaway e2e test that holds the menu open
across it, the menu closed before the fix and stayed open after.
The fix is to make the more actions button cell a single module-level
`ActionsCell` component and pass `makeActions` and `copyIdLabel` through
column `meta` instead of closing over them in a dynamic cell definition.
The element type is then stable no matter how often the callback or the
columns array changes identity, so it fixes every table using
`getActionsCol` without touching any call sites. The browser spec opens
a row menu, rerenders with a new `makeActions`, and asserts the menu is
still open. It failed in all three browsers before the fix.
This is the same mechanism behind the polling-closes-the-menu problems
in #2112, #2460, and #2816. Each of those was fixed by memoizing
`makeActions` or the columns array carefully enough to keep the closure
identity stable. With a stable cell component, that memoization is only
a render-count optimization, so I softened the doc comments on
`useColsWithActions`. The `instanceState` hack on NIC rows from #2460
could be unwound now, but I've left that for a followup.1 parent c927f2f commit 7ac1e3c
4 files changed
Lines changed: 94 additions & 14 deletions
File tree
- app/table/columns
- types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | | - | |
43 | 46 | | |
44 | | - | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 69 | + | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
75 | 94 | | |
76 | 95 | | |
77 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
0 commit comments