Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Save event listeners when calling newPlot
Call react again to ensure transitions are triggered
Remove obsolete references to configChanged
  • Loading branch information
camdecoster committed Sep 3, 2025
commit 29ccfaf99f6eb2fb788180363634e1d59c106eea
23 changes: 15 additions & 8 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,17 @@ function react(gd, data, layout, config) {
}

if(configChanged) {
plotDone = exports.newPlot(gd, data, layout, config);
// Save event listeners as newPlot will remove them
const eventListeners = gd._ev.eventNames().map(name => [name, gd._ev.listeners(name)]);
plotDone = exports.newPlot(gd, data, layout, config)
.then(() => {
for (const [name, callbacks] of eventListeners) {
callbacks.forEach((cb) => gd.on(name, cb));
}

// Call react in case transition should have occurred along with config change
return exports.react(gd, data, layout, config)
});
} else {
gd.data = data || [];
helpers.cleanData(gd.data);
Expand Down Expand Up @@ -2683,7 +2693,7 @@ function react(gd, data, layout, config) {
// only used when 'transition' is set by user and
// when at least one animatable attribute has changed,
// N.B. config changed aren't animatable
if(newFullLayout.transition && !configChanged && (restyleFlags.anim || relayoutFlags.anim)) {
if(newFullLayout.transition && (restyleFlags.anim || relayoutFlags.anim)) {
if(relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout);

Plots.doCalcdata(gd);
Expand All @@ -2692,7 +2702,7 @@ function react(gd, data, layout, config) {
seq.push(function() {
return Plots.transitionFromReact(gd, restyleFlags, relayoutFlags, oldFullLayout);
});
} else if(restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {
} else if(restyleFlags.fullReplot || relayoutFlags.layoutReplot) {
gd._fullLayout._skipDefaults = true;
seq.push(exports._doPlot);
} else {
Expand Down Expand Up @@ -2737,11 +2747,8 @@ function react(gd, data, layout, config) {
}
}

return plotDone.then(function() {
gd.emit('plotly_react', {
data: data,
layout: layout
});
return plotDone.then(() => {
if (!configChanged) gd.emit('plotly_react', { config, data, layout });
Copy link
Contributor

Choose a reason for hiding this comment

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

@camdecoster Is there a reason we don't want to emit a plotly_react event if the config changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will emit twice for one call to react without that check. This is because we call newPlot and then react again after that, all within the first call to react.


return gd;
});
Expand Down
Loading