bin size becomes 1 (very thin) when data changes with `barmode: 'overlay'` for histogram

Reproducible example

Demo: https://codepen.io/Lexachoc/pen/KwdWZGv

The problem

When the histogram data changes (mutates) and layout.barmode is set to 'overlay', the bin size resets to 1.
This happens in two cases:

  1. Switching from linear (numeric) values to category values, then back to linear.

Before:
linear (numeric):
Image

category values (after changing data):
Image

After:
linear (numeric) (after changing back):
Image

  1. Switching from linear (numeric) values to linear (numeric), then back to original data.

Before:
linear (numeric):
Image

linear (numeric) (after changing data):
Image

After:
linear (numeric) (after changing back):
Image

You can clearly see the bins become extremely thin after the data update, but only when barmode: 'overlay' is used.

Expected behavior

Bin sizes should remain consistent or auto-adjust correctly when data changes, not reset to 1, which makes the bins extremely thin.

Why this is important

For react-plotly and other reactive setups, data changes are very common. This bug makes histogram rendering unreliable when using 'overlay', which is often needed for comparing multiple datasets. It is a critical issue for apps that frequently re-render histograms with updated data.

This problem seems to exist for many years. I've seen similar issues reported a long time ago.

Relevent issue

#2389

Note

This issue may just be a side effect of Plotly.react (see #2389) that happens to be visible in this case. Here, I'm only focusing on the resulting bin size issue.