Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking(responsive, xychart): require ResizeObserver or polyfill #1622

Merged
merged 6 commits into from
Jan 6, 2023

Conversation

williaster
Copy link
Collaborator

@williaster williaster commented Jan 3, 2023

💥 Breaking Changes

Cleaning up some legacy stuff here in preparation for the 3.0.0 breaking release:

  • @visx/responsive
    • removes ParentSizeModern and withParentSizeModern which assume a globally-available ResizeObserver polyfill
    • removes the global ResizeObserver polyfill in ParentSize and withParentSize, and adds resizeObserverPolyfill as an optional prop (component) / option (enhancer). this mirrors how @visx/tooltip and @visx/annotation handle this polyfill requirment
  • @visx/xychart
    • this packages uses @visx/responsive, so bringing in the above change requires that we now polyfill ResizeObserver. instructions were added to the readme, but this can be done either globally, or through prop injection on XYChart
      • noting that <Tooltip /> and <AnnotationLabel /> inside @visx/xychart already required such a polyfill, so this shouldn't be a huge problem for upgrading (tho it is definitely a breaking change)

console.warn = console.error = function mockedConsole(message) {
throw new Error(message);
};
function mockedConsole(...args) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was swallowing some messages so made it ...args

observe(el: Element): void;
type ResizeObserverCallback = (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;

declare class ResizeObserver {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated this definition to better match @juggle/resize-observer and react-use-measure

@@ -42,5 +42,5 @@ module.exports = {
testURL: 'http://localhost',
timers: 'fake',
verbose: false,
testPathIgnorePatterns: ['<rootDir>/packages/visx-demo', '<rootDir>/packages/visx-visx'],
testPathIgnorePatterns: ['<rootDir>/packages/visx-demo'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@visx/visx tests were turned off 😱

@github-actions
Copy link

github-actions bot commented Jan 4, 2023

Size Changes

Package Diff ESM Prev ESM CJS Prev CJS
visx-responsive 🔻 -37.9% 12.67 KB 20.4 KB 15.8 KB 25.61 KB
visx-xychart +0.4% 173.95 KB 173.24 KB 234.3 KB 233.59 KB

Compared to master. File sizes are unminified and ungzipped.

View raw build stats

Previous (master)

{
  "visx-annotation": {
    "esm": 31002,
    "lib": 43431
  },
  "visx-axis": {
    "esm": 21861,
    "lib": 26466
  },
  "visx-bounds": {
    "esm": 2948,
    "lib": 3371
  },
  "visx-brush": {
    "esm": 54136,
    "lib": 58297
  },
  "visx-chord": {
    "esm": 3478,
    "lib": 4691
  },
  "visx-clip-path": {
    "esm": 4524,
    "lib": 6062
  },
  "visx-curve": {
    "esm": 323,
    "lib": 1462
  },
  "visx-demo": {
    "esm": 0,
    "lib": 36504
  },
  "visx-drag": {
    "esm": 12756,
    "lib": 14402
  },
  "visx-event": {
    "esm": 3878,
    "lib": 5194
  },
  "visx-geo": {
    "esm": 13515,
    "lib": 16741
  },
  "visx-glyph": {
    "esm": 15177,
    "lib": 19992
  },
  "visx-gradient": {
    "esm": 18202,
    "lib": 22847
  },
  "visx-grid": {
    "esm": 18982,
    "lib": 22665
  },
  "visx-group": {
    "esm": 1648,
    "lib": 2267
  },
  "visx-heatmap": {
    "esm": 7394,
    "lib": 8731
  },
  "visx-hierarchy": {
    "esm": 12093,
    "lib": 17910
  },
  "visx-legend": {
    "esm": 26944,
    "lib": 34024
  },
  "visx-marker": {
    "esm": 9152,
    "lib": 11350
  },
  "visx-mock-data": {
    "esm": 326040,
    "lib": 329480
  },
  "visx-network": {
    "esm": 4674,
    "lib": 6809
  },
  "visx-pattern": {
    "esm": 11689,
    "lib": 15763
  },
  "visx-point": {
    "esm": 1003,
    "lib": 1818
  },
  "visx-react-spring": {
    "esm": 14000,
    "lib": 17725
  },
  "visx-responsive": {
    "esm": 20892,
    "lib": 26221
  },
  "visx-scale": {
    "esm": 18649,
    "lib": 30334
  },
  "visx-shape": {
    "esm": 86912,
    "lib": 108820
  },
  "visx-stats": {
    "esm": 13738,
    "lib": 15320
  },
  "visx-text": {
    "esm": 8567,
    "lib": 10114
  },
  "visx-threshold": {
    "esm": 2907,
    "lib": 3806
  },
  "visx-tooltip": {
    "esm": 14976,
    "lib": 21474
  },
  "visx-visx": {
    "esm": 1524,
    "lib": 4487
  },
  "visx-voronoi": {
    "esm": 2314,
    "lib": 3021
  },
  "visx-wordcloud": {
    "esm": 2620,
    "lib": 3455
  },
  "visx-xychart": {
    "esm": 177399,
    "lib": 239197
  },
  "visx-zoom": {
    "esm": 16077,
    "lib": 19135
  }
}

Current

{
  "visx-annotation": {
    "esm": 31002,
    "lib": 43431
  },
  "visx-axis": {
    "esm": 21861,
    "lib": 26466
  },
  "visx-bounds": {
    "esm": 2948,
    "lib": 3371
  },
  "visx-brush": {
    "esm": 54136,
    "lib": 58297
  },
  "visx-chord": {
    "esm": 3478,
    "lib": 4691
  },
  "visx-clip-path": {
    "esm": 4524,
    "lib": 6062
  },
  "visx-curve": {
    "esm": 323,
    "lib": 1462
  },
  "visx-demo": {
    "esm": 0,
    "lib": 36504
  },
  "visx-drag": {
    "esm": 12756,
    "lib": 14402
  },
  "visx-event": {
    "esm": 3878,
    "lib": 5194
  },
  "visx-geo": {
    "esm": 13515,
    "lib": 16741
  },
  "visx-glyph": {
    "esm": 15177,
    "lib": 19992
  },
  "visx-gradient": {
    "esm": 18202,
    "lib": 22847
  },
  "visx-grid": {
    "esm": 18982,
    "lib": 22665
  },
  "visx-group": {
    "esm": 1648,
    "lib": 2267
  },
  "visx-heatmap": {
    "esm": 7394,
    "lib": 8731
  },
  "visx-hierarchy": {
    "esm": 12093,
    "lib": 17910
  },
  "visx-legend": {
    "esm": 26944,
    "lib": 34024
  },
  "visx-marker": {
    "esm": 9152,
    "lib": 11350
  },
  "visx-mock-data": {
    "esm": 326040,
    "lib": 329480
  },
  "visx-network": {
    "esm": 4674,
    "lib": 6809
  },
  "visx-pattern": {
    "esm": 11689,
    "lib": 15763
  },
  "visx-point": {
    "esm": 1003,
    "lib": 1818
  },
  "visx-react-spring": {
    "esm": 14000,
    "lib": 17725
  },
  "visx-responsive": {
    "esm": 12972,
    "lib": 16175
  },
  "visx-scale": {
    "esm": 18649,
    "lib": 30334
  },
  "visx-shape": {
    "esm": 86912,
    "lib": 108820
  },
  "visx-stats": {
    "esm": 13738,
    "lib": 15320
  },
  "visx-text": {
    "esm": 8567,
    "lib": 10114
  },
  "visx-threshold": {
    "esm": 2907,
    "lib": 3806
  },
  "visx-tooltip": {
    "esm": 14976,
    "lib": 21474
  },
  "visx-visx": {
    "esm": 1524,
    "lib": 4487
  },
  "visx-voronoi": {
    "esm": 2314,
    "lib": 3021
  },
  "visx-wordcloud": {
    "esm": 2620,
    "lib": 3455
  },
  "visx-xychart": {
    "esm": 178125,
    "lib": 239923
  },
  "visx-zoom": {
    "esm": 16077,
    "lib": 19135
  }
}

@williaster williaster changed the title breaking(responsive/ParentSize, withParentSize): require ResizeObserver or polyfill breaking(responsive, xychart): require ResizeObserver or polyfill Jan 4, 2023
import { ResizeObserver } from 'your-favorite-polyfill';

function App() {
return <Label resizeObserverPolyfill={ResizeObserver} {...} />
Copy link

Choose a reason for hiding this comment

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

I wonder if this can be globally configured instead so users don't have to pass it around any time they need to use the observer? E.g.

import { ResizeObserver } from 'your-favorite-polyfill';
import { setResizeObserverPolyfill } from '@visx/responsive';

setResizeObserverPolyfill(ResizeObserver)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh that's a great idea

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I may pursue that as a followup since it could be added as a util to complement the props-based approach. I think we'd prob still want both options.

@williaster williaster force-pushed the chris--responsive-modern-only branch from 356b1d0 to fcbc680 Compare January 5, 2023 22:57
@williaster williaster merged commit 0c838eb into master Jan 6, 2023
@williaster williaster deleted the chris--responsive-modern-only branch January 6, 2023 01:28
@williaster williaster mentioned this pull request Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants