Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/ssr.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @jest-environment node
*/
// #251 - Test SSR compatibility where Element is not defined

describe('SSR compatibility', () => {
test('propTypes.js can be imported in Node.js environment without Element global', () => {
// In Node.js environment (jest-environment: node), Element is not defined
expect(typeof Element).toBe('undefined');

// This should not throw ReferenceError: Element is not defined
expect(() => {
require('../lib/propTypes');
}).not.toThrow();
});

test('Resizable.js can be imported in Node.js environment without Element global', () => {
expect(typeof Element).toBe('undefined');

// This should not throw ReferenceError: Element is not defined
expect(() => {
require('../lib/Resizable');
}).not.toThrow();
});

test('ResizableBox.js can be imported in Node.js environment without Element global', () => {
expect(typeof Element).toBe('undefined');

// This should not throw ReferenceError: Element is not defined
expect(() => {
require('../lib/ResizableBox');
}).not.toThrow();
});
});
3 changes: 2 additions & 1 deletion lib/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export const resizableProps: Object = {
children: PropTypes.node,
disabled: PropTypes.bool,
enableUserSelectHack: PropTypes.bool,
offsetParent: PropTypes.instanceOf(Element),
// #251: Check for Element to support SSR environments where DOM globals don't exist
offsetParent: typeof Element !== 'undefined' ? PropTypes.instanceOf(Element) : PropTypes.any,
grid: PropTypes.arrayOf(PropTypes.number),
handle: PropTypes.string,
nodeRef: PropTypes.object,
Expand Down
Loading