Copilot commented on code in PR #8351:
URL: https://github.com/apache/texera/pull/8351#discussion_r4119334811


##########
frontend/src/app/workspace/service/workflow-graph/model/workflow-action.service.ts:
##########
@@ -136,12 +157,70 @@ export class WorkflowActionService {
     );
     this.sharedModelChangeHandler.setConfigService(this.config);
     this.workflowMetadata = DEFAULT_WORKFLOW;
-    this.workflowSettings = this.getDefaultSettings();
     
this.undoRedoService.setUndoManager(this.texeraGraph.sharedModel.undoManager);
 
+    // Watch the shared content map, re-attaching whenever the shared model is 
recreated
+    // (opening another workflow), the same way SharedModelChangeHandler 
re-attaches its
+    // graph observers. A formBinding change from a local edit or a co-editor 
is republished
+    // on formBindingChanged$ so the Form View re-renders and the existing 
autosave picks it
+    // up. The reload seed is skipped -- like the graph seed -- so opening a 
workflow is not
+    // announced as an edit and does not save on every open.
+    this.observeContentMeta();
+    this.texeraGraph.newYDocLoadedSubject.subscribe(() => 
this.observeContentMeta());
+
     this.handleJointElementDrag();
   }
 
+  private observeContentMeta(): void {
+    // Detach the observer from the previous shared model before attaching to 
the new one, so
+    // re-attaching on each opened workflow does not stack listeners on the 
same map.
+    this.observedContentMetaMap?.unobserve(this.contentMetaObserver!);
+    // A new document starts with no seed state: nothing in it came from the 
previous room, no key
+    // has been seeded on it yet, and whatever copy the previously open 
workflow left waiting is
+    // not this one's -- dropped here, so it cannot leak into the next save of 
a workflow opened
+    // (or a blank one started) on this document.
+    for (const key of [...this.contentMetaSeeds.keys()]) {
+      this.cancelContentMetaSeed(key); // drops the copy it holds, and stops 
its listening
+    }
+    this.roomOwnedContentMeta.clear();
+    this.seededContentMetaKeys.clear();
+    const contentMetaMap = this.texeraGraph.sharedModel.contentMetaMap;
+    this.contentMetaObserver = event => {
+      if (!event.transaction.local) {
+        // An entry that arrived from the room belongs to the room, a 
co-editor's value or its
+        // cleared mark alike: the seed a workflow is opened with yields to it 
(see seedContentMeta).
+        // The first sync delivers the room's state as a remote transaction, 
which is how an
+        // opening client learns what the room already holds.
+        for (const key of event.changes.keys.keys()) {
+          this.roomOwnedContentMeta.add(key as ContentMetaKey);
+        }
+      } else {
+        // A local edit of a key supersedes the database copy a seed is still 
holding for it: the
+        // document now carries what the author wants, and the seed must 
neither write over it nor,
+        // for a workflow opened without a value, clear it once the sync lands.
+        for (const key of event.changes.keys.keys()) {
+          if (!this.seedingContentMetaKeys.has(key as ContentMetaKey)) {
+            this.cancelContentMetaSeed(key as ContentMetaKey);
+          }

Review Comment:
   A local edit while the initial sync is pending is still a concurrent Yjs 
write; cancelling the database seed does not make that edit win. If the room 
already has this key, its first update and the user's 
`setFormBinding`/`setWorkflowSettings` can be resolved by client ID, so an edit 
made immediately after opening can be silently lost (or can overwrite unseen 
room state). Prevent content-meta editing until the first sync, or queue 
field-level user intent and apply it after synchronization instead of writing 
the whole stale value immediately.
   
   This issue also appears on line 959 of the same file.



-- 
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