From a42c5a7423a8ebd5e3b241e40edd643259614203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E5=BB=B7=E5=AE=89?= <73953029+nrps9909@users.noreply.github.com> Date: Fri, 28 Aug 2026 18:09:46 +0800 Subject: [PATCH] fix: guard missing React version export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陳廷安 <73953029+nrps9909@users.noreply.github.com> --- src/ref.ts | 2 +- tests/ref-version.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/ref-version.test.ts diff --git a/src/ref.ts b/src/ref.ts index fd9513b9..9dd8c41d 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -4,7 +4,7 @@ import { ForwardRef, isMemo } from 'react-is'; import useMemo from './hooks/useMemo'; import isFragment from './React/isFragment'; -const ReactMajorVersion = Number(version.split('.')[0]); +const ReactMajorVersion = Number(version?.split('.')[0]); export const fillRef = (ref: React.Ref, node: T) => { if (typeof ref === 'function') { diff --git a/tests/ref-version.test.ts b/tests/ref-version.test.ts new file mode 100644 index 00000000..5c438909 --- /dev/null +++ b/tests/ref-version.test.ts @@ -0,0 +1,10 @@ +jest.mock('react', () => ({ + ...jest.requireActual('react'), + version: undefined, +})); + +describe('ref without a React version export', () => { + it('loads without throwing', () => { + expect(() => jest.requireActual('../src/ref')).not.toThrow(); + }); +});