This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9367-52093b446b2c659c4fb626ae9e6d18b02deca7b1
in repository https://gitbox.apache.org/repos/asf/texera.git

commit bde1f7d88b0ca95ec9678e17529cca4a54bf9911
Author: Tanishq Gandhi <[email protected]>
AuthorDate: Mon Nov 16 05:05:41 2026 +0000

    fix(frontend): drop a version preview left open when leaving the workspace 
(#9367)
    
    ### What changes were proposed in this PR?
    
    A version preview could outlive the workflow it was opened in.
    Previewing a version turns off autosave and stores the open workflow so
    the ← arrow can put it back. That state lives in root services, and only
    ← or "Restore this version" reset it. Browser Back is the only other way
    out of a preview, and it left the state in place. So the next workflow
    opened was stuck in preview mode:
    - its edits weren't saved;
    - pressing ← loaded the first workflow's graph into it;
    - that graph was then saved over it.
    
    When the workspace is left, `WorkspaceComponent.ngOnDestroy` now calls a
    new `WorkflowVersionService.discardOpenVersionDisplay()`. If a preview
    is still open, that method:
    - drops the stored workflow;
    - turns autosave back on;
    - clears the preview flag.
    
    It runs after `clearWorkflow()`, so the clear itself still happens with
    autosave off. Handing the workflow to its own Form View is not leaving,
    so the preview is kept there.
    
    The graph is deliberately not reloaded on the way out. Doing what ← does
    at that point empties the closing workflow's co-editing document: the
    reload's deletions reach the room, but its re-added operators are
    rendered asynchronously and the document is destroyed first.
    
    | Before | After |
    |---|---|
    | <img width="1440" height="900" alt="before-2-b-stuck-in-preview"
    
src="https://github.com/user-attachments/assets/2f7139d4-30d0-40a6-914c-77b2a8ef2483";
    /> B opens stuck in A's preview | <img width="1440" height="900"
    alt="after-1-b-opens-normally"
    
src="https://github.com/user-attachments/assets/235082fc-400b-444f-aa6e-b2c2ab46b281";
    /> B opens normally |
    | <img width="1440" height="900" alt="before-4-b-overwritten"
    
src="https://github.com/user-attachments/assets/7c285d4a-9ce5-459e-b85f-8d9eb944bf70";
    /> B reopened shows A's operators, saved into B | <img width="1440"
    height="900" alt="after-2-b-keeps-its-content"
    
src="https://github.com/user-attachments/assets/5d2d1d2a-9625-4ac7-87c3-a505ebb0a0a2";
    /> B keeps its own operator |
    
    ### Any related issues, documentation, discussions?
    
    Closes #9354.
    
    ### How was this PR tested?
    
    - New `WorkflowVersionService` tests:
    - `discardOpenVersionDisplay` ends an open preview (it resets the temp
    workflow, turns autosave on and clears the flag and selected version)
    without reloading the graph;
      - it does nothing when no preview is open.
    - New `WorkspaceComponent` test: leaving the workspace discards the
    preview after `clearWorkflow()`. The Form View hand-over test now also
    checks that the preview is kept.
    - With the fix removed, the two new behaviour tests fail.
    `workflow-version.service` and `workspace.component` specs pass (70
    tests). Prettier and eslint are clean.
    - Manually on a local stack, following the issue's steps:
      - B opens normally;
      - an edit to B is saved;
      - a new session shows B's own content;
      - A keeps its content with no extra versions;
      - the ← arrow still closes a preview and the next edit saves to A.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Claude Opus 5.5)
    
    ---------
    
    Co-authored-by: Xuan Gu <[email protected]>
---
 .../workflow-version.service.spec.ts               | 26 ++++++++++++++++++++++
 .../workflow-version/workflow-version.service.ts   | 16 +++++++++++++
 .../component/workspace.component.spec.ts          | 18 +++++++++++++++
 .../app/workspace/component/workspace.component.ts |  5 ++++-
 4 files changed, 64 insertions(+), 1 deletion(-)

diff --git 
a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts
 
b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts
index e59849a461..aa29f45590 100644
--- 
a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts
+++ 
b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts
@@ -461,6 +461,32 @@ describe("WorkflowVersionService", () => {
       expect(service.selectedVersionId.getValue()).toBeNull();
     });
 
+    it("discardOpenVersionDisplay ends an open preview without reloading the 
graph", async () => {
+      service.displayParticularVersion(buildWorkflow(), 3, 2);
+      actionSpy.reloadWorkflow.mockClear();
+      actionSpy.enableWorkflowModification.mockClear();
+      persistSpy.setWorkflowPersistFlag.mockClear();
+
+      service.discardOpenVersionDisplay();
+
+      expect(actionSpy.resetTempWorkflow).toHaveBeenCalled();
+      expect(persistSpy.setWorkflowPersistFlag).toHaveBeenCalledWith(true);
+      // A blank workflow opened next is never re-enabled by its own load.
+      expect(actionSpy.enableWorkflowModification).toHaveBeenCalled();
+      expect(actionSpy.reloadWorkflow).not.toHaveBeenCalled();
+      expect(await 
firstValueFrom(service.getDisplayParticularVersionStream())).toBe(false);
+      expect(service.selectedVersionId.getValue()).toBeNull();
+      expect(service.canRestoreVersion).toBe(false);
+    });
+
+    it("discardOpenVersionDisplay does nothing when no preview is open", () => 
{
+      service.discardOpenVersionDisplay();
+
+      expect(actionSpy.resetTempWorkflow).not.toHaveBeenCalled();
+      expect(persistSpy.setWorkflowPersistFlag).not.toHaveBeenCalled();
+      expect(actionSpy.enableWorkflowModification).not.toHaveBeenCalled();
+    });
+
     it("restoreModificationState re-disables modification when the snapshot 
was false", () => {
       actionSpy.checkWorkflowModificationEnabled.mockReturnValue(false);
       service.displayReadonlyWorkflow(buildWorkflow());
diff --git 
a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts
 
b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts
index 1b527e35cb..cf2db135ee 100644
--- 
a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts
+++ 
b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts
@@ -267,6 +267,22 @@ export class WorkflowVersionService {
     this.setDisplayParticularVersion(false);
   }
 
+  /**
+   * Drops a version preview still open when the workspace closes, so the next 
workflow opened does
+   * not inherit it. The graph is left alone: the workflow is closing, and 
reloading it here would
+   * reach the co-editing room only half done.
+   */
+  public discardOpenVersionDisplay(): void {
+    if (!this.displayParticularWorkflowVersion.getValue()) {
+      return;
+    }
+    this.workflowActionService.resetTempWorkflow();
+    this.workflowPersistService.setWorkflowPersistFlag(true);
+    this.workflowActionService.enableWorkflowModification();
+    this.modificationEnabledBeforeTempWorkflow = undefined;
+    this.setDisplayParticularVersion(false);
+  }
+
   public unhighlightOpVersionDiff(differentOpIDsList: DifferentOpIDsList) {
     for (const id of 
differentOpIDsList.added.concat(differentOpIDsList.modified)) {
       this.highlightOpBoundary(id, "0,0,0,0");
diff --git a/frontend/src/app/workspace/component/workspace.component.spec.ts 
b/frontend/src/app/workspace/component/workspace.component.spec.ts
index 118fc9e411..8a7a33faef 100644
--- a/frontend/src/app/workspace/component/workspace.component.spec.ts
+++ b/frontend/src/app/workspace/component/workspace.component.spec.ts
@@ -48,6 +48,7 @@ import { ComputingUnitStatusService } from 
"../../common/service/computing-unit/
 import { EntityType, HubService } from "../../hub/service/hub.service";
 import { commonTestProviders } from "../../common/testing/test-utils";
 import { WorkspaceComponent } from "./workspace.component";
+import { WorkflowVersionService } from 
"../../dashboard/service/user/workflow-version/workflow-version.service";
 import { USER_WORKSPACE, workspaceFormUrl } from "../../app-routing.constant";
 
 describe("WorkspaceComponent", () => {
@@ -69,6 +70,7 @@ describe("WorkspaceComponent", () => {
   let executeWorkflowService: any;
   let workflowConsoleService: any;
   let workflowResultService: any;
+  let workflowVersionService: any;
   let connectionResetSubject: Subject<void>;
   let metadataChangedSubject: Subject<void>;
   let stubGraph: { triggerCenterEvent: ReturnType<typeof vi.fn>; 
hasElementWithID: ReturnType<typeof vi.fn> };
@@ -173,6 +175,7 @@ describe("WorkspaceComponent", () => {
     };
     workflowConsoleService = { clearConsoleMessages: vi.fn() };
     workflowResultService = { clearResults: vi.fn() };
+    workflowVersionService = { discardOpenVersionDisplay: vi.fn() };
 
     // Drop the standalone component's child imports and allow unknown 
elements via
     // CUSTOM_ELEMENTS_SCHEMA. The template still renders, so `<ng-template 
#codeEditor>`
@@ -209,6 +212,7 @@ describe("WorkspaceComponent", () => {
         { provide: ComputingUnitStatusService, useValue: 
computingUnitStatusService },
         { provide: ExecuteWorkflowService, useValue: executeWorkflowService },
         { provide: WorkflowResultService, useValue: workflowResultService },
+        { provide: WorkflowVersionService, useValue: workflowVersionService },
         ...commonTestProviders,
       ],
       schemas: [NO_ERRORS_SCHEMA],
@@ -564,6 +568,19 @@ describe("WorkspaceComponent", () => {
       expect(workflowResultService.clearResults).toHaveBeenCalled();
     });
 
+    it("drops a version preview left open, after the workflow is cleared 
(issue #9354)", async () => {
+      await createFixture();
+      fixture.detectChanges();
+
+      component.ngOnDestroy();
+
+      
expect(workflowVersionService.discardOpenVersionDisplay).toHaveBeenCalled();
+      // Cleared first, so the clear still runs with saving off.
+      
expect(workflowActionService.clearWorkflow.mock.invocationCallOrder[0]).toBeLessThan(
+        
workflowVersionService.discardOpenVersionDisplay.mock.invocationCallOrder[0]
+      );
+    });
+
     // Leaving the document (a refresh, a closed tab, a URL typed over this 
one) fires beforeunload,
     // and the browser may then keep the document in its back/forward cache 
instead of discarding
     // it. The Form View switch used to be such a navigation and routes now. 
Coming back restores the JavaScript
@@ -597,6 +614,7 @@ describe("WorkspaceComponent", () => {
       component.ngOnDestroy();
 
       expect(workflowActionService.clearWorkflow).not.toHaveBeenCalled();
+      
expect(workflowVersionService.discardOpenVersionDisplay).not.toHaveBeenCalled();
       expect(computingUnitStatusService.disconnect).not.toHaveBeenCalled();
       
expect(executeWorkflowService.resetExecutionAndWorkers).not.toHaveBeenCalled();
       
expect(workflowConsoleService.clearConsoleMessages).not.toHaveBeenCalled();
diff --git a/frontend/src/app/workspace/component/workspace.component.ts 
b/frontend/src/app/workspace/component/workspace.component.ts
index 3e43c07acd..3727c4b8c2 100644
--- a/frontend/src/app/workspace/component/workspace.component.ts
+++ b/frontend/src/app/workspace/component/workspace.component.ts
@@ -56,6 +56,7 @@ import { ExecuteWorkflowService } from 
"../service/execute-workflow/execute-work
 import { HeatmapStatsRestoreService } from 
"../service/heatmap/heatmap-stats-restore.service";
 import { WorkflowResultService } from 
"../service/workflow-result/workflow-result.service";
 import { checkIfWorkflowBroken } from "../../common/util/workflow-check";
+import { WorkflowVersionService } from 
"../../dashboard/service/user/workflow-version/workflow-version.service";
 import { NzSpinComponent } from "ng-zorro-antd/spin";
 import { ResultPanelComponent } from "./result-panel/result-panel.component";
 import { WorkflowEditorComponent } from 
"./workflow-editor/workflow-editor.component";
@@ -140,7 +141,8 @@ export class WorkspaceComponent implements AfterViewInit, 
OnInit, OnDestroy {
     private computingUnitStatusService: ComputingUnitStatusService,
     private executeWorkflowService: ExecuteWorkflowService,
     private workflowResultService: WorkflowResultService,
-    private heatmapStatsRestoreService: HeatmapStatsRestoreService
+    private heatmapStatsRestoreService: HeatmapStatsRestoreService,
+    private workflowVersionService: WorkflowVersionService
   ) {}
 
   ngOnInit() {
@@ -217,6 +219,7 @@ export class WorkspaceComponent implements AfterViewInit, 
OnInit, OnDestroy {
     // rather than rebuilt, which is what used to make the switch take seconds.
     if (isLeavingWorkspace(this.router, 
this.workflowActionService.getOpenWorkflowId())) {
       this.workflowActionService.clearWorkflow();
+      this.workflowVersionService.discardOpenVersionDisplay();
       this.computingUnitStatusService.disconnect();
       this.resetWorkflowSessionState();
       // The overlay's view lives in the root-provided wrapper; the metrics 
behind it are cleared

Reply via email to