Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import 'core-js/stable';
import { ResizeObserver as Polyfill } from '@juggle/resize-observer';
import { css } from '@linaria/core';

// @ts-expect-error
if (typeof ResizeObserver === 'undefined') {
// @ts-expect-error
window.ResizeObserver = Polyfill;
}
window.ResizeObserver ??= Polyfill;

css`
:global() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"react-sortable-hoc": "^1.11.0",
"rollup": "^2.39.0",
"rollup-plugin-postcss": "^4.0.0",
"typescript": "~4.1.5"
"typescript": "~4.2.2"
},
"peerDependencies": {
"react": "^16.14 || ^17.0",
Expand Down
15 changes: 1 addition & 14 deletions src/hooks/useGridDimensions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { useRef, useState, useLayoutEffect } from 'react';

// https://github.com/microsoft/TypeScript/issues/37861
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

interface ResizeObserverEntry {
contentRect: {
width: number;
height: number;
};
}

type ResizeObserver = new (callback: (entries: readonly ResizeObserverEntry[]) => void) => {
observe: (target: Element) => void;
disconnect: () => void;
};

export function useGridDimensions(): [ref: React.RefObject<HTMLDivElement>, width: number, height: number] {
const gridRef = useRef<HTMLDivElement>(null);
const [gridWidth, setGridWidth] = useState(1);
const [gridHeight, setGridHeight] = useState(1);

useLayoutEffect(() => {
const { ResizeObserver } = window as typeof window & { ResizeObserver: ResizeObserver };
const { ResizeObserver } = window;

// don't break in jest/jsdom and browsers that don't support ResizeObserver
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Expand Down
23 changes: 15 additions & 8 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// @ts-expect-error
window.ResizeObserver ??= function ResizeObserver(callback: () => void) {
callback();

return {
observe() {},
disconnect() {}
};
import 'core-js/stable';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TS complains without an import/export, so I added this. It doesn't hurt to have I guess.

test/setup.ts:1:1 - error TS1208: 'setup.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

1 window.ResizeObserver ??= class {
  ~~~~~~


window.ResizeObserver ??= class {
callback: ResizeObserverCallback;

constructor(callback: ResizeObserverCallback) {
this.callback = callback;
}

observe() {
this.callback([], this);
}

unobserve() {}
disconnect() {}
};

// patch clientWidth/clientHeight to pretend we're rendering DataGrid at 1080p
Expand Down