diff --git a/__tests__/ssr.test.js b/__tests__/ssr.test.js new file mode 100644 index 00000000..8d4cbe87 --- /dev/null +++ b/__tests__/ssr.test.js @@ -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(); + }); +}); diff --git a/lib/propTypes.js b/lib/propTypes.js index a1185e47..d38c2a6d 100644 --- a/lib/propTypes.js +++ b/lib/propTypes.js @@ -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,