Skip to content

Commit 2f48f6e

Browse files
authored
refactor: remove window.resize fallback
1 parent 978bd01 commit 2f48f6e

2 files changed

Lines changed: 3 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ In short, this means that simply adding data points to a trace in `data` or chan
132132
| `className` | `string` | `undefined` | applied to the `<div>` into which the plot is rendered |
133133
| `style` | `Object` | `{position: 'relative', display: 'inline-block'}` | used to style the `<div>` into which the plot is rendered |
134134
| `debug` | `Boolean` | `false` | Assign the graph div to `window.gd` for debugging |
135-
| `useResizeHandler` | `Boolean` | `false` | When true, adds a call to `Plotly.Plots.resize()` using `ResizeObserver`. Falls back to a `window.resize` event when `ResizeObserver` is unavailable |
135+
| `useResizeHandler` | `Boolean` | `false` | When true, adds a call to `Plotly.Plots.resize()` using `ResizeObserver`. |
136136

137137
**Refs**: a `ref` attached to `<Plot>` resolves to the rendered `<div>` element (the plotly graph div), so you can call low-level plotly.js APIs against it directly (e.g. `Plotly.toImage(ref.current)`).
138138

src/factory.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ export default function plotComponentFactory(Plotly) {
181181
if (resizeObserverRef.current) {
182182
resizeObserverRef.current.disconnect();
183183
resizeObserverRef.current = null;
184-
} else if (resizeHandlerRef.current && isBrowser) {
185-
window.removeEventListener('resize', resizeHandlerRef.current);
186184
}
187185

188186
resizeHandlerRef.current = null;
@@ -194,14 +192,8 @@ export default function plotComponentFactory(Plotly) {
194192
}
195193
if (useResizeHandler && !resizeHandlerRef.current) {
196194
resizeHandlerRef.current = () => Plotly.Plots.resize(elRef.current);
197-
198-
if (typeof window.ResizeObserver === 'function') {
199-
resizeObserverRef.current = new window.ResizeObserver(resizeHandlerRef.current);
200-
resizeObserverRef.current.observe(elRef.current);
201-
} else {
202-
window.addEventListener('resize', resizeHandlerRef.current);
203-
}
204-
195+
resizeObserverRef.current = new window.ResizeObserver(resizeHandlerRef.current);
196+
resizeObserverRef.current.observe(elRef.current);
205197
if (invoke) {
206198
resizeHandlerRef.current();
207199
}

0 commit comments

Comments
 (0)