From ec3f6d2e36f09bb6d37a8687bb734c10a5e6fa8c Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Thu, 1 Jan 2026 20:06:25 -0500 Subject: [PATCH] fix: support SSR environments where Element is not defined (#251) The `draggableOpts.offsetParent` prop type used `PropTypes.instanceOf(Element)` which throws a ReferenceError in SSR/Node.js environments where the DOM global `Element` doesn't exist. This was introduced in a prior release that added the draggableOpts prop type definitions. The fix checks if Element is defined before using instanceOf. --- __tests__/ssr.test.js | 34 ++++++++++++++++++++++++++++++++++ lib/propTypes.js | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 __tests__/ssr.test.js 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,