Skip to content

fix(frontend): find the preset to replace by value, not by reference - #7797

Open
mengw15 wants to merge 1 commit into
apache:mainfrom
mengw15:fix/7795-preset-update-deep-equality
Open

fix(frontend): find the preset to replace by value, not by reference#7797
mengw15 wants to merge 1 commit into
apache:mainfrom
mengw15:fix/7795-preset-update-deep-equality

Conversation

@mengw15

@mengw15 mengw15 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

PresetService.updatePreset located the preset to replace with lodash indexOf, which compares by reference. The list it searches comes straight out of JSON.parse, so the lookup always returned -1 while the contains guard above it — which compares with isEqual — still let execution through. Both arms then did the wrong thing:

  • presets[-1] = replacementPreset writes 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 updateOrCreatePreset directly below already used a deep-equality findIndex, with a comment naming this cause; this applies the same lookup to updatePreset. indexOf is 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 PresetService portion is handled here.

How was this PR tested?

Unit tests, run locally in frontend/:

ng test --watch=false --include .../preset.service.spec.ts
# Test Files 1 passed (1) | Tests 61 passed (61)
prettier --write / eslint   # clean

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 deleting v2 instead of v1. The coverage report over this spec now shows no unhit line and no partial branch in preset.service.ts.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8 [1M context])

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.
@github-actions github-actions Bot added fix frontend Changes related to the frontend GUI labels Aug 19, 2026
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Aug 19, 2026
@github-actions
github-actions Bot requested a review from xuang7 August 19, 2026 23:12
@github-actions

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. release/* labels drive the post-merge backport, so add or remove one to change where this fix lands.

Release branch Analysis
release/v1.2 Change detected on this branch — label added; this fix is queued to backport here. Requested review from @xuang7.

Auto-label run.

@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan, @Ma77Ball
    You can notify them by mentioning @aglinxinyuan, @Ma77Ball in a comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes preset updates by locating JSON-parsed presets using deep equality instead of reference equality.

Changes:

  • Replaces indexOf lookups with deep-equality findIndex.
  • 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.

@mengw15
mengw15 requested review from aglinxinyuan and removed request for xuang7 August 19, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix frontend Changes related to the frontend GUI release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PresetService.updatePreset silently drops the edit or deletes the wrong preset

3 participants