Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
2ee2af2
wip: initial assessment
tnaum-ms Nov 26, 2026
95a0455
finalized grids assessment
tnaum-ms Nov 26, 2026
ce85793
wip: initial dev plan
tnaum-ms Nov 26, 2026
9d86741
initial dev plan
tnaum-ms Nov 26, 2026
1cba23b
initial dev plan
tnaum-ms Nov 26, 2026
40d8947
detailed dev plan
tnaum-ms Nov 26, 2026
5015417
docs: draft grid migration decisions (WI-0a)
tnaum-ms Nov 26, 2026
32544b5
docs: record WI-0a completion
tnaum-ms Nov 26, 2026
373373a
docs: specify neutral grid interfaces (WI-1c)
tnaum-ms Nov 26, 2026
c3beb1a
docs: record WI-1c completion
tnaum-ms Nov 26, 2026
4f8ef19
docs: record grid runtime pin evidence (WI-1)
tnaum-ms Nov 26, 2026
6fbd055
docs: record WI-1 completion and Step 0 gates
tnaum-ms Nov 26, 2026
b84c74c
docs: record G1 feedback and built-in grid retest
tnaum-ms Nov 26, 2026
83afd07
docs: record beta.64 selection at G1
tnaum-ms Nov 26, 2026
32ca8c6
docs: record beta.64 support floor policy
tnaum-ms Nov 26, 2026
5c9d411
docs: identify candidate VS Code minimum for beta.64
tnaum-ms Nov 26, 2026
a15d509
docs: record accepted beta.64 support floor evidence
tnaum-ms Nov 26, 2026
a81d40f
chore: raise minimum VS Code to 1.123.0 (WI-4a-floor)
tnaum-ms Nov 26, 2026
3f92ddc
docs: record G1 release and support-floor completion
tnaum-ms Nov 26, 2026
38b013b
docs: accept grid migration scope and decisions (WI-0b)
tnaum-ms Nov 26, 2026
f669a3a
docs: record WI-0b completion and current grid decision
tnaum-ms Nov 26, 2026
b415822
feat: define neutral document grid types (WI-2a)
tnaum-ms Nov 26, 2026
c8f47b8
docs: record WI-2a completion
tnaum-ms Nov 26, 2026
d83782f
feat: drive keyboard and focus in browser scenarios (WI-3a)
tnaum-ms Nov 26, 2026
6f2c5ee
docs: record WI-3a completion
tnaum-ms Nov 26, 2026
409ecee
feat: replace SlickGrid with the React Data Grid foundation (WI-4a)
tnaum-ms Nov 26, 2026
f36da78
docs: record WI-4a completion and bundle contract
tnaum-ms Nov 26, 2026
80200fc
feat: shape collection results with stable document identities (WI-2b)
tnaum-ms Nov 26, 2026
3e1002d
docs: record WI-2b acceptance and advisor verdict
tnaum-ms Nov 26, 2026
5128443
feat: map document grid theme to VS Code colors (WI-4b)
tnaum-ms Nov 26, 2026
f2acf5e
docs: record WI-4b theme verification
tnaum-ms Nov 26, 2026
b6851a9
test: add Collection View grid scenario fixtures (WI-3b)
tnaum-ms Nov 26, 2026
bfe204b
docs: record WI-3b completion and A2 pass
tnaum-ms Nov 26, 2026
eec82bf
docs: verify cross-collection isolation at G2
tnaum-ms Nov 26, 2026
418b7e8
docs: record tree spike and A4 pass (WI-9a)
tnaum-ms Nov 26, 2026
799c509
test: pin Collection View grid behavior contracts (WI-3c)
tnaum-ms Nov 26, 2026
42648bc
docs: record WI-3c completion and A3 gate
tnaum-ms Nov 26, 2026
f301fa0
feat: render Collection View table with React Data Grid (WI-5)
tnaum-ms Nov 26, 2026
1c4e7b0
test: visit virtualized columns before checking BSON values (E3)
tnaum-ms Nov 26, 2026
bf2686f
feat: render typed BSON values in Collection View (WI-6)
tnaum-ms Nov 26, 2026
25d0baa
feat: select Collection View rows and guard document actions (WI-7)
tnaum-ms Nov 26, 2026
e7090a5
test: wait for the M7 step-in result before asserting (E3)
tnaum-ms Nov 27, 2026
d06bbd6
feat: restore nested Collection View navigation (WI-8)
tnaum-ms Nov 27, 2026
d97fae8
docs: schedule grid keyboard navigation follow-up (WI-9b)
tnaum-ms Nov 27, 2026
59281cd
feat: render the Collection View document tree (WI-9)
tnaum-ms Nov 27, 2026
a2cdd23
fix: make Collection View grid keyboard focus predictable (WI-9b)
tnaum-ms Nov 27, 2026
f63039f
test: reach virtualized tree array children by keyboard (E3)
tnaum-ms Nov 27, 2026
20c1c7a
fix: stabilize Tree scrollbar measurements (WI-9)
tnaum-ms Nov 27, 2026
2dd820f
docs: record verified G2 package and raise gate (A9)
tnaum-ms Nov 27, 2026
bd4d024
docs: release G2 and schedule grid follow-ups
tnaum-ms Nov 27, 2026
0b1c70a
fix: fill the available Tree results area (WI-G2-1)
tnaum-ms Nov 27, 2026
c69951d
fix: ellipsize Table values without clipping BSON types (WI-G2-3)
tnaum-ms Nov 27, 2026
ada44f4
fix: explain keyboard Table navigation (WI-G2-4)
tnaum-ms Nov 27, 2026
dc2d388
fix: animate the Fluent Tree expander chevron (WI-G2-2)
tnaum-ms Nov 27, 2026
56ecba5
fix: clear Table row selection before Escape leaves the grid (WI-G2-5)
tnaum-ms Nov 27, 2026
0c4f487
docs: describe Collection View grid interactions (WI-11)
tnaum-ms Nov 27, 2026
4b22242
docs: record completed Collection View sweep (WI-10)
tnaum-ms Nov 27, 2026
64663a2
chore: resolve early Case 2 grid verification issues
tnaum-ms Nov 27, 2026
279ccae
test: wait for acknowledged deletion to render (E3)
tnaum-ms Nov 27, 2026
3cff9df
docs: record validated grid findings for G3a (WI-12)
tnaum-ms Nov 27, 2026
3fdd912
code review and decisions
tnaum-ms Nov 27, 2026
223844a
docs: establish approved review-fix plan (WI-G3)
tnaum-ms Nov 27, 2026
a852554
Merge branch 'main' into feature/rdg-migration
tnaum-ms Nov 27, 2026
8cc23e1
fix: preserve safe document identities (WI-G3-1)
tnaum-ms Nov 27, 2026
120f128
docs: record identity fix evidence (WI-G3-1)
tnaum-ms Nov 27, 2026
e873b12
docs: record refactor baseline and gates (WI-G3-2)
tnaum-ms Nov 27, 2026
bf7285d
refactor: simplify collection results (WI-G3-2)
tnaum-ms Nov 27, 2026
a5d146b
docs: record simplification completion (WI-G3-2)
tnaum-ms Nov 27, 2026
4753926
docs: checkpoint fresh-session handoff (WI-G3)
tnaum-ms Nov 27, 2026
e6190d8
docs: record focus reproduction gate (WI-G3-3)
tnaum-ms Nov 27, 2026
9eb782b
fix: restore keyboard step-in focus (WI-G3-3)
tnaum-ms Nov 27, 2026
0a18957
docs: record focus restoration completion (WI-G3-3)
tnaum-ms Nov 27, 2026
c09cdb6
fix: expose full cell type names (WI-G3-4)
tnaum-ms Nov 27, 2026
513597e
docs: record cell naming completion (WI-G3-4)
tnaum-ms Nov 27, 2026
3ac6607
fix: require collection results in packaged checks (WI-G3-5)
tnaum-ms Nov 27, 2026
985a1f7
docs: record readiness fix completion (WI-G3-5)
tnaum-ms Nov 27, 2026
668118b
docs: align review fix behavior and evidence (WI-G3-6)
tnaum-ms Nov 27, 2026
7d3c117
docs: finalize resumed review-fix record (WI-G3)
tnaum-ms Nov 27, 2026
9f57362
docs: record timing and machine diagnosis (WI-G3)
tnaum-ms Nov 27, 2026
186678b
Merge remote-tracking branch 'origin/feature/rdg-migration' into feat…
tnaum-ms Nov 27, 2026
47da875
chore: format review fixes for handover
tnaum-ms Nov 27, 2026
f9f59e7
fix: satisfy collection focus lint checks (WI-G3-3)
tnaum-ms Nov 27, 2026
8094c33
test: make collection count assertions locale-portable
tnaum-ms Nov 27, 2026
3429b30
docs: record synchronization and Case 2 corrections
tnaum-ms Nov 27, 2026
eca5330
test: make verification resilient to environment changes
tnaum-ms Nov 28, 2026
8182e88
feat(data-grid): update UX review findings and implement column resiz…
tnaum-ms Nov 30, 2026
3aa55ba
docs(data-grid): plan iteration 07 UX work and F5 gate
tnaum-ms Nov 30, 2026
7f32af7
docs(data-grid): settle WI-1 sizing prototype interfaces
tnaum-ms Nov 30, 2026
bfd8a0b
docs(data-grid): record WI-1 implementation return
tnaum-ms Nov 30, 2026
8f87eab
docs(data-grid): record WI-1 advisor review and rework
tnaum-ms Nov 30, 2026
feffc5e
docs(data-grid): record WI-1 checks and paging blocker
tnaum-ms Nov 30, 2026
6faa89a
docs(data-grid): isolate WI-1 paging loop evidence
tnaum-ms Nov 30, 2026
c0293e4
docs(data-grid): record WI-1 root cause and F5 automation request
tnaum-ms Nov 30, 2026
1f3dac8
docs(data-grid): record WI-1 correction and F5 availability
tnaum-ms Nov 30, 2026
cf26da5
feat(data-grid): prototype stable column sizing (WI-1)
tnaum-ms Nov 30, 2026
8a5cf03
docs(data-grid): record WI-1 prototype commit and F5 stop
tnaum-ms Nov 30, 2026
1398a23
docs(data-grid): record F5 launch and manual operator gate
tnaum-ms Nov 30, 2026
1e7de68
docs(data-grid): record F5 verdict and proposed sizing follow-ups
tnaum-ms Nov 30, 2026
575e1b7
docs(data-grid): propose path cache and bounded full-width sizing
tnaum-ms Nov 30, 2026
99c792e
docs(data-grid): record chosen fill and panel cache prototypes
tnaum-ms Nov 30, 2026
f6ac32b
docs(data-grid): settle WI-1a cache interfaces and stale-map fixes
tnaum-ms Nov 30, 2026
0086eb9
docs(data-grid): record WI-1a cache implementation return
tnaum-ms Nov 30, 2026
bfcc152
docs(data-grid): record WI-1a review and runtime isolation gate
tnaum-ms Nov 30, 2026
d1d4aa6
docs(data-grid): record fresh cache runtime diagnosis
tnaum-ms Nov 30, 2026
feab24e
docs(data-grid): record successful cache step-in runner
tnaum-ms Nov 30, 2026
650cf50
feat(data-grid): restore manual widths across paths and views (WI-1a)
tnaum-ms Nov 30, 2026
6d61f3f
docs(data-grid): record WI-1a commit and WI-1b fill contract
tnaum-ms Nov 30, 2026
1ab6aea
docs(data-grid): record WI-1b fill implementation return
tnaum-ms Nov 30, 2026
d1a41e8
feat(data-grid): fill spare pane space with automatic columns (WI-1b)
tnaum-ms Nov 30, 2026
52490bb
docs(data-grid): record WI-1b1 continuity fix verdict
tnaum-ms Nov 30, 2026
c3a1461
fix(data-grid): preserve filled widths when resizing starts (WI-1b1)
tnaum-ms Nov 30, 2026
0753383
docs(data-grid): record corrected sizing prototype and F5 handoff
tnaum-ms Nov 30, 2026
cd4e1be
docs(data-grid): release F5 gate and record fresh-session handoff
tnaum-ms Nov 30, 2026
dba9d65
fix: WI-2 show shallow object previews and tree counts
tnaum-ms Nov 30, 2026
a1fee76
docs: record WI-2 delivery and WI-3 copy approval
tnaum-ms Nov 30, 2026
c53b0e4
fix: WI-3 copy active-cell display text natively
tnaum-ms Nov 30, 2026
03b019d
docs: record WI-3 review and pending browser evidence
tnaum-ms Nov 30, 2026
0beb74d
feat: WI-4 respect hover accessibility preferences
tnaum-ms Nov 30, 2026
04e256c
docs: record WI-4 review and browser tooling blocker
tnaum-ms Nov 30, 2026
b3bb6ed
feat: WI-5 announce grid Escape guidance on entry
tnaum-ms Nov 30, 2026
e974885
docs: record RDG UX delivery and verification evidence
tnaum-ms Nov 30, 2026
d17a1b5
docs: record workbench results and reopen WI-3 Copy
tnaum-ms Nov 30, 2026
eb687ae
docs: record WI-3 diagnostic gate and checked host route
tnaum-ms Nov 30, 2026
48d7eec
docs: record WI-3-F1 regression proof and host retest gate
tnaum-ms Nov 30, 2026
e62dfff
fix: WI-3-F1 handle workbench document Copy events
tnaum-ms Nov 30, 2026
ab3d1e5
docs: accept WI-3-F1 host Copy and record follow-up evidence
tnaum-ms Nov 30, 2026
56d300f
chore: generate RDG UX localization and apply formatting
tnaum-ms Nov 30, 2026
600ad98
fix: Case2-L1 keep grid scope snapshots render-pure
tnaum-ms Nov 30, 2026
dff609a
docs: record green RDG verification and publication readiness
tnaum-ms Nov 30, 2026
8846fb3
fix: align host probe with the VS Code 1.123 runtime
tnaum-ms Dec 1, 2026
e546f2d
refactor: release column holds after RDG and scope widths with the page
tnaum-ms Dec 1, 2026
52e1ce2
chore: prettier-fix
tnaum-ms Dec 1, 2026
da2f779
docs: record Copilot review triage for #1142
tnaum-ms Dec 1, 2026
8bc293a
docs: refresh React webview guidance (WI-R7)
tnaum-ms Dec 1, 2026
67c5ef9
fix: compact Tree result keys (WI-R1)
tnaum-ms Dec 1, 2026
be840c6
fix: mark current Table breadcrumb (WI-R4)
tnaum-ms Dec 1, 2026
9722e1f
fix: close UDP socket after DNS stub bind failure (WI-R6)
tnaum-ms Dec 1, 2026
e707940
perf: memoize the Tree node index (WI-R3)
tnaum-ms Dec 1, 2026
2caae4e
fix: name the Table navigation button Level up (WI-R5)
tnaum-ms Dec 1, 2026
5bafef2
fix: restore Tree focus after a results refresh (WI-R2)
tnaum-ms Dec 1, 2026
f031df5
docs: record Copilot review fixes and Tree navigation
tnaum-ms Dec 1, 2026
2e01800
chore: format Copilot review fixes
tnaum-ms Dec 1, 2026
1d31b5f
test: type the Tree focus selector shim (WI-R2)
tnaum-ms Dec 1, 2026
9ca58be
docs: record Copilot review verification
tnaum-ms Dec 1, 2026
71785e4
Address Copilot review comments on #1142 (#1152)
tnaum-ms Dec 1, 2026
1f7e212
feat: implement keyboard resizing for Table and Tree headers
tnaum-ms Dec 1, 2026
b6af419
Unify Results Tree and Indexes expand-collapse controls
tnaum-ms Dec 1, 2026
5788154
Match RDG Tree indentation to Fluent Tree spacing
tnaum-ms Dec 1, 2026
4033c44
feat: enhance expandable tree and index table interactions with impro…
tnaum-ms Dec 1, 2026
bed64f0
feat: implement animated index detail rows with Fluent Collapse compo…
tnaum-ms Dec 1, 2026
30f1389
Fix webview lint errors
tnaum-ms Dec 1, 2026
6325430
Merge branch 'main' into feature/rdg-migration
tnaum-ms Dec 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/skills/react-webview-architecture/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: react-webview-architecture
description: Architecture patterns for React-based webviews in the vscode-documentdb extension. Use when creating new webview components, modifying existing views (CollectionView, DocumentView), working with state management (Context API), integrating Fluent UI components, handling Monaco Editor or SlickGrid, solving stale closure bugs with refs, or debugging webview rendering issues. Does NOT cover tRPC messaging (see webview-trpc-messaging skill) or accessibility/ARIA (see accessibility-aria-expert skill).
description: Architecture patterns for React-based webviews in the vscode-documentdb extension. Use when creating new webview components, modifying existing views (CollectionView, DocumentView), working with state management (Context API), integrating Fluent UI components or React Data Grid, handling Monaco, or debugging webview rendering issues. Does NOT cover tRPC messaging (see webview-trpc-messaging skill) or accessibility/ARIA (see accessibility-aria-expert skill).
---

# React Webview Architecture
Expand All @@ -19,7 +19,7 @@ Patterns and conventions for React webviews in vscode-documentdb.
- Creating or modifying a webview (DocumentView, CollectionView)
- Adding new components inside `src/webviews/`
- Working with CollectionView context or state management
- Integrating Monaco Editor or SlickGrid
- Integrating Monaco Editor or Collection View's React Data Grid
- Debugging stale closure issues in event handlers

## Rendering Pipeline
Expand Down Expand Up @@ -115,23 +115,24 @@ setCurrentContext((prev) => ({
}));
```

## Stale Closure Pattern (CRITICAL)
## Event Handler Freshness

Third-party components (SlickGrid) bind event handlers at initialization — they don't update when state changes. **Always use refs** to access current data in those handlers:
React event handlers passed through component props are refreshed during rendering; do not add
refs by default. Use a ref only when a long-lived subscription or imperative API requires a stable
callback, and keep it synchronized with the current value. Prefer correct effect dependencies and
cleanup when the API permits replacing the callback.
Comment thread
tnaum-ms marked this conversation as resolved.
Resolved

```tsx
const dataRef = useRef(data);
useEffect(() => {
dataRef.current = data;
}, [data]);
## Collection View Grid

const onCellDblClick = useCallback((event) => {
const item = dataRef.current[event.detail.args.row]; // ✅ always current
// NOT: data[event.detail.args.row]; ❌ stale closure
}, []); // stable deps only
```
The Table and Tree use the exact-pinned `react-data-grid@7.0.0-beta.64`. Keep their data boundary
grid-neutral (`src/utils/documentGrid/`): `TablePage` and `TreeNode` carry display values and
identity metadata, not RDG-specific row models. The Tree is flattened and expanded by the
application; do not replace it with `TreeDataGrid` without revisiting arbitrary-depth behavior,
keyboard contracts, and accessibility verification.

**Why**: SlickGrid binds handlers once at init time. Without refs, handlers see the data from initialization, not the latest state. This caused multiple hard-to-debug issues.
Row keys identify rendered rows; they do not by themselves authorize document actions. Resolve
selected keys against the current Table page and require its safe `documentId` before exposing or
running document actions. Position-keyed rows remain browsable and selectable.

## Monaco Editor

Expand Down Expand Up @@ -206,7 +207,6 @@ Animations: `Collapse` from `@fluentui/react-motion-components-preview`
| Hook | Purpose |
| ------------------------------------- | -------------------------------------------------------------------------------------------- |
| `useSelectiveContextMenuPrevention()` | Prevents browser context menu everywhere except Monaco editors. Call once in top-level view. |
| `useHideScrollbarsDuringResize()` | Returns a function that temporarily hides scrollbars during layout transitions (500ms). |

## Conditional Rendering Patterns

Expand Down Expand Up @@ -239,7 +239,7 @@ try {

## Common Pitfalls

1. **Forgetting refs with third-party components** → stale data in event handlers
1. **Using refs for event-handler freshness** → event handlers refresh during rendering; use refs only for a stable callback in a long-lived subscription or imperative API, and keep current values synchronized
2. **Not cleaning up** event listeners, Monaco instances, AbortControllers in `useEffect` return
3. **Not calling `editor.layout()`** after resize → blank Monaco panels
4. **Using `any`** → use proper types or `unknown` with type guards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ export type CollectionViewContextType = {
disableDeleteDocument: boolean;
};
dataSelection: {
selectedDocumentObjectIds: string[];
selectedDocumentIndexes: number[];
readonly selectedRowKeys: readonly string[];
};
queryEditor?: {
getCurrentQuery: () => {
Expand Down Expand Up @@ -396,69 +395,27 @@ setCurrentContext((prev) => ({
}));
```

#### Solving Stale Closure Issues
#### Event Handler Freshness

**🚨 CRITICAL PATTERN**: When using third-party components (like SlickGrid) that don't automatically update event handlers on re-renders:

```tsx
// Problem: Event handlers capture state at initialization time
// Solution: Store latest state in refs

const [currentQueryResults, setCurrentQueryResults] = useState<QueryResults>();
const currentQueryResultsRef = useRef(currentQueryResults);

// Keep ref in sync with state
useEffect(() => {
currentQueryResultsRef.current = currentQueryResults;
}, [currentQueryResults]);

// In event handler, use ref to get latest data
const onCellDblClick = useCallback((event: CustomEvent) => {
// ✅ Good: Access latest data via ref
const activeDocument = currentQueryResultsRef.current?.tableData?.[row];

// ❌ Bad: Would capture stale state
// const activeDocument = currentQueryResults?.tableData?.[row];
}, []);
```

**Why this is needed:**

```tsx
// Third-party components like SlickGrid bind event handlers during initialization:
// 1. Component initializes with state = { data: [...] }
// 2. Event handler is created and captures state
// 3. State updates to { data: [...new items...] }
// 4. Event handler STILL sees old state (stale closure)
// 5. Using ref solves this because ref.current is always the latest value
```
React event handlers passed through component props are refreshed during rendering. Prefer normal
closures with correct dependencies; refs are not a general requirement for third-party components.
Use a ref when a long-lived subscription or imperative API requires a stable callback, and keep
the ref synchronized with current state. Clean up subscriptions when their source changes or the
component unmounts.

### `useCallback` - Memoized Callbacks

Use `useCallback` for event handlers passed to child components or third-party libraries:
Use `useCallback` when stable callback identity is useful. Include every reactive value used by
the callback in its dependency list. A ref is appropriate only when the API requires callback
identity to remain stable:

```tsx
const handleViewChanged = useCallback((optionValue: string) => {
setCurrentContext((prev) => ({ ...prev, currentView: selection }));
getDataForView(selection);
}, []); // Dependencies array
```

**Note**: When combined with the ref pattern, dependencies should only include stable references:

```tsx
const onSelectedRowsChanged = useCallback(
(_eventData: unknown, _args: OnSelectedRowsChangedEventArgs): void => {
setCurrentContext((prev) => ({
...prev,
dataSelection: {
selectedDocumentIndexes: _args.rows,
// Use ref for latest data, not the prop
selectedDocumentObjectIds: _args.rows.map((row) => liveDataRef.current[row]?.['x-objectid'] ?? ''),
},
}));
const handleViewChanged = useCallback(
(selection: Views): void => {
setCurrentContext((previous) => ({ ...previous, currentView: selection }));
getDataForView(selection);
},
[setCurrentContext], // Only setCurrentContext, NOT liveData
[getDataForView, setCurrentContext],
);
```

Expand Down Expand Up @@ -578,95 +535,21 @@ monaco.languages.json.jsonDefaults.setDiagnosticsOptions({...});

## Third-Party Component Integration

### SlickGrid Integration

SlickGrid is used for table and tree views. It requires special handling due to stale closure issues.

#### Basic SlickGrid Setup

```tsx
import { SlickgridReact, type GridOption } from 'slickgrid-react';

<SlickgridReact
gridId="myGrid"
gridOptions={gridOptions}
columnDefinitions={gridColumns}
dataset={liveData}
onReactGridCreated={() => console.log('Grid created')}
/>;
```

#### Grid Options Pattern
### Collection View Result Grids

```tsx
const gridOptions: GridOption = {
autoResize: {
calculateAvailableSizeBy: 'container',
container: '#resultsDisplayAreaId', // Parent container selector
delay: 100,
bottomPadding: 2,
},
enableAutoResize: true,
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableRowSelection: true,
multiSelect: true,
};
```
The Table and Tree use RDG's `DataGrid`; their input contracts remain in
`src/utils/documentGrid/types.ts`.

#### Event Handlers with Refs (Critical!)

```tsx
// Store latest data in refs
const liveDataRef = useRef<TableDataEntry[]>(liveData);
const gridColumnsRef = useRef<GridColumn[]>([]);

// Keep refs in sync
useEffect(() => {
liveDataRef.current = liveData;
}, [liveData]);

useEffect(() => {
gridColumnsRef.current = gridColumns;
}, [gridColumns]);

// Event handler using refs
const onCellDblClick = useCallback(
(event: CustomEvent<{ args: OnDblClickEventArgs }>) => {
// ✅ Use ref to get latest data
const activeDocument = liveDataRef.current[event.detail.args.row];
const activeColumn = gridColumnsRef.current[event.detail.args.cell].field;

// Process event...
},
[handleStepIn],
); // Only stable dependencies
```

**Why this matters:**

- SlickGrid binds event handlers at initialization
- These handlers don't update when props/state change
- Without refs, handlers see stale/outdated data
- This caused multiple bugs that took hours to debug

### Custom Cell Formatters

```tsx
const cellFormatter: Formatter<object> = (_row: number, _cell: number, value: CellValue) => {
if (value === undefined || value === null) {
return {
text: '',
toolTip: l10n.t('This field is not set'),
};
}
return {
text: value.value,
addClasses: `typedTableCell type-${value.type}`,
toolTip: bsonStringToDisplayString(value.type),
};
};
```
- Table columns render `TablePage` cells, retaining BSON display text and type metadata.
`getRowKey` uses the row identity supplied by the neutral shaper.
- The application builds a flattened visible hierarchy for the Tree, with path-based `TreeNode`
keys, `aria-level` and `aria-expanded`; RDG does not own document expansion state.
- Use `DataGridHandle.setActivePosition` only where focus must be synchronized after a custom
interaction. Keep focus on the surviving Tree cell before collapsing a branch.
- Preserve the current Table selection gestures and safe-ID action guard. Do not infer action
eligibility from a selected row or invent an unapproved keyboard binding.
- Avoid per-cell Tab stops. Native grid navigation, Escape to the view picker, and the Tree's Enter
expansion behavior are part of the current interaction contract.

---

Expand Down Expand Up @@ -885,16 +768,6 @@ const configuration = useConfiguration<CollectionViewWebviewConfigurationType>()

Prevents browser context menus everywhere except Monaco editors. Call once in the top-level view component.

### `useHideScrollbarsDuringResize`

Temporarily hides scrollbars during layout transitions (e.g., QueryEditor collapse animations) to prevent flickering:

```tsx
const hideScrollbarsTemporarily = useHideScrollbarsDuringResize();
// Call before triggering a layout change
hideScrollbarsTemporarily();
```

For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-messaging** skill.

---
Expand Down Expand Up @@ -931,23 +804,11 @@ For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-me

### ⚠️ Common Pitfalls

1. **Forgetting to use refs with third-party components**
1. **Using refs as a blanket fix for stale closures**

```tsx
// ❌ Will capture stale state
const onClick = () => {
console.log(someState);
};

// ✅ Use ref pattern
const stateRef = useRef(someState);
useEffect(() => {
stateRef.current = someState;
}, [someState]);
const onClick = () => {
console.log(stateRef.current);
};
```
Ordinary React handlers can use the current render's values. For a long-lived external
subscription, include current values in the effect dependencies and clean it up; use a ref only
when the API requires a stable callback.

2. **Not cleaning up event listeners**

Expand Down Expand Up @@ -1006,8 +867,8 @@ For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-me

- Use consistent 10px spacing units
- Use flexbox with `row-gap`/`column-gap` for spacing
- Store third-party component references in `useRef`
- Use ref pattern to solve stale closure issues
- Store imperative component handles in `useRef` when needed
- Use refs for current state only when a long-lived API requires callback identity to stay stable
- Clean up event listeners, subscriptions, and AbortControllers
- Use functional state updates when depending on previous state
- Always localize user-facing strings with `l10n.t()`
Expand All @@ -1023,7 +884,7 @@ For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-me
- Don't overuse negative margins (fix layout instead)
- Don't forget to clean up in useEffect return (listeners, AbortControllers)
- Don't use `any` type (use proper types or `unknown`)
- Don't capture state in closures for third-party components (use refs)
- Don't add refs for callbacks without a long-lived-API requirement
- Don't hardcode delays (use proper initialization checks)
- Don't forget to call `editor.layout()` after resize
- Don't mix state management patterns inconsistently
Expand All @@ -1037,11 +898,11 @@ For tRPC-related hooks (`useTrpcClient`) and patterns, see the **webview-trpc-me
- Accessibility: See `.github/skills/accessibility-aria-expert/SKILL.md`
- VS Code Webview API: [VS Code Webview API](https://code.visualstudio.com/api/extension-guides/webview)
- Monaco Editor API: [Monaco Editor API](https://microsoft.github.io/monaco-editor/api/index.html)
- SlickGrid React: [SlickGrid React Docs](https://ghiscoding.gitbook.io/slickgrid-react/)
- React Data Grid: consult the exact dependency pin in the root `package.json`; do not assume the latest API applies
- React Hooks: [React Hooks Reference](https://react.dev/reference/react)

---

_Document Version: 2.0_
_Last Updated: February 12, 2026_
_Document Version: 2.1_
_Last Updated: November 27, 2026_
_Based on: DocumentView, CollectionView, QueryEditor, QueryInsights analysis_
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Reopen your terminal after installation, then repeat the check.
code --version
```

Use a version satisfying `engines.vscode` in `package.json` (currently 1.109.0 or
Use a version satisfying `engines.vscode` in `package.json` (currently 1.123.0 or
later in the 1.x line). **Install if missing:** visit
[code.visualstudio.com](https://code.visualstudio.com/), or run:

Expand Down
Loading
Loading