Skip to content

Commit b96c1fe

Browse files
yangzhang75claude
andcommitted
fix(workflow-form): redraw a result's chart in place, and drop the key that was meant to rebuild it
The visualization frame audited before it filtered. An update event carries only the operators whose result changed, so a window that closed on another operator's event was handed that event by the filter and dropped, taking this operator's pending redraw with it: the last update of a run could leave the previous picture showing for good. Filter first. The canvas result panel uses the same frame and gains the same reliability. The Form View keyed each chart frame by a per-operator version, bumped on every result update, meaning to rebuild the frame rather than reuse it. It could not do that. Every visualisation operator takes its whole input before it draws (`process_table`, single-snapshot output), so the update that carries a picture is the one that mounts the frame, and a second one never arrives; measured on a run, the chart's operator sees two updates, one picture and one frame, with the key and without it. A re-run replaces the snapshot inside the operator's result service, which lives until the page is left, so there is no new frame to key on there either. The machinery never fired, so it goes. No visible change: this fixes a latent ordering bug and removes code that cannot run. Closes apache#8759 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FVvP3ttj22f9LB4p9u2anY
1 parent ada1cfe commit b96c1fe

5 files changed

Lines changed: 52 additions & 46 deletions

File tree

‎frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ describe("VisualizationFrameContentComponent", () => {
151151
expect(iframe.getAttribute("srcdoc")).toBe(initialSrcdoc);
152152
}));
153153

154+
// An update event carries only the operators whose result changed, so events for different
155+
// operators interleave. With the audit before the filter, a window that closed on another
156+
// operator's event was dropped by the filter and this operator's pending redraw was lost.
157+
it("does not lose this operator's pending redraw to a later emission for another operator", fakeAsync(() => {
158+
snapshotProvider = () => makeResultSnapshot("<html><body><div>v1</div></body></html>");
159+
buildComponent("op-1");
160+
const iframe = fixture.nativeElement.querySelector("iframe") as HTMLIFrameElement;
161+
162+
snapshotProvider = () => makeResultSnapshot("<html><body><div>v2</div></body></html>");
163+
resultUpdateStream.next({ "op-1": { fake: true } });
164+
tick(UPDATE_INTERVAL_MS / 2);
165+
resultUpdateStream.next({ "some-other-op": { fake: true } });
166+
tick(UPDATE_INTERVAL_MS / 2);
167+
fixture.detectChanges();
168+
169+
expect(iframe.getAttribute("srcdoc")).toContain("v2");
170+
}));
171+
154172
it("ignores stream emissions when operatorId is undefined", fakeAsync(() => {
155173
buildComponent(undefined);
156174
const drawSpy = vi.spyOn(component, "drawChart");

‎frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ export class VisualizationFrameContentComponent implements AfterContentInit {
4545
// attempt to draw chart immediately
4646
this.drawChart();
4747

48-
// setup an event lister that re-draws the chart content every (n) milliseconds
49-
// auditTime makes sure the first re-draw happens after (n) milliseconds has elapsed
48+
// Re-draw on this operator's result updates, at most once per UPDATE_INTERVAL_MS: auditTime
49+
// holds the first re-draw until the interval has elapsed. Filter BEFORE auditing: an update
50+
// event carries only the operators whose result changed, so with the audit first a window that
51+
// closed on another operator's event handed the filter that event, and this operator's pending
52+
// re-draw was lost -- the last update of a run showed the previous picture for good.
5053
this.workflowResultService
5154
.getResultUpdateStream()
52-
.pipe(auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS))
5355
.pipe(filter(rec => this.operatorId !== undefined && rec[this.operatorId] !== undefined))
56+
.pipe(auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS))
5457
.pipe(untilDestroyed(this))
5558
.subscribe(() => {
5659
this.drawChart();

‎frontend/src/app/workspace/component/workflow-form/workflow-form.component.html‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,13 @@ <h3>Results shown here</h3>
608608
*ngSwitchCase="isTabularResult(id)"
609609
[operatorId]="id"></texera-result-table-frame>
610610
<ng-container *ngSwitchCase="vizHasContent(id)">
611-
<!-- Keyed on the result's version so a new result builds a new frame: the component
612-
reads its content once, at creation. -->
613-
<texera-visualization-panel-content
614-
*ngFor="let key of [resultKey(id)]; trackBy: trackByKey"
615-
[operatorId]="id"></texera-visualization-panel-content>
611+
<!-- The frame draws its content at creation and redraws in place on its operator's
612+
updates. A new run replaces the snapshot inside the operator's result service,
613+
which lives until the page is left, so there is never a new frame to key on.
614+
This was keyed on a per-result version meant to rebuild it; that key could never
615+
fire, because the update carrying a picture is the one that mounts the frame
616+
(see the result-update subscription). -->
617+
<texera-visualization-panel-content [operatorId]="id"></texera-visualization-panel-content>
616618
</ng-container>
617619
<p
618620
*ngSwitchDefault

‎frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,17 +2495,6 @@ describe("WorkflowFormComponent", () => {
24952495
expect(component.resultLabel("gone")).toBe("gone");
24962496
});
24972497

2498-
it("keeps a result's frame identity stable until its version moves", () => {
2499-
build(formViewWorkflow).ngOnInit();
2500-
const before = component.resultKey("op-1");
2501-
expect(component.resultKey("op-1")).toBe(before);
2502-
2503-
(component as any).resultVersion.set("op-1", 1);
2504-
2505-
expect(component.resultKey("op-1")).not.toBe(before);
2506-
expect(component.trackByKey(0, "k")).toBe("k");
2507-
});
2508-
25092498
it("resizes a result within bounds, per result, and re-fits after", () => {
25102499
vi.useFakeTimers();
25112500
build(formViewWorkflow).ngOnInit();
@@ -2528,13 +2517,20 @@ describe("WorkflowFormComponent", () => {
25282517
vi.useRealTimers();
25292518
});
25302519

2531-
it("bumps the result version and re-fits on a result update", () => {
2520+
// An update to a result the form already shows reaches the frame in place (the frame redraws on
2521+
// its operator's updates); the form only re-limits the shown set and re-fits. It used to keep a
2522+
// per-operator version here as well, to key the frame on, which nothing needs.
2523+
it("re-limits the shown results and re-fits on a result update, and rebuilds nothing", () => {
25322524
vi.useFakeTimers();
25332525
build(formViewWorkflow).ngOnInit();
2526+
const refresh = vi.spyOn(component as any, "refreshShownResults");
25342527
const fit = vi.spyOn(component as any, "fitVisualisations").mockImplementation(() => {});
25352528

25362529
h.resultUpdateStream.next({ "op-1": {} });
2537-
expect(component.resultKey("op-1")).toBe("op-1#1");
2530+
h.resultUpdateStream.next({ "op-1": {} });
2531+
2532+
expect(refresh).toHaveBeenCalledTimes(2);
2533+
expect(fit).not.toHaveBeenCalled();
25382534
vi.advanceTimersByTime(300);
25392535
expect(fit).toHaveBeenCalled();
25402536
vi.useRealTimers();

‎frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ export class WorkflowFormComponent implements OnInit, OnDestroy {
240240
/** Chart height per result (0 compact / 1 default / 2 tall). Per operator so one does not resize
241241
* the others, and in memory only -- a viewing preference, not part of the workflow. */
242242
private zoomByResult = new Map<string, number>();
243-
/** Bumped when a result changes, used as the chart's *ngFor identity so the frame is rebuilt, not
244-
* reused: the chart reads its content once at creation, so a stale frame showed "undefined". */
245-
private resultVersion = new Map<string, number>();
246-
247243
/** The collapsible workflow preview: closed until the reader opens it. */
248244
public workflowOpen = false;
249245
/** The embedded canvas is built the first time the strip opens, never while collapsed. */
@@ -367,15 +363,21 @@ export class WorkflowFormComponent implements OnInit, OnDestroy {
367363
.pipe(untilDestroyed(this))
368364
.subscribe(() => this.syncSelectionFromHighlight());
369365

370-
// A result changing bumps that operator's version (so its chart frame is rebuilt, not reused),
371-
// re-limits what the form shows to the currently-viewed set, and re-fits the visualisations.
366+
// A result update re-limits what the form shows to the currently-viewed set and re-fits the
367+
// visualisations. The chart frame itself is left alone: it redraws in place on its own
368+
// operator's updates (see the visualization frame, at most once per two seconds), and an
369+
// operator's result service lives until the page is left -- a re-run replaces the snapshot
370+
// inside it, nothing clears it -- so there is never a new frame to build mid-session.
371+
// This used to bump a per-operator version that keyed the frame, meaning to rebuild it rather
372+
// than reuse it. It could not do that: every visualisation operator takes its whole input
373+
// before it draws (`process_table`, single-snapshot output), so the one update that carries a
374+
// picture is also the one that mounts the frame, and a second one never comes. Measured on a
375+
// run: two updates for the chart's operator, one picture, one frame -- with the key and
376+
// without it. Dead machinery, so it goes.
372377
this.workflowResultService
373378
.getResultUpdateStream()
374379
.pipe(untilDestroyed(this))
375-
.subscribe(update => {
376-
for (const operatorID of Object.keys(update ?? {})) {
377-
this.resultVersion.set(operatorID, (this.resultVersion.get(operatorID) ?? 0) + 1);
378-
}
380+
.subscribe(() => {
379381
this.refreshShownResults();
380382
// markForCheck, not detectChanges: this fires often during a run, and a synchronous pass
381383
// can be thrown out of by an unrelated component's NG0100, killing the subscription.
@@ -1414,21 +1416,6 @@ export class WorkflowFormComponent implements OnInit, OnDestroy {
14141416
return operator ? this.formBindingService.operatorLabel(operator) : operatorID;
14151417
}
14161418

1417-
public trackByKey(_: number, key: string): string {
1418-
return key;
1419-
}
1420-
1421-
/**
1422-
* A per-result identity that changes on each result-update for that operator, used as the chart's
1423-
* *ngFor key so the frame is rebuilt (not reused) when the result changes: the chart reads its
1424-
* content once at creation, so a reused frame kept showing the old (or "undefined") picture. A
1425-
* visualisation's result arrives as a single snapshot, so in practice this bumps about once per
1426-
* result rather than per tuple.
1427-
*/
1428-
public resultKey(operatorID: string): string {
1429-
return operatorID + "#" + (this.resultVersion.get(operatorID) ?? 0);
1430-
}
1431-
14321419
public resultZoom(operatorID: string): number {
14331420
return this.zoomByResult.get(operatorID) ?? 1;
14341421
}

0 commit comments

Comments
 (0)