From 4b819eca80d1e5fea31424910999ef9099694d97 Mon Sep 17 00:00:00 2001 From: hanxx Date: Wed, 7 Jan 2026 11:37:54 +0800 Subject: [PATCH] fix(react-form): complie error with webpack when react lower than v18 Change-Id: Ia4b18c0cf0d6a2c809923588c567f2cabbd08bde --- .changeset/smooth-teeth-send.md | 5 +++++ packages/react-form/src/useFormId.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/smooth-teeth-send.md diff --git a/.changeset/smooth-teeth-send.md b/.changeset/smooth-teeth-send.md new file mode 100644 index 000000000..51f16beee --- /dev/null +++ b/.changeset/smooth-teeth-send.md @@ -0,0 +1,5 @@ +--- +'@tanstack/react-form': patch +--- + +Fix compile error with webpack when using react v17 diff --git a/packages/react-form/src/useFormId.ts b/packages/react-form/src/useFormId.ts index 4b78db9b9..575478201 100644 --- a/packages/react-form/src/useFormId.ts +++ b/packages/react-form/src/useFormId.ts @@ -1,6 +1,11 @@ import * as React from 'react' import { useUUID } from './useUUID' -/** React 17 does not have the useId hook, so we use a random uuid as a fallback. */ +/** + * React 17 does not have the useId hook, so we use a random uuid as a fallback. + * This is needed to avoid bundlers trying to import non-existing export. + * Read more: https://github.com/webpack/webpack/issues/14814 + */ +const _React = React export const useFormId = - React.version.split('.')[0] === '17' ? useUUID : React.useId + React.version.split('.')[0] === '17' ? useUUID : _React.useId