Skip to content

Commit

Permalink
Fix Grid ssr with maxElementSize util
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jan 16, 2018
1 parent d842fb6 commit 5b810c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
33 changes: 33 additions & 0 deletions source/Grid/Grid.ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @flow
* @jest-environment node
*/

import React from 'react';
import ReactDOMServer from 'react-dom/server';
import Grid from './Grid';

declare var test: any;
declare var expect: any;

test('should render Grid with dom server', () => {
const rendered = ReactDOMServer.renderToString(
<Grid
cellRenderer={({style, key, rowIndex, columnIndex}) => (
<div style={style} key={key}>
{rowIndex + ':' + columnIndex}
</div>
)}
columnCount={1000}
columnWidth={20}
height={500}
rowCount={1000}
rowHeight={20}
width={500}
/>,
);

expect(rendered).toContain('0:0');
expect(rendered).toContain('24:24');
expect(rendered).not.toContain('25:25');
});
9 changes: 6 additions & 3 deletions source/Grid/utils/maxElementSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
const DEFAULT_MAX_ELEMENT_SIZE = 1500000;
const CHROME_MAX_ELEMENT_SIZE = 1.67771e7;

const isBrowser = () => typeof window !== 'undefined';

const isChrome = () => !!window.chrome && !!window.chrome.webstore;

export const getMaxElementSize = (): number => {
if (isChrome()) {
return CHROME_MAX_ELEMENT_SIZE;
if (isBrowser()) {
if (isChrome()) {
return CHROME_MAX_ELEMENT_SIZE;
}
}

return DEFAULT_MAX_ELEMENT_SIZE;
};

0 comments on commit 5b810c6

Please sign in to comment.