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-8729-097fecc56ad76e904a222e6bb3ff2cc3ee2ff597
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 846bf06c87a2fae2df2d0cf54ba539e721a4e0ce
Author: Prateek Ganigi <[email protected]>
AuthorDate: Sun Nov 8 06:38:24 2026 +0000

    fix(gui): release the previous row's work when the result modal navigates 
(#8729)
    
    ### What changes were proposed in this PR?
    
    The row-details modal is reused as the user pages through rows, the
    footer's `<` and `>` buttons mutate `rowIndex` and call `ngOnChanges()`
    directly, but its teardown was scoped to the modal's lifetime, so work
    started for one row outlived the move to the next.
    
    Two consequences. Every media cell fetched through the proxy created an
    object URL that was only revoked in `ngOnDestroy`, so paging through
    rows of images, audio or video held every blob from every row visited
    until the modal closed. And each `ngOnChanges` added another
    `selectTuple` subscription without ending the previous one, since
    `untilDestroyed` fires on destroy rather than on the next change, so a
    slower earlier response could land last and overwrite the row on screen.
    In-flight media requests had the same problem.
    
    Both now share one teardown: a `rowChange` subject that `ngOnChanges`
    emits before starting the next row's work. `releaseRow()` fires it and
    revokes that row's blobs, and the `selectTuple` and media requests are
    piped through `takeUntil(this.rowChange)`, so only the current row's
    work is ever live. `ngOnDestroy` calls the same method, keeping the
    revoke logic in one place.
    
    ### Any related issues?
    
    Closes #8727
    
    ### How was this PR tested?
    
    Written test-first. Three tests were added to
    `result-panel-modal.component.spec.ts`, the previous row's blobs are
    revoked on navigation, a late response from the previous row no longer
    overwrites the current one, and an in-flight media request is cancelled
    when the row changes. All three fail against the current component and
    pass with the change; reverting the component and re-running makes
    exactly those three fail again.
    
    The file is at 24 tests, the result-panel suite at 180 across 5 files,
    and Prettier is clean.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Yes, this PR was co-authored with Claude in compliance with ASF policy.
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../result-panel-modal.component.spec.ts           | 110 ++++++++++++++++++++-
 .../result-panel/result-panel-modal.component.ts   |  29 +++++-
 2 files changed, 135 insertions(+), 4 deletions(-)

diff --git 
a/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.spec.ts
 
b/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.spec.ts
index 1251c0cd88..e0ccc6f08c 100644
--- 
a/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.spec.ts
+++ 
b/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.spec.ts
@@ -24,7 +24,7 @@ import { PanelResizeService } from 
"../../service/workflow-result/panel-resize/p
 import { WorkflowResultService } from 
"../../service/workflow-result/workflow-result.service";
 import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal";
 import { HttpClientTestingModule, HttpTestingController } from 
"@angular/common/http/testing";
-import { of } from "rxjs";
+import { of, Subject } from "rxjs";
 import { AppSettings } from "../../../common/app-setting";
 import { NotificationService } from 
"../../../common/service/notification/notification.service";
 
@@ -143,6 +143,66 @@ describe("RowModalComponent", () => {
     revokeSpy.mockRestore();
   });
 
+  // #8727: the modal is reused across rows — the footer's < / > buttons mutate
+  // rowIndex and call ngOnChanges() directly — but its teardown was scoped to 
the
+  // modal's lifetime, so blobs and subscriptions accumulated per row visited.
+  it("should revoke the previous row's blob URLs when navigating to another 
row", () => {
+    const revokeSpy = vi.spyOn(URL, "revokeObjectURL");
+    (component as any).allocatedBlobUrls.push("blob:row-3-a", "blob:row-3-b");
+
+    component.rowIndex = 4;
+    component.ngOnChanges();
+
+    expect(revokeSpy).toHaveBeenCalledWith("blob:row-3-a");
+    expect(revokeSpy).toHaveBeenCalledWith("blob:row-3-b");
+    expect((component as any).allocatedBlobUrls).toEqual([]);
+    revokeSpy.mockRestore();
+  });
+
+  it("should ignore a previous row's response that arrives after navigating 
away", () => {
+    const rowThree = new Subject<{ tuple: Record<string, unknown> }>();
+    const rowFour = new Subject<{ tuple: Record<string, unknown> }>();
+    const selectTuple = 
vi.fn().mockReturnValueOnce(rowThree).mockReturnValueOnce(rowFour);
+    const service = TestBed.inject(WorkflowResultService) as any;
+    // Restore afterwards: the spy object is shared across every test in this 
file.
+    const original = service.getPortPaginatedResultService;
+    service.getPortPaginatedResultService = vi.fn().mockReturnValue({ 
selectTuple });
+
+    try {
+      component.rowIndex = 3;
+      component.ngOnChanges();
+      component.rowIndex = 4;
+      component.ngOnChanges();
+
+      // Row 4 answers first, then row 3's slower response lands.
+      rowFour.next({ tuple: { id: "row-4" } });
+      rowThree.next({ tuple: { id: "row-3" } });
+
+      expect(component.currentDisplayRowData).toEqual({ id: "row-4" });
+    } finally {
+      service.getPortPaginatedResultService = original;
+    }
+  });
+
+  it("should cancel an in-flight media request when navigating to another 
row", () => {
+    const createObjectURLSpy = vi.spyOn(URL, 
"createObjectURL").mockReturnValue("blob:stale");
+    const remoteUrl = "https://example.com/stale.png";;
+    (component as any).buildRowEntries({ img: remoteUrl });
+    const req = httpMock.expectOne(
+      
`${AppSettings.getApiEndpoint()}/huggingface/media-proxy?url=${encodeURIComponent(remoteUrl)}`
+    );
+    expect(req.cancelled).toBe(false);
+
+    component.rowIndex = 4;
+    component.ngOnChanges();
+
+    // The previous row's fetch is dropped, so it can neither allocate a blob 
nor
+    // write its media into the row now on screen.
+    expect(req.cancelled).toBe(true);
+    expect(createObjectURLSpy).not.toHaveBeenCalled();
+    createObjectURLSpy.mockRestore();
+  });
+
   it("prettyRowJson should return pretty-printed JSON of 
currentDisplayRowData", () => {
     component.currentDisplayRowData = { name: "test", value: 42 };
     expect(component.prettyRowJson).toBe(JSON.stringify({ name: "test", value: 
42 }, null, 2));
@@ -248,6 +308,54 @@ describe("RowModalComponent (with pre-loaded rowData)", () 
=> {
   });
 });
 
+// Review feedback on #8729 (@Copilot): the constructor builds entries from 
preloaded
+// rowData, which starts their media requests. Opening the modal must not tear 
that
+// first row down, or with no pagination service to refetch the row its remote 
media
+// never loads.
+describe("RowModalComponent (with pre-loaded remote media)", () => {
+  let component: RowModalComponent;
+  let httpMock: HttpTestingController;
+
+  const remoteUrl = "https://example.com/preloaded.png";;
+
+  beforeEach(async () => {
+    await TestBed.configureTestingModule({
+      imports: [RowModalComponent, HttpClientTestingModule],
+      providers: [
+        { provide: NZ_MODAL_DATA, useValue: { operatorId: "op-3", rowIndex: 0, 
rowData: { img: remoteUrl } } },
+        { provide: NzModalRef, useValue: { getConfig: () => ({}), close: 
vi.fn() } },
+        {
+          provide: WorkflowResultService,
+          useValue: { getPortPaginatedResultService: 
vi.fn().mockReturnValue(null) },
+        },
+        { provide: PanelResizeService, useValue: { pageSize: 10 } },
+      ],
+    }).compileComponents();
+
+    httpMock = TestBed.inject(HttpTestingController);
+    const fixture = TestBed.createComponent(RowModalComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  afterEach(() => {
+    httpMock.verify();
+  });
+
+  it("should load the first row's remote media even with no pagination service 
to refetch it", () => {
+    const createObjectURLSpy = vi.spyOn(URL, 
"createObjectURL").mockReturnValue("blob:preloaded");
+    const req = httpMock.expectOne(
+      
`${AppSettings.getApiEndpoint()}/huggingface/media-proxy?url=${encodeURIComponent(remoteUrl)}`
+    );
+    expect(req.cancelled).toBe(false);
+
+    req.flush(new Blob(["img"], { type: "image/png" }));
+
+    expect(component.rowEntries.find(e => e.key === 
"img")?.mediaSrc).toBe("blob:preloaded");
+    createObjectURLSpy.mockRestore();
+  });
+});
+
 describe("RowModalComponent (template rendering)", () => {
   let component: RowModalComponent;
   let fixture: ComponentFixture<RowModalComponent>;
diff --git 
a/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.ts
 
b/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.ts
index 5105bcbbd0..86b0b8dab0 100644
--- 
a/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.ts
+++ 
b/frontend/src/app/workspace/component/result-panel/result-panel-modal.component.ts
@@ -25,6 +25,7 @@ import { NzIconModule } from "ng-zorro-antd/icon";
 import { HttpClient } from "@angular/common/http";
 import { WorkflowResultService } from 
"../../service/workflow-result/workflow-result.service";
 import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
+import { Subject, takeUntil } from "rxjs";
 import { PanelResizeService } from 
"../../service/workflow-result/panel-resize/panel-resize.service";
 import { NotificationService } from 
"../../../common/service/notification/notification.service";
 import { isAudioUrl, isVideoUrl, isImageUrl } from 
"src/app/common/util/media-type.util";
@@ -54,6 +55,12 @@ export class RowModalComponent implements OnChanges, 
OnDestroy {
   rowEntries: { key: string; value: string; mediaSrc: string; isVideo: 
boolean; isImage: boolean; isAudio: boolean }[] =
     [];
   private readonly allocatedBlobUrls: string[] = [];
+  // The modal is reused as the user pages through rows (the footer's < and >
+  // buttons mutate rowIndex and call ngOnChanges), so work started for one row
+  // has to be torn down when the next one is requested. untilDestroyed only
+  // fires when the modal closes, which is too late: stale responses would
+  // overwrite the current row and every row's blobs would be held until then.
+  private readonly rowChange = new Subject<void>();
   // Index of current displayed row in currentResult
   private readonly modalData: {
     operatorId: string;
@@ -78,7 +85,9 @@ export class RowModalComponent implements OnChanges, 
OnDestroy {
       this.currentDisplayRowData = this.modalData.rowData;
       this.rowEntries = this.buildRowEntries(this.currentDisplayRowData);
     }
-    this.ngOnChanges();
+    // Load, not ngOnChanges: there is no previous row yet, and releasing here 
would
+    // cancel the media requests the preloaded entries above just started.
+    this.loadRow();
   }
 
   get prettyRowJson(): string {
@@ -93,10 +102,16 @@ export class RowModalComponent implements OnChanges, 
OnDestroy {
   }
 
   ngOnChanges(): void {
+    this.releaseRow();
+    this.loadRow();
+  }
+
+  /** Fetches the current row; a later row change cancels it. */
+  private loadRow(): void {
     this.workflowResultService
       .getPortPaginatedResultService(this.operatorId, this.portIndex)
       ?.selectTuple(this.rowIndex, this.resizeService.pageSize)
-      .pipe(untilDestroyed(this))
+      .pipe(takeUntil(this.rowChange), untilDestroyed(this))
       .subscribe(res => {
         if (res?.tuple) {
           this.currentDisplayRowData = res.tuple;
@@ -110,9 +125,17 @@ export class RowModalComponent implements OnChanges, 
OnDestroy {
   }
 
   ngOnDestroy(): void {
+    this.releaseRow();
+    this.rowChange.complete();
+  }
+
+  /** Cancels the current row's in-flight work and frees the blobs it 
allocated. */
+  private releaseRow(): void {
+    this.rowChange.next();
     for (const url of this.allocatedBlobUrls) {
       URL.revokeObjectURL(url);
     }
+    this.allocatedBlobUrls.length = 0;
   }
 
   private fetchBlobSrc(
@@ -122,7 +145,7 @@ export class RowModalComponent implements OnChanges, 
OnDestroy {
     const proxyUrl = 
`${AppSettings.getApiEndpoint()}/huggingface/media-proxy?url=${encodeURIComponent(remoteUrl)}`;
     this.http
       .get(proxyUrl, { responseType: "blob" })
-      .pipe(untilDestroyed(this))
+      .pipe(takeUntil(this.rowChange), untilDestroyed(this))
       .subscribe({
         next: blob => {
           const blobUrl = URL.createObjectURL(blob);

Reply via email to