mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3028] [Issue]: Preset variable option label-edit and move-up/down rebuild from stale props, silently dropping an in-flight option edit #1597
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1597
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3028
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
In the preset-variable editor (
VariableCard), most option mutations build on the latest local copy of the options array (currentOpts()), which holds in-flight edits while a save round-trips. But the option LABEL commit and the move-up/down handler instead rebuild from the props-derivedopts, which lags behind any mutation still being saved. So if you edit one option and then commit a label edit (or reorder) before the first edit's PATCH lands, the new array is built from the stale array and the in-flight edit is silently discarded. The same defect wipes a freshly added option if you edit a label before the create refetches.How to reproduce (try it yourself)
You'll see: option A's value reverts to its old value.
Alternatively: click "Add Option" to create C, then immediately edit an existing option's Label and commit before the create refetch lands — C disappears.
Expected: concurrent option edits are preserved; the label/move paths carry the in-flight array.
Where it is
packages/client/src/components/presets/PresetEditor.tsx— option labelonCommitat lines 2323-2326 (const next = [...opts]; next[oi] = {...}; updateOpts(next);) andmoveOptionByOffsetat lines 1962-1966 (reorderItems(opts, ...)). Intended source-of-truth pattern at 1908-1928 (optsRef/sync guard/currentOpts/updateOpts); render maps over propsoptsat 2231.What's happening
optsRef.current/currentOpts()is the intended source of truth during in-flight saves (the sync guard only resyncs from props when!onUpdateVariable.isPending).useUpdateVariablehas no optimisticonMutate, so propsoptsstays at the last server-confirmed value until the PATCH resolves. Two mutation paths bypasscurrentOpts()and read the lagging props array, overwriting the server with a snapshot that misses the concurrent edit.Suggested fix
Make both bypassing paths read
currentOpts()like every other option mutation.updateOptionFieldalready readscurrentOpts()and keys by id, avoiding index drift against a diverged array.2.
moveOptionByOffset(~1962-1966): build fromcurrentOpts(), mirroring the accepted drag path:Key the label commit by
opt.id(not the render indexoi) so it stays correct whencurrentOpts()has diverged in order/length from props. Leave the read-only/display uses of propsopts(2050, 2052, 2105, 2231, 2236-2237, the disabled guard at 2310) unchanged.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed on staging in PR #3031 (merged as
f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.