Fix Ground Control: migrate gridApi to useRef, remove connect() container#3637
Fix Ground Control: migrate gridApi to useRef, remove connect() container#3637martin-henz wants to merge 4 commits intomasterfrom
Conversation
The mutable gridApi variable was lost on every re-render after the component was converted to a functional component. Migrate to useRef to persist the reference correctly. Also removes the Redux connect() container (GroundControlContainer) in favour of calling useDispatch() directly in the component, consistent with the rest of the codebase. Revives #2881 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pull Request Test Coverage Report for Build 22759197128Details
💛 - Coveralls |
Claude Code Session: Reviving PR #2881This document records the full conversation between the user (martin-henz) and Claude Code (claude-sonnet-4-6) that led to the creation of PR #3637. Step 1: Examining the old PRUser: take a look at this old PR: #2881 Claude: Fetched the PR via PR #2881 summary
What the PR does
Step 2: Is it worth reviving, or should we close it?User: Is it worth reviving, or should we just close it? Claude: Checked the current state of the affected files: Key findings:
Verdict: Worth reviving. The Step 3: Rebase or new PR?User: yes can you check if a rebase is possible. Alternatively, we could make a new PR for this? Claude: Checked the PR merge state: {"mergeStateStatus": "DIRTY"}Checked commits touching the affected files since the PR's base commit ( Verdict: A rebase is not feasible — the branch is 2 years old, already marked DIRTY, and the codebase has had major breaking changes (AG Grid v34 upgrade, BlueprintJS v6, Redux Toolkit migration that changed action import shapes). A new PR is the right call. The changes to apply are small and clear. Step 4: Applying the changesUser: yes please Claude: Created a new branch and applied the following changes: BranchChanges made
|
| File | Change |
|---|---|
src/pages/academy/groundControl/GroundControl.tsx |
Bug fix + refactor: useRef, useDispatch, lazy export |
src/pages/academy/academyRoutes.ts |
Import GroundControl directly instead of via container |
src/pages/academy/groundControl/GroundControlContainer.ts |
Deleted |
Net diff: +59 / -82 lines
Two causes identified: - onGridSizeChanged calling sizeColumnsToFit() created a feedback loop (resize → sizeColumnsToFit → resize → ...). Removed the handler. - columnDefs being redefined on every render caused AG Grid to re-process columns each cycle. Wrapped in useMemo([dispatch]) so it is only computed once (dispatch from useDispatch is stable). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code Session: Follow-up on PR #3637 (Richard's Feedback)This document records the follow-up conversation between the user (martin-henz) and Claude Code (claude-sonnet-4-6) after sharing Richard Dominick's (RichDom2185, original author of PR #2881) feedback on PR #3637. Richard's Feedback (verbatim)
Step 1: Claude's Analysis of Richard's FeedbackUser: Any comments or suggestions? Claude: Addressed both of Richard's points: Point 1: "Claude reintroduced changes that have been removed"This is a valid criticism of the prompting approach. When Claude was asked to apply the changes from PR #2881, it was not given explicit context about which parts of the diff had already been incorporated into master by other PRs between 2023 and now. Claude identified what was already applied by reading the current files, but may have missed subtleties about things that were deliberately removed. Point 2: Infinite re-render loopClaude investigated the likely cause by reading const ContentDisplay: React.FC<ContentDisplayProps> = props => {
useEffect(() => {
props.loadContentDispatch?.();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
...
};The Two causes were identified: Cause 1:
|
| Commit | Message |
|---|---|
8484414f |
Fix Ground Control grid API regression by migrating to useRef |
6abfcaa5 |
Fix infinite re-render loop in Ground Control |
16cac0cd |
style: format GroundControl.tsx |
Reflection on Richard's meta-point
Richard made a broader observation about using Claude Code for old PRs:
"It is generally a good approach if the PRs are e.g. features (which have since become conflicted). But for refactors it's been hit or miss especially because of these side effects at run time making things not so straightforward."
And on prompting strategy:
"I think when you prompted you could've added context on the diff to the master branch that has occurred since my branch was last updated."
This is accurate: the initial session identified what changes from #2881 were already in master by reading the current files, but Claude was not given (and did not proactively fetch) a full git diff between the PR's base commit and HEAD for the affected files. That would have given a clearer picture of intentional removals versus gaps. For future sessions of this kind, explicitly providing git diff <base>..<HEAD> -- <files> as context before applying the old PR's changes would reduce the risk of reintroducing removed code.
|
@RichDom2185 you moved this PR to "draft". In your view what would need to happen to get out of "draft"? We are back to the state the PR was in when you worked on this last year right? |
Description
[This PR is an experiment in using Claude Code to revive old PRs and clean up the repo. The description below was generated by Claude Code, Sonnet 4.6. I will post the prompt conversation below.]
Revives and re-applies #2881, updated for the current state of the codebase.
The mutable
gridApivariable was never properly persisted across re-renders after the component was converted to a functional component in #2875. It was declared as a plainletinside the component body, which means it gets reset toundefinedon every render — so any call toresizeGrid()after the initial mount was a no-op.Changes:
let gridApi→useRef<GridApi>()(the actual bug fix)DispatchPropstype andGroundControlContainer.ts; dispatch actions directly viauseDispatch(), consistent with the rest of the codebaseacademyRoutes.tsto importGroundControldirectly instead of via the containeronGridSizeChangedon the grid soresizeGridis actually called on window resizeType of change
How to test
Open Ground Control as an admin. The assessment grid should render and columns should size correctly. Resizing the window should also resize the grid columns.
Checklist