fix(frontend): find the preset to replace by value, not by reference - #7797
Open
mengw15 wants to merge 1 commit into
Open
fix(frontend): find the preset to replace by value, not by reference#7797mengw15 wants to merge 1 commit into
mengw15 wants to merge 1 commit into
Conversation
PresetService.updatePreset located the preset with lodash indexOf, which compares by reference. The list it searches is freshly JSON-parsed, so the lookup always returned -1: the replacement was written to a non-index property and silently discarded, and the "replacement already exists" path spliced the last element instead of the original. Use the same deep-equality findIndex that updateOrCreatePreset already uses.
Contributor
Backport auto-label reportThis
|
Contributor
Automated Reviewer SuggestionsBased on the
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes preset updates by locating JSON-parsed presets using deep equality instead of reference equality.
Changes:
- Replaces
indexOflookups with deep-equalityfindIndex. - Adds regression coverage for replacement, merging, and missing storage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
preset.service.ts |
Corrects preset replacement and removal lookup logic. |
preset.service.spec.ts |
Adds regression tests for affected update paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
PresetService.updatePresetlocated the preset to replace with lodashindexOf, which compares by reference. The list it searches comes straight out ofJSON.parse, so the lookup always returned-1while thecontainsguard above it — which compares withisEqual— still let execution through. Both arms then did the wrong thing:presets[-1] = replacementPresetwrites a non-index property on the array, so the edit was silently discarded and the unchanged list written back.presets.splice(-1, 1)removes the last element, so replacing a preset with one that already existed deleted the wrong preset.The sibling
updateOrCreatePresetdirectly below already used a deep-equalityfindIndex, with a comment naming this cause; this applies the same lookup toupdatePreset.indexOfis no longer used in the file, so the import drops with it.Three tests come with it — the two that reproduce the defect (an in-place replace, and a replace onto an existing preset), plus the absent-entry case that reaches the
?? "[]"default. They fail against the old code with exactly the wrong values described above.Any related issues, documentation, discussions?
Closes #7795
Both lines were unhit, which is how this went unnoticed; they are among the gaps listed in #7777, so that issue's
PresetServiceportion is handled here.How was this PR tested?
Unit tests, run locally in
frontend/:The failure path was verified by reverting the production change and re-running: the run exits non-zero with
2 failed | 59 passed, the in-place replace writing back the unchanged list and the merge case deletingv2instead ofv1. The coverage report over this spec now shows no unhit line and no partial branch inpreset.service.ts.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8 [1M context])