فهرست منبع

Fix bug where versions were added to history view in incorrect order (this bug occurred during my presentation at MLE workshop - MODELS'23).

Joeri Exelmans 1 سال پیش
والد
کامیت
53f96b683e
1فایلهای تغییر یافته به همراه7 افزوده شده و 4 حذف شده
  1. 7 4
      src/frontend/versioned_model/single_model.tsx

+ 7 - 4
src/frontend/versioned_model/single_model.tsx

@@ -112,25 +112,28 @@ export function newOnion({readonly, deltaRegistry, versionRegistry}) {
       setHistoryGraph(historyGraph => {
         const versionsToAdd: Version[] = [];
         const addIfDontHaveYet = version => {
-          if (!(historyGraph.nodes.some(n => n.obj === version) || versionsToAdd.includes(version))) {
+          if (!historyGraph.nodes.some(n => n.obj === version) && !versionsToAdd.includes(version)) {
             collectVersions(version);
           }
         }
         const collectVersions = version => {
-          // first add child, then parent
+          // first add parent, then child
           // this prevents infinite recursion when a version explicitly embeds itself.
-          versionsToAdd.push(version);
           for (const [parent] of version.parents) {
             addIfDontHaveYet(parent);
           }
           for (const {version: guest} of version.embeddings.values()) {
+            if (guest === version) {
+              continue; // special case: self-embedding...
+            }
             addIfDontHaveYet(guest);
           }
+          versionsToAdd.push(version);
         }
         for (const v of versions) {
           collectVersions(v);
         }
-        return versionsToAdd.reduceRight((historyGraph, version) => historyGraphReducer(historyGraph, {type: 'addVersion', version}), historyGraph);
+        return versionsToAdd.reduce((historyGraph, version) => historyGraphReducer(historyGraph, {type: 'addVersion', version}), historyGraph);
       })
     }
     // Idempotent