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

Fix Grid ssr with maxElementSize util #970

Merged
merged 2 commits into from
Jan 16, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
};