Conversation
…g with large data such as segmentations
❌ Deploy Preview for ohif-dev failed. Why did it fail? →
|
|
@wayfarer3130 @jbocce please review if you have time |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUndo/redo history size is now configurable through Cornerstone customizations. A React hook tracks history availability, and the viewer header disables unavailable Undo and Redo controls while adding accessible labels. ChangesUndo/redo history controls
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CornerstoneToolEvents
participant useUndoRedoState
participant DefaultHistoryMemo
participant ViewerHeader
CornerstoneToolEvents->>useUndoRedoState: notify history-changing event
useUndoRedoState->>DefaultHistoryMemo: read availability after timeout
DefaultHistoryMemo-->>useUndoRedoState: return canUndo and canRedo
useUndoRedoState-->>ViewerHeader: provide undo/redo state
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // Limit the undo/redo history size. Segmentation memos hold full labelmap | ||
| // buffers, so a large history can cause out-of-memory / buffer allocation | ||
| // issues. Configurable via appConfig.maxUndoRedoCacheSize. | ||
| if (appConfig.maxUndoRedoCacheSize != null) { |
There was a problem hiding this comment.
Just appConfig.maxUndoRedoCacheSize >=0
| }; | ||
| useCursors?: boolean; | ||
| maxCacheSize?: number; | ||
| /** |
There was a problem hiding this comment.
This should be a customization now rather than a config item - it is still possible to set as a config item, but through the customization values.
wayfarer3130
left a comment
There was a problem hiding this comment.
Can you make maxUndoRedoCacheSize a customization setting?
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@extensions/cornerstone/src/init.tsx`:
- Around line 162-171: Update the validation guarding the assignment to
csUtilities.HistoryMemo.DefaultHistoryMemo.size in the maxUndoRedoCacheSize
configuration flow. Accept only finite, non-negative integer values, rejecting
Infinity, NaN, and fractional values before mutating the history size.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d89a251e-4669-4484-a0b6-65ed38534dfa
📒 Files selected for processing (3)
extensions/cornerstone/src/init.tsxextensions/cornerstone/src/types/AppTypes.tsplatform/docs/docs/configuration/configurationFiles.md
Resolve the conflict in extensions/default/src/ViewerLayout/ViewerHeader.tsx. The master branch moved the undo/redo buttons out of ViewerHeader and into extensions/default/src/ViewerLayout/HeaderUndoRedo.tsx, which the new `ohif.headerRightSide` customization renders. This merge keeps the structure of master, and it moves the changes of this branch into HeaderUndoRedo.tsx: the `useUndoRedoState` hook, the `disabled` property on each button, the `aria-label` on each button, and the move of the `cursor-pointer` class from the wrapper element to each button. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The merge of
|
Viewers
|
||||||||||||||||||||||||||||
| Project |
Viewers
|
| Branch Review |
feat/undo-redo-limit
|
| Run status |
|
| Run duration | 01m 47s |
| Commit |
|
| Committer | Bill Wallace |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
28
|
| View all changes introduced in this branch ↗︎ | |
…value The customization was read in preRegistration, before the global phase and the legacy customizationService form are applied, so the limit never took effect for those forms. Read it in onModeEnter instead, and again when a global or mode customization changes, so the mode phase also applies. Accept only an integer from 1 to 10000. The Cornerstone size setter throws a RangeError for a fractional or too-large value, and a size of 0 makes push write to ring[NaN]. An invalid value logs a warning and keeps the default. The setter clears the history, so the size is assigned only when it changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A drag of an existing annotation fires ANNOTATION_MODIFIED only while the pointer moves. The tool pushes the memo on mouse up and fires no event for it, so the buttons kept the state from before the drag. Listen for ANNOTATION_MODIFIED, and re-read the history state after mouseup/touchend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n keys Move cornerstone.maxUndoRedoCacheSize from the list of top-level appConfig keys to the customization table, because no code reads a top-level key. Add the Header:Undo and Header:Redo keys that the button labels use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove the subscriptions to the global and mode customization events. The history size comes from the customization at the time of mode entry only, and onModeEnter applies it once, after it registers the event handlers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove the applyUndoRedoCacheSize helper and its test. onModeEnter sets DefaultHistoryMemo.size to the customization value, or to 50 when the value is unset. An invalid value makes the Cornerstone setter throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Context
When editing segmentations, each labelmap edit records an undo memo that holds full labelmap buffers. Over a long session the undo/redo history can therefore grow large enough to cause memory pressure / out-of-memory or buffer-allocation failures, especially with large volumes.
Today the history size is fixed at Cornerstone's internal default and cannot be tuned by a deployment. This PR adds an optional
maxUndoRedoCacheSizeapp config so integrators working with large data can bound the history. It is opt-in: when the option is not set, Cornerstone's existing default is used, so there is no behavior change for current users.While in this area, it also fixes a small UX papercut: the header Undo/Redo buttons were always clickable, so clicking them with an empty history did nothing and made the app feel broken.
This contribution has been donated by the University of Calgary.
Changes & Results
maxUndoRedoCacheSize(platform/core/src/types/AppTypes.ts): optionalnumberonAppTypes.Config. When unset, the Cornerstone default is used.extensions/cornerstone/src/init.tsx): whenappConfig.maxUndoRedoCacheSizeis provided, setcsUtilities.HistoryMemo.DefaultHistoryMemo.sizeaccordingly.extensions/default/src/ViewerLayout/ViewerHeader.tsx): the buttons are nowdisabled(greyed out) based oncanUndo/canRedo.useUndoRedoStatehook (extensions/default/src/ViewerLayout/useUndoRedoState.ts): tracksDefaultHistoryMemo.canUndo/canRedoand re-evaluates on the relevant Cornerstone events (HISTORY_UNDO/HISTORY_REDO, plusANNOTATION_COMPLETED/ANNOTATION_REMOVED/SEGMENTATION_DATA_MODIFIED, since a new memo can be pushed without emitting a history event).platform/docs/docs/configuration/configurationFiles.md): document the newmaxUndoRedoCacheSizeoption.Effects:
Testing
The Undo button and the Redo button (no configuration):
The history size limit (optional):
The dev servers (
pnpm dev,pnpm dev:fast) loadplatform/app/public/config/dev.js. A production build loadsconfig/default.js. To use a different file, setAPP_CONFIG, for exampleAPP_CONFIG=config/default.js pnpm dev:fast.The viewer applies the value when a mode opens. Therefore, open a study before each check in the console.
config/dev.js, add this entry to thecustomizationServicearray (the legacy form):window.cornerstone.utilities.HistoryMemo.DefaultHistoryMemo.sizereturns5.customizationServicearray with the phased form. Then do step 2 again:0. Reload the viewer, and open a study. Make sure thatDefaultHistoryMemo.sizereturns50.10.5. Reload the viewer, and open a study. Make sure that the console showsRangeError: Invalid array length. The mode entry throws this error for an invalid value.DefaultHistoryMemo.sizereturns50, the Cornerstone default. This result shows that the default behavior does not change.The test steps do not use
window.config.maxUndoRedoCacheSize. The option is a customization, and it is not a top-levelappConfigkey.Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment
Summary by CodeRabbit
cornerstone.maxUndoRedoCacheSize.cornerstone.maxUndoRedoCacheSizeconfiguration option and what happens when it’s unset.