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


##########
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:
   Agreed for these two single-key values (the graph's per-operator keys do not 
race this way). Done in 1a5d528c2, the second of the two options: an edit made 
before the first sync is held the way the database copy is (`seedContentMeta` 
with `edit`), read from and announced at once so the page shows it and an 
autosave carries it, and written after the sync as a write that follows the 
room's state and replaces it -- an edit, not a coin flip -- so it yields to 
nothing. `setFormBinding` / `setWorkflowSettings` go through 
`writeContentMeta`, which writes straight into the document once it has synced. 
Spec: an edit typed right after opening is not in the document before the sync, 
is what the page shows while a co-editor's value arrives, and is what the 
document holds after the sync; the settings edit the same.



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