diff --git a/.changeset/media-react-hook-form-v8.md b/.changeset/media-react-hook-form-v8.md new file mode 100644 index 0000000000..046284d7ff --- /dev/null +++ b/.changeset/media-react-hook-form-v8.md @@ -0,0 +1,5 @@ +--- +"sanity-plugin-media": patch +--- + +Update react-hook-form to v8 (8.0.0-beta.3), which has first-class React Compiler support, and re-enable React Compiler for the asset details form. Dialog footers (and the confirm dialog header) are no longer declared as inline components, so they no longer remount whenever form state changes. diff --git a/plugins/sanity-plugin-media/README.md b/plugins/sanity-plugin-media/README.md index 51502b870b..989ed752f4 100644 --- a/plugins/sanity-plugin-media/README.md +++ b/plugins/sanity-plugin-media/README.md @@ -60,6 +60,19 @@ or yarn add sanity-plugin-media ``` +### Peer dependency warnings + +The plugin uses [`react-hook-form`](https://react-hook-form.com/) v8 together with [`@hookform/resolvers`](https://www.npmjs.com/package/@hookform/resolvers), which doesn't declare react-hook-form v8 in its peer dependencies yet (it declares `react-hook-form ^7.55.0`), even though the resolver contract is unchanged and works fine with v8. Until a v8-compatible release is published, tell your package manager to allow it: + +- `npm`: install with the `--legacy-peer-deps` flag +- `pnpm`: set [`peerDependencyRules.allowedVersions`](https://pnpm.io/settings#peerdependencyrulesallowedversions) in `pnpm-workspace.yaml`: + + ```yaml + peerDependencyRules: + allowedVersions: + '@hookform/resolvers>react-hook-form': '8.0.0-beta.3' + ``` + ## Usage Add it as a plugin in your `sanity.config.ts` (or .js) file: diff --git a/plugins/sanity-plugin-media/package.json b/plugins/sanity-plugin-media/package.json index 1053dcbcee..8e7797aa87 100644 --- a/plugins/sanity-plugin-media/package.json +++ b/plugins/sanity-plugin-media/package.json @@ -60,7 +60,7 @@ "pluralize": "^8.0.0", "react-dropzone": "^11.7.1", "react-file-icon": "^1.6.0", - "react-hook-form": "catalog:", + "react-hook-form": "catalog:react-hook-form-v8", "react-redux": "^9.3.0", "react-select": "^5.10.2", "react-virtuoso": "^4.18.11", diff --git a/plugins/sanity-plugin-media/src/components/DialogAssetEdit/Details.tsx b/plugins/sanity-plugin-media/src/components/DialogAssetEdit/Details.tsx index 3c0fb19d9b..4a12503666 100644 --- a/plugins/sanity-plugin-media/src/components/DialogAssetEdit/Details.tsx +++ b/plugins/sanity-plugin-media/src/components/DialogAssetEdit/Details.tsx @@ -64,11 +64,6 @@ export default function Details({ creditLine, locales, }: DetailsProps) { - 'use no memo' - // React Compiler memoizes the register() field JSX using asset-derived deps only. - // That can leave Save stuck disabled while the DOM still updates (uncontrolled inputs). - // Tags work because they use Controller; string fields use register and need this opt-out. - const hasLocales = locales && locales.length > 0 const [activeLocaleTab, setActiveLocaleTab] = useState(0) const folderId = currentAsset?.opt?.media?.folder?._ref diff --git a/plugins/sanity-plugin-media/src/components/DialogConfirm/index.tsx b/plugins/sanity-plugin-media/src/components/DialogConfirm/index.tsx index c600a6b7a3..5b0dfcfe54 100644 --- a/plugins/sanity-plugin-media/src/components/DialogConfirm/index.tsx +++ b/plugins/sanity-plugin-media/src/components/DialogConfirm/index.tsx @@ -37,7 +37,7 @@ const DialogConfirm = (props: Props) => { handleClose() } - const Footer = () => ( + const footer = (