Skip to content

Commit d080f32

Browse files
committed
Set contentWindow default ourselves to avoid Jest serialization
Jest serializes all props in snapshots. Window is a huge object, so when Jest tries to serialize it, it typically throws `RangeError: Invalid string length` because the process runs out of memory. This switches from using defaultProps to setting the default ourselves, so in the test environment there won't be a prop value to serialize.
1 parent 0095e6e commit d080f32

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/SortableContainer/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
4444
distance: 0,
4545
useWindowAsScrollContainer: false,
4646
hideSortableGhost: true,
47-
contentWindow: typeof window !== 'undefined' ? window : null,
4847
shouldCancelStart: function(e) {
4948
// Cancel sorting if the event target is an `input`, `textarea`, `select` or `option`
5049
const disabledElements = ['input', 'textarea', 'select', 'option', 'button'];
@@ -100,11 +99,17 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
10099

101100
componentDidMount() {
102101
const {
103-
contentWindow,
104102
getContainer,
105103
useWindowAsScrollContainer,
106104
} = this.props;
107105

106+
/*
107+
* Set our own default rather than using defaultProps because Jest
108+
* snapshots will serialize window, causing a RangeError
109+
* https://github.com/clauderic/react-sortable-hoc/issues/249
110+
*/
111+
const contentWindow = this.props.contentWindow || window;
112+
108113
this.container = typeof getContainer === 'function'
109114
? getContainer(this.getWrappedInstance())
110115
: findDOMNode(this);

0 commit comments

Comments
 (0)