Coder Social home page Coder Social logo

react-virtualized-auto-sizer's Introduction

react-virtualized-auto-sizer

Standalone version of the AutoSizer component from react-virtualized.

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Install

npm install --save react-virtualized-auto-sizer

Documentation

Property Type Required? Description
children Function Function responsible for rendering children. This function should implement the following signature: ({ height?: number | undefined, width?: number | undefined }) => PropTypes.element
className String Optional custom CSS class name to attach to root AutoSizer element. This is an advanced property and is not typically necessary.
defaultHeight Number Height passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate height after mounting.
defaultWidth Number Width passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate width after mounting.
disableHeight Boolean Fixed height; if specified, the child's height property will not be managed
disableWidth Boolean Fixed width; if specified, the child's width property will not be managed
doNotBailOutOnEmptyChildren boolean Optional propr that can override default behavior of not rendering children when either width or height are 0
nonce String Nonce of the inlined stylesheets for Content Security Policy
onResize Function Callback to be invoked on-resize; it is passed the following named parameters: ({ height: number, width: number }).
style Object Optional custom inline style to attach to root AutoSizer element. This is an advanced property and is not typically necessary.
tagName string Optional HTML tag name for root element; defaults to "div"

Examples

Some components (like those found in react-window or react-virtualized) require numeric width and height parameters. The AutoSizer component can be useful if you want to pass percentage based dimensions.

import AutoSizer from "react-virtualized-auto-sizer";

// UI
<AutoSizer>
  {({ height, width }) => {
    // Use these actual sizes to calculate your percentage based sizes
  }}
</AutoSizer>;

FAQs

Can I use this component with flexbox?

Flex containers don't prevent their children from growing and AutoSizer greedily grows to fill as much space as possible. Combining the two can be problematic. The simple way to fix this is to nest AutoSizer inside of a block element (like a <div>) rather than putting it as a direct child of the flex container, like so:

<div style={{ display: 'flex' }}>
  <!-- Other children... -->
  <div style={{ flex: '1 1 auto' }}>
    <AutoSizer>
      {({ height, width }) => (
        <Component
          width={width}
          height={height}
          {...props}
        />
      )}
    </AutoSizer>
  </div>
</div>

Why is AutoSizer passing a height of 0?

AutoSizer expands to fill its parent but it will not stretch the parent. This is done to prevent problems with flexbox layouts. If AutoSizer is reporting a height (or width) of 0- then it's likely that the parent element (or one of its parents) has a height of 0.

The solution to this problem is often to add height: 100% or flex: 1 to the parent. One easy way to test this is to add a style property (eg background-color: red;) to the parent to visually confirm that it is the expected size.

Can I use AutoSizer to manage only width or height (not both)?

You can use AutoSizer to control only one dimension of its child component using the disableHeight or disableWidth attributes. For example, a fixed-height component that should grow to fill the available width can be created like so:

<AutoSizer disableHeight>
  {({width}) => <Component height={200} width={width} {...props} />}
</AutoSizer>

Module parsing fails because of an unexpected token?

This package targets ECMAScript 2015 (ES6) and requires a build tool such as babel-loader that is capable of parsing the ES6 class syntax.

Can this component work with a Content Security Policy?

The specification of Content Security Policy describes as the following:

This document defines Content Security Policy, a mechanism web applications can use to mitigate a broad class of content injection vulnerabilities, such as cross-site scripting (XSS).

To apply Content Security Policy, pass a nonce to AutoSizer and add a matching nonce-source to the Content-Security-Policy field in HTTP header.

react-virtualized-auto-sizer's People

Contributors

andarist avatar bvaughn avatar go7hic avatar hoxyq avatar inokawa avatar lritter79 avatar moritzmhmk avatar petemill avatar replygirl avatar saperdadsk avatar shhnjk avatar soren121 avatar thawsitt avatar yorch-s1 avatar yroc92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-virtualized-auto-sizer's Issues

AutoSize has a styling problem

I downloaded the react-window@next

左侧使用的是固定宽度和高度的 FixedSizeList

The left side USES FixedSizeList with fixed width and height

右侧使用的是react-virtualized-auto-sizer

On the right are the ruit-virtualized -auto-sizer

样式表现有问题

目前遇到两个问题我很困惑:
At present, I am confused by two problems:

1.自动宽度和高度,是否把滚动条的宽度也会计算进去?
Auto width and height, will scroll bar width be calculated?
2.为什么自动宽度和高度有时会失效? 一条消息的宽度竟然会重叠,样式会变成不可控制的状态

  1. Why does automatic width and height sometimes fail? The width of a message can overlap, and the style can become uncontrollable
    image

我用您的库重构了整个项目,这是最后遇到的问题了,也是最核心的部分,这段时间一直打扰您,不好意思。谢谢!

I used your library to reconstruct the whole project. This is the last problem I encountered, which is also the most core part. I have been disturbing you all this time. Thank you very much!

API change in type Size

Hello,
I was trying the latest version (seems like I decided to update the same time as you did).
And I wonder why this change was made and is necessary.

The type Size changed from
{ height: number, width: number } to { height?: number, width?: number }
To me this seems unnecessary as there is a defaultHeight and defaultWidth props that should be used if no value is computed.

export type Size = {
height?: number;
width?: number;
};

Version 1.0.9 - Breaking Change in Output Format and Semantic Versioning

Hello Maintainers,

First of all, I'd like to express my gratitude for the effort you've put into creating and maintaining this fantastic open-source project. It has been very beneficial to us, and we truly appreciate your hard work.

I'm writing to report an issue we've encountered in version 1.0.9 of the react-virtualized-auto-sizer module. It appears that the recent changes in output format have introduced a breaking change, causing one of our builds to fail. As a temporary solution, we've pinned the version to 1.0.7.

Here is the error message we encountered:

[2023-03-29T03:07:57.343Z] ./node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.module.js 201:24
[2023-03-29T03:07:57.343Z]   201:24  error  Module parse failed: Unexpected token You may need an appropriate
[2023-03-29T03:07:57.343Z]                  loader to handle this file type, currently no loaders are configured to
[2023-03-29T03:07:57.343Z]                  process this file.

I understand that our codebase is outdated, and we are partially responsible for the issue we've encountered. However, I'd like to kindly point out that the open-source community generally adheres to semantic versioning. In my opinion, the breaking change in output format should be marked as a major release, helping users to be aware of the potential issues before updating their dependencies.

I understand that maintaining an open-source project can be challenging, and I want to emphasize that we appreciate all your hard work. I hope this bug report is helpful to you and the community. If you need any further information or assistance in resolving this issue, please don't hesitate to ask.

Thank you and best regards

bailoutOnChildren causes remounts

Hey,

I'm building an app that uses react navigation which includes a tab navigation. When a tab isn't selected I'm hiding the parent screens using display: none so I can retain scrolling positions as users tab around the app. I noticed that one of my lists was losing its scroll and entirely being remounted and it's due to the usage of the ResizeObserver calling the onResize callback while the screen is in this state. Previously it'd just render but now since bailoutOnChildren is true (due to the rect being 0x0) it'll render no children, then when you tab back it'll render again. It might be nice to have a flag to control if this bail out happens

Thanks!

Autosizer sets state in componentDidMount causing a nested update

Autosizer sets state in componentDidMount phase which will block browser from repainting. This can be a big performance bottleneck.

Here is a codesandbox to demonstrate how changing state in componentDidMount phase can take longer to paint

https://codesandbox.io/p/sandbox/react-class-forked-5ffvgl?file=%2Fsrc%2Findex.js

Trace with state change inside componentDidMount
image

Trace without state change inside componentDidMount
image

Has anyone else run into this? Can we get the state changes before the first rather and avoid a nested update?

Types of disableHeight and disableWidth are incorrect

I believe the types of the disableHeight and disableWidth props are incorrectly set to false here etc - when they should actually be boolean.

It leads to TypeScript errors like in the screenshot when trying to use them:

image

It looks like this was introduced in 1.0.18 if that helps.

Thanks!

AutoSizer cannot be used as a JSX component typescript error

Hi,

from version 1.0.10 and up I ended up having the following typescript error when using the AutoSizer component:

error TS2786: 'AutoSizer' cannot be used as a JSX component.
  Its instance type 'AutoSizer' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
        Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.

package.json context:

"@types/react": "17.0.2",
"@types/react-dom": "17.0.2",
"react": "17.0.2",
"react-dom": "17.0.2",

no additional types are included.

Doesn't execute function, throws errors if pixel sizes are used

I tried out this stand-alone version, but it did not work at all:

  • the function inside the <AutoSizer> component isn't invoked at all
  • if the surrounding element (or its CSS) has a pixels height (e.g. height: 400px;), the component throws an error

The version included in the full package works flawlessly.

Is it possible to test AutoSizer-powered components in unit tests?

I know, I know, this has been asked and answered before, but I'm finding that all the answers I've uncovered are several years old and are unsatisfactory. Using the last comment of this issue as a reference:

You can pass in an explicit width/height props (for testing only) ...

I would argue this is philosophically a bad approach, for several reasons:

  1. It leads to "props creep" (API gets more complex)
  2. It makes the component more complicated
  3. It gives users a false illusion that they can set static height/width values, when this isn't actually intended

Basically, the component is being tainted to accommodate unit test shortcomings, which feels like a perversion of the intent of the code.

... and use those as the defaultHeight and defaultWidth for AutoSizer when present

Even if you don't agree with the philosophy above, and plow ahead anyway, you'll find that this doesn't work. Here's a snippet of my component:

    <AutoSizer defaultWidth={500} style={{ height: '100%', position: 'relative', width: '100%' }}>
      {({ height, width }) => {
        console.log('🚀 ~ file: Chart.tsx:97 ~ width:', width);

Here's what I see when I run my test:

🚀 ~ file: Chart.tsx:97 ~ width: NaN
🚀 ~ file: Chart.tsx:97 ~ width: NaN

NaN is considered defined, so the default isn't used.

Or you can mock out the portion of the browser API that AutoSizer users to measure itself

This also doesn't work. If you try it, you get this:

TypeError: Cannot assign to read only property 'offsetHeight' of object '[object Object]'

I've also heard the argument of "AutoSizer isn't meant to be tested, so refactor your components accordingly" and sure, we could, but again, this feels like a maintenance burden brought on by testing shortcomings. The better approach is to mock at the test level and leave the components alone.

Looking at everything from a 10,000-foot view, isn't the real issue here that AutoSizer is passing NaN? That behavior seems extremely undesirable (what caller would actually want that?), so why not just fix it inside AutoSizer? Treat NaN like undefined (so that the defaults get used) and all these problems go away.

parentNode dimensions defining bug

I'm a little confused, but as i see offsetHeight/offsetWidth of parentNode always returns rounded values.In my case i'm getting 233 instead of 232.5 of parent height and as a result grid horizontal scroll is overlapping the parent node.I have tested it with getBoundingClientRect and got correct dimensions of parentNode.Could you fix that?

code example:
const height = this._parentNode.getBoundingClientRect().height || 0;
const width = this._parentNode.getBoundingClientRect().width || 0;

Uncaught TypeError: children is not a function

Hello,
I'm facing with exception:
Unhandled Rejection (TypeError): children is not a function
which happens in
AutoSizer.render: node_modules/react-virtualized-auto-sizer/dist/index.esm.js:387

Here is stack strace:

Uncaught (in promise) TypeError: children is not a function
    at AutoSizer.render (umi.js:210668)
    at finishClassComponent (umi.js:197340)
    at updateClassComponent (umi.js:197293)
    at beginWork$1 (umi.js:199041)
    at HTMLUnknownElement.callCallback (umi.js:179295)
    at Object.invokeGuardedCallbackDev (umi.js:179344)
    at invokeGuardedCallback (umi.js:179399)
    at beginWork$$1 (umi.js:204663)
    at performUnitOfWork (umi.js:203571)
    at workLoopSync (umi.js:203547)
    at performSyncWorkOnRoot (umi.js:203115)
    at umi.js:191171
    at unstable_runWithPriority (umi.js:231847)
    at runWithPriority$2 (umi.js:191121)
    at flushSyncCallbackQueueImpl (umi.js:191166)
    at flushSyncCallbackQueue (umi.js:191154)
    at scheduleUpdateOnFiber (umi.js:202534)
    at scheduleRootUpdate (umi.js:205878)
    at updateContainerAtExpirationTime (umi.js:205906)
    at updateContainer (umi.js:206008)
    at legacyRenderSubtreeIntoContainer (umi.js:206612)
    at Object.render (umi.js:206689)
    at _callee$ (umi.js:273500)
    at tryCatch (umi.js:228678)
    at Generator.invoke [as _invoke] (umi.js:228904)
    at Generator.prototype.<computed> [as next] (umi.js:228730)
    at asyncGeneratorStep (umi.js:95087)
    at _next (umi.js:95109)
    at umi.js:95116
    at new Promise (<anonymous>)
    at umi.js:95105
    at clientRender (umi.js:273511)
    at umi.js:273608
    at hotApply (umi.js:635)
    at umi.js:314

Here is my code that generates this exception:

import React from 'react';
import AutoSizer, { Size } from 'react-virtualized-auto-sizer';
import { connect } from 'dva';
import { CellMeasurerCache } from 'react-virtualized';
import { FixedSizeGrid, GridChildComponentProps } from 'react-window';
import { ConnectState } from '@/models/connect';
import BatteryView from '@/components/BatteryView';
import { Battery } from '@/types/battery';
import BatteryPreviewDrawer from '@/components/BatteryPreviewDrawer';

interface BatteriesComponentProps {
  batteries: Battery[];
}

interface BatteriesComponentState {
  columnWidth: number;
  rowHeight: number;
  gutterSize: number;
  columnCount: number;
}

class Batteries extends React.PureComponent<BatteriesComponentProps, BatteriesComponentState> {
  gridWidth: number = 0;

  cache: CellMeasurerCache = new CellMeasurerCache({
    defaultHeight: 300,
    defaultWidth: 300,
    fixedWidth: true,
  });

  state: BatteriesComponentState = {
    columnWidth: 300,
    rowHeight: 300,
    gutterSize: 10,
    columnCount: 0,
  };

  private onResize = ({ width }: Size) => {
    this.gridWidth = width;
    this.calculateColumnCount();
  };

  private calculateColumnCount = () => {
    const { columnWidth, gutterSize } = this.state;
    const columnCount = Math.floor(this.gridWidth / (columnWidth + gutterSize));
    console.log(`columnCount: ${columnCount}`);
    this.setState({ columnCount });
  };

  private renderGrid = ({ width, height }: Size) => {
    this.gridWidth = width;
    const { columnWidth, rowHeight, columnCount } = this.state;

    console.log(`render grid of dimensions ${width}x${height}`);
    const { batteries } = this.props;
    const rowCount = Math.ceil(batteries.length / columnCount);
    const getBattery = (columnIndex: number, rowIndex: number) =>
      batteries[(rowIndex * columnCount + columnIndex) % batteries.length];
    return (
      <div>
        <FixedSizeGrid
          columnCount={columnCount}
          columnWidth={columnWidth}
          width={width}
          height={height}
          rowCount={rowCount}
          rowHeight={rowHeight}
        >
          {({ columnIndex, rowIndex, style }: GridChildComponentProps) => (
            <div style={{ ...style }}>
              <BatteryView
                height={rowHeight}
                width={columnWidth}
                battery={getBattery(columnIndex, rowIndex)}
              />
            </div>
          )}
        </FixedSizeGrid>
        <BatteryPreviewDrawer />
      </div>
    );
  };

  public render() {
    return <AutoSizer onResize={this.onResize}>{this.renderGrid}</AutoSizer>;
  }
}

export default connect(({ batteries: { batteries } }: ConnectState) => ({ batteries }))(Batteries);

And the worst thing about it is that it was working before, and it seems that I didn't change anything in this file (that's what git says)

AutoSizer not rendering initially with consistent height for fixed height components

Hi,

I have a case where AutoSizer only manages the width of the child component. It's similar to the example given in the FAQ:

<AutoSizer disableHeight> {({width}) => <Component height={200} width={width} {...props} />} </AutoSizer>

However, I’ve noticed that AutoSizer skips rendering the child component on its initial render since the width it initially calculates is zero. Since I’m specifying a fixed height for the child component, I would like for it to take up the height I specified even on the initial render.

In my specific case, I am trying to render a virtualized list of items, where the item uses AutoSizer when it is in view, but uses a different component when it is not. When I try to scroll up from the bottom of the list, the list sometimes doesn't scroll properly. This seems to be because the height of items being scrolled into view changes between the initial and subsequent render.

CodeSandbox Link

I was wondering if the AutoSizer implementation could be changed so that the child component should be rendered whenever the client fixes one of the dimensions (ie either disableWidth or disableHeight is true), regardless of whether the other dimension controlled by AutoSizer is zero or not?

(If not, I could work around it by passing a non-zero value for defaultWidth so the initial render isn't skipped. Just wanted to bring this issue up in case this is something that should be fixed.)

Testing Component using AutoSizer

In your tests (@bvaughn), I see that you are mocking the OffsetSize and adding _mountNode to the document.body.

If I want to test a component that's using the AutoSizer, how can I do this without exposing the implementation details of the component?

PS: I'm using jest and enzyme

1.0.19 does not render anything

Hi!

We use your lib in our React app. We updated from 1.0.17 to 1.0.20. Our build stack includes:

  • Typescript
  • Esbuild
  • Webpack
  • Turborepo

1.0.19 only renders an empty div. No errors.

before
after

"react-virtualized-auto-sizer 新版本重复渲染子组件,和 antd tabs 冲突

我之前用的是"react-virtualized-auto-sizer": "1.0.7"版本,
最近更新的比较快。发布时候找到最新的版本,结果 antd tabs有冲突, tab1 和 tab2 切换会重新渲染组件。
起初我以为是antd 问题。 锁板还能复现。
最后排查react-virtualized-auto-sizer 这个东西 会重新更新内容, antd tabs 都缓存不了展示过的内容。
这对性能来说是一个很严重的问题。
image

API change in return type

Hello, I've just moved to the latest version and I can't compile in typescript due the changes to the children function.

Previous typings used ReactNode and it seems this has changed to ReactElement. This means I can't return null anymore.

Was this intentional? Our use case if the the space is less than a set breakpoint we hide the element.

Thanks!

children: (size: Size) => ReactElement;

`Module parse failed: Unexpected token` error

Upgrading to 1.0.12 causes a build error due to nullish coalescing operator ?? introduced in ccb88dd#diff-89386aae2ac82c8ec4a0d1367a57061c8abc02b01921b7db3bc139959a5778b7R187-R190

ERROR in /app/node_modules/react-base-table/node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.module.js 236:56
Module parse failed: Unexpected token (236:56)
File was processed with these loaders:
 * ../../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|         // See issue #150 for more context.
|         const style = window.getComputedStyle(this._parentNode) || {};
>         const paddingLeft = parseInt(style.paddingLeft ?? "0", 10);
|         const paddingRight = parseInt(style.paddingRight ?? "0", 10);
|         const paddingTop = parseInt(style.paddingTop ?? "0", 10);
 @ /app/node_modules/react-base-table/es/AutoResizer.js 3:0-53 29:29-38
 @ /app/node_modules/react-base-table/es/index.js
 @ ./src/components/Table.tsx
...
 @ multi /app/node_modules/@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js /app/node_modules/react-dev-utils/webpackHotDevClient.js ./src/index.tsx

Should it be transpiled when building this library?

Thanks

TypeScript: Incorrect typing of AutoSize height and width

I am upgrading an old library from react-virtualized and it was doing this.

<AutoSizer
          disableHeight={this.props.height !== "auto"}
          disableWidth={this.props.width !== "auto"}
        >
          {({ height, width }) => (

When upgrading to this library its now saying height and width are not valid because my props are defaulted to auto but allow the user to change.

image

Missing class properties transform

I Guess there is a problem with 1.0.9, this is the error i get when building a project.
react-virtualized is installed as dependencie to react-map-gl

Failed to compile.

./node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.module.js
SyntaxError: /tmp/cirrusdev/node_modules/react-virtualized-auto-sizer/dist/react-virtualized-auto-sizer.module.js: Missing class properties transform.
  199 |
  200 | class $6e2bb92d9db3b0c8$export$9d94f4ee1d930ff extends (0, $hgUW1$Component) {
> 201 |     static defaultProps = {
      |     ^
  202 |         onResize: ()=>{},
  203 |         disableHeight: false,
  204 |         disableWidth: false,


error Command failed with exit code 1.

Best
Ben

Element type is invalid Check the render method of `AutoSizer`.

The code is here, but I just report an error , Did I make a mistake? Can you tell me
代码如下,就是会报错:

Element type is invalid ,

image

import React from 'react';
import { DynamicSizeList as List } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';

const Row = ({ data, index, style }) => (
  <div className={index % 2 ? 'ListItemOdd' : 'ListItemEven'} style={style}>
    {index}
  </div>
);

class App extends React.PureComponent{
     render(){
       return (
          <AutoSizer>
             {({ width, height }) => (
              <List
                width={width}
                height={height}
                className="msgList"
                itemCount={20}
              >
                {Row}
              </List>
            )}
          </AutoSizer>
)
}
}

export default App;

The container's width (or the resize event) does not update if the parent has a scaling animation

The container width can only be obtained from parent's initial width. If the container is resized using CSS transform scale, the resize event is not be triggered (which may be the expected behavior), resulting in the width not being updated accordingly
However, the AutoSizer component of react-virtualized seems to work well in this scenario ( tested with react-base-table which uses react-virtualized )
It is possible that listening to the transitionend_event event may help to address this issue ?

'AutoSizer' cannot be used as a JSX component.

How can I fix this error please??

"'AutoSizer' cannot be used as a JSX component.
Its instance type 'AutoSizer' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'ReactElement<any, string | JSXElementConstructor>' is not assignable to type 'ReactNode'.
Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor>' but required in type 'ReactPortal'.ts(2786"

It seems to be a minor issue but I cant get my head around it

Here is my component

'use client'

import React, { CSSProperties, FC, ReactElement, useCallback } from 'react'
import AutoSizer from 'react-virtualized-auto-sizer'
import { FixedSizeList } from 'react-window'

type RowCallback = (row: { index: number; style: CSSProperties }) => ReactElement

export interface ListProps {
className?: string
rowHeight?: number
rowRenderer: FC
rowData: TData[]
}

export type ListComponent = (props: ListProps) => React.ReactElement | null

export function List({ className, rowHeight, rowData, rowRenderer: RowComponent }: ListProps) {
const Row = useCallback<RowCallback>(
({ index, style }) => {
return <RowComponent style={style} {...rowData[index]} />
},
[RowComponent, rowData]
)

return (

{({ height }: { height: number }) => (
<FixedSizeList
width="100%"
height={height}
itemCount={rowData.length}
itemSize={rowHeight || 48}
className={className}
style={{ overflow: 'overlay' }}
>
{Row}

)}

)
}

ResizeObserver loop limit exceeded

After updating from 1.0.11 to 1.0.12 the following code
window.addEventListener("error", (e) => {...} started to receive the error ResizeObserver loop limit exceeded continuously.

That happens in chromium-based browsers only

"Can't perform a React state update on an unmounted component" console error

After replacing the AutoSizer component in react-virtualized with the AutoSizer from this library, I started seeing some "Can't perform a React state update on an unmounted component" console errors originating from the component. Specifically, the error seems to be pointing to the line scaledWidth: this.props.defaultWidth || 0, in the state initialization.

This error occurs most frequently when navigating to a different page (the autosized component is unmounted) during a resize operation. I tried recreating this scenario in a code-sandbox, but was unable to reproduce the issue.

Version: 1.0.17

Reporting an integer size when the available space has decimals

Sometimes Chrome reports a height that has decimals, but autosizer will return the next integer number, therefore resulting in more space than what's available on screen. At the moment I'm solving it by always removing one to the result returned by autosize, but if I could get the height as reported by Chrome with the decimals, the problem would be solved even if it's passed as pixels to CSS.

Access the component height from outside the component to pass to itemSize

Hi ya @bvaughn ,
I am using the react-window and the react-virtualized auto sizer.. and I have a virtual book that I display and each paragraph is a component.

the paragraphs are variable heights.. of course that changes based on the width of the page etc etc.

using the ref I can get the height and set that within the function.. or even use react -use-measure... but the challenge exposing that height outside the component to use that to get set the height in the auto-sizer itemSize

Any ideas on how to export a components height outside the component so I can pass it to the autosized? Hope this makes sense.

might even be interesting to make this a built in thing that the auto0sizer can work with flex components

Recurrence of old Resizer bug (Width/Height NaN for AutoSizer #150)

Been seeing an error periodically when running some tests on our webpage via Cypress:

`NaN` is an invalid value for the `width` css style property

I don't currently have a consistent reproduction case - error only happens when running in the test environment.

I traced the error down to this library, and specifically https://github.com/bvaughn/react-virtualized-auto-sizer/blob/master/src/AutoSizer.ts#L155-L185, and noticed the comment there referencing an old issue on react-virtualized (bvaughn/react-virtualized#150). It looks like the checks added in bvaughn/react-virtualized@33bdde8 were modified at some point to use null-coalescing, which no longer handles empty string values.

I'll note we're still running on React 17 and Cypress 10.

Allow changing the innerElementType

I am using this amazing library with react-window to create a virtualized table component. One issue I am facing as of now is the validateDomNesting warning I get because of the AutoSizer.

Basically, I am experimenting a feature to allow custom element types for the windowed table. And passing element types like p or tr causes warnings from React since the AutoSizer always renders div tags.

Would it be possible to allow changing the innerElementType of the Autosizer components(similar to how it is being done for components like FixedSizeList)?

Thank you very much.

AutoSizer not triggering updates when inside a FlatList

I'm using react-native-web and when the AutoSizer is inside the FlatList it stops working.

I made a small repro demo: https://codesandbox.io/s/issue-react-native-for-web-i8vgg

Is this a bug or desired behavior?
@bvaughn Please let me know what could be causing this. Investigated for hours but no success.

When inspecting the elements, all parents dimensions seems to be correct, with full height.
The resize-triggers div also has the correct dimensions, but AutoSizer state doesn't.

Kapture 2019-08-23 at 21 18 06

AutoSizer height and width changed from type `number` to `number | undefined` in 1.0.8

I'm using react-virtualized-auto-sizer along with react-window and there was a breaking change in 1.0.8: the height and width values provided by AutoSizer are now number | undefined and can't be passed down directly to FixedSizeList from react-window. The react-window list components expect number | string and won't allow undefined.

Here's a codesandbox showing the issue, you can change the installed version between 1.0.7 and 1.0.8 to see the difference:
https://codesandbox.io/s/weathered-silence-op15io?file=/src/App.tsx

I can default the values to 0 if AutoSizer gives me undefined and it seems to work, is this the recommended solution? It would be ideal if the AutoSizer values matched the list props from react-window but it would be helpful to know the right thing to do if AutoSizer gives an undefined width or height.

Thanks!

Types issues with onResize

We've just upgraded to version 1.0.9 and I've noticed that there is an issue with the types of onResize.

The parameter passed to the function is of type React.SyntheticEvent<HTMLDivElement, Event> | Size, which means that you cannot access the properties width and height directly as they don't exist on the SyntheticEvent.

To silence the Typescript error, we either needs to

  • Add a @ts-ignore
  • Cast the parameter like this (param as { width: number; height: number}).width)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.