kunwp1 commented on code in PR #8839:
URL: https://github.com/apache/texera/pull/8839#discussion_r4690792245


##########
frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts:
##########
@@ -1034,20 +1099,33 @@ export class WorkflowFormComponent implements OnInit, 
OnDestroy {
     if (this.canEdit) {
       card.flushWrite = () => {
         card.pendingWrite = false;
-        // Formly emits the schema's empty default while building the control, 
before any edit;
-        // writing that back silently wiped the operator's real value (both 
views edit one
-        // workflow). So only accept a dirtied form, or a value that differs 
from the operator's
-        // without being emptier (some controls set values without marking 
dirty).
-        const next = model[binding.id];
-        const current = this.formBindingService.readValue(binding.operatorID, 
binding.propertyKey);
+        // What this card changed since it was built is written back: the 
bound property, and the
+        // siblings a widget changed with it. Formly emits the schema's empty 
default for the bound
+        // control while building it, before any edit; writing that back 
silently wiped the
+        // operator's real value (both views edit one workflow). So the bound 
property is taken
+        // only from a dirtied form, or when it differs without being emptier 
(some controls set
+        // values without marking dirty).
         const isEmpty = (v: unknown) => v === undefined || v === null || v === 
"";
-        const unchanged = JSON.stringify(next ?? null) === 
JSON.stringify(current ?? null);
-        if (unchanged || (!form.dirty && isEmpty(next) && !isEmpty(current))) {
+        // An empty string and an absent property mean the same to an 
operator, and formly fills a
+        // blank for a string the operator never had: neither is a change of 
the other.
+        const asJson = (value: unknown) => JSON.stringify(value === "" ? null 
: value ?? null);
+        const differs = (key: string) => asJson(model[key]) !== 
asJson(baseline[key]);
+        const bound = binding.propertyKey;
+        const blankBeforeEdit = !form.dirty && isEmpty(model[bound]) && 
!isEmpty(baseline[bound]);
+        const patch = Object.fromEntries(
+          Object.keys(model)
+            .filter(key => differs(key) && !(key === bound && blankBeforeEdit))
+            .map(key => [key, model[key]])
+        );
+        if (Object.keys(patch).length === 0) {
           return;
         }
         // Write straight onto the operator (the same edit the canvas makes) 
and refresh this
         // card's snapshot, which the template reads.
-        this.formBindingService.writeValue(binding, next);
+        this.formBindingService.writeProperties(binding.operatorID, patch);
+        // The card has caught up with what it just sent; anything else on the 
operator stays
+        // someone else's, and only a rebuild re-seeds this card with it.
+        baseline = { ...baseline, ...cloneDeep(patch) };

Review Comment:
   **A main issue.** After a card writes a sibling, its `contextKey` still 
describes the operator as it was when the card was built. Notice that 
`contextKeyFor` leaves out only the bound properties, so the `task` this card 
just wrote counts as a change to the widget context, and the compilation that 
the write triggers rebuilds the card. As a consequence, the HuggingFace picker 
is recreated and loses `taskStateByTag`. Switching the task back on the card is 
then treated as a first visit, and `resetTaskStateForFirstVisit` blanks 
`modelId` and the prompt fields, which the card writes back. On the panel, 
whose picker survives the compilation, the same switch restores them. This 
seems to be the interaction that Copilot's latest review asks a human to look 
at.
   
   One way to fix it is to advance the context key together with the baseline, 
so that only someone else's change rebuilds the card:
   ```ts
           baseline = { ...baseline, ...cloneDeep(patch) };
           card.contextKey = this.contextKeyOf(binding.operatorID, baseline);
   ```
   Here `contextKeyOf(operatorID, properties)` is the serializing half of 
`contextKeyFor`. A spec next to "rebuilds the inputs when another property of a 
card's operator changed" that sets `task` through the card's control, flushes, 
and runs a compilation fails without this change and passes with it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to