Skip to content

SWR matplotlib__matplotlib-18454 - #75

Open
richeshgupta wants to merge 1 commit into
swr-base-840035cfrom
swr-head-840035c
Open

richeshgupta wants to merge 1 commit into
swr-base-840035cfrom
swr-head-840035c

Conversation

@richeshgupta

Copy link
Copy Markdown

SWRBench case matplotlib__matplotlib-18454: pinned base ec45ec7 to head 840035c of matplotlib#18454. Benchmark replay, not for merge.

When converting from jQuery to vanilla JavaScript, the trigger for the
figure closure was set to a non-existent event name, as the 'remove'
event is jQuery-specific.

As there is no DOM node removal event (unless using MutationObserver),
connect this handler to the notebook's `Cell` `OutputArea`'s 'cleared'
event. This is triggered both by re-running a cell, and by using the
Clear Output menu option.

Fixes matplotlib#18447.

@razorpay-slash razorpay-slash Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review

Reviewed up to 840035c.
All 5 reviewers completed.

mpl.figure.prototype.handle_close = function (fig, msg) {
var width = fig.canvas.width / fig.ratio;
fig.root.removeEventListener('remove', this._remove_fig_handler);
fig.cell_info[0].output_area.element.off(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Closing one figure unbinds the 'cleared' cleanup handler of every other figure in the same cell

Issue

Every figure shares the single prototype function _remove_fig_handler, and jQuery's .off(events, handler) removes all bindings of that function's guid on the element, so handle_close strips the 'cleared' handler of every figure bound to the cell's output area, not just the figure being closed. After one sibling figure is closed, clearing or re-running the cell never closes the remaining figures' comms, leaving their websockets and kernel-side figure managers alive for the life of the page.

Evidence

CONFIRMED: jQuery's .one() stores a wrapper carrying the original function's guid ('use same guid so caller can remove using origFn') and .off(type, fn) removes every handler with that guid; _remove_fig_handler is one prototype-level function that every figure in a cell binds to the same output_area.element, so a single handle_close removes them all. Creating two figures in one cell, closing the first, then clearing the cell shows the second figure's comm never closing.

console.error('Failed to find cell for figure', id, fig);
return;
}
fig.cell_info[0].output_area.element.one(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] No test exercises the new nbagg figure teardown when notebook output is cleared

Issue

The PR's core behaviour (closing figures when a cell's output area is cleared, and unbinding that handler in handle_close) is reachable only in a browser notebook session, and the diff adds no test covering it. A wrong event name, a broken event.data.fig contract in _remove_fig_handler, or the unconditional fig.cell_info[0] dereference in handle_close would fail no build, and the silent failure is the figure and websocket leak this teardown exists to prevent.

Evidence

SUSPECTED: the diff touches no test file, but coverage elsewhere in the repo was not verifiable from this review; a browser-driven nbagg test that renders a figure, clears the output area, and asserts the comm/websocket closes, plus one that closes a figure whose cell was never found, would settle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants