Skip to content

Commit

Permalink
Fix Grid ssr with maxElementSize util (#970)
Browse files Browse the repository at this point in the history
Fix Grid ssr with maxElementSize util
  • Loading branch information
TrySound committed Jan 16, 2018
1 parent d842fb6 commit 50a5177
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"start": "webpack-dev-server --hot --config webpack.config.dev.js",
"test": "npm run test:jest",
"test:jest": "jest --no-watchman --runInBand",
"test:ci": "cross-env JEST=ci jest --testPathPattern=jest.js --no-watchman --maxWorkers 2 --coverage && codecov",
"test:ci": "cross-env JEST=ci jest --testPathPattern=\".(jest|ssr).js\" --no-watchman --maxWorkers 2 --coverage && codecov",
"watch": "watch 'clear && npm run test -s' source",
"watch:jest": "jest --no-watchman --watch"
},
Expand Down
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 50a5177

Please sign in to comment.