From 23668220b38cba59fc0b8de377ca8ca6f72974b9 Mon Sep 17 00:00:00 2001 From: MateoKruk Date: Mon, 5 Aug 2024 17:38:48 -0300 Subject: [PATCH] fix: useSyncExternalStore backward compatibility --- cmdk/package.json | 3 ++- cmdk/src/index.tsx | 3 ++- pnpm-lock.yaml | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmdk/package.json b/cmdk/package.json index b88cf69..408af70 100644 --- a/cmdk/package.json +++ b/cmdk/package.json @@ -28,7 +28,8 @@ "dependencies": { "@radix-ui/react-dialog": "^1.1.1", "@radix-ui/react-id": "^1.0.1", - "@radix-ui/react-primitive": "^2.0.0" + "@radix-ui/react-primitive": "^2.0.0", + "use-sync-external-store": "^1.2.2" }, "devDependencies": { "@types/react": "18.0.15" diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index 1547b27..6f4c9e0 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -3,6 +3,7 @@ import * as React from 'react' import { commandScore } from './command-score' import { Primitive } from '@radix-ui/react-primitive' import { useId } from '@radix-ui/react-id' +import { useSyncExternalStore } from 'use-sync-external-store' type Children = { children?: React.ReactNode } type DivProps = React.ComponentPropsWithoutRef @@ -1013,7 +1014,7 @@ function mergeRefs(refs: Array | React.Legacy function useCmdk(selector: (state: State) => T) { const store = useStore() const cb = () => selector(store.snapshot()) - return React.useSyncExternalStore(store.subscribe, cb, cb) + return useSyncExternalStore(store.subscribe, cb, cb) } function useValue( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc127ee..277f950 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: react-dom: specifier: ^18.0.0 version: 18.2.0(react@18.2.0) + use-sync-external-store: + specifier: ^1.2.2 + version: 1.2.2(react@18.2.0) devDependencies: '@types/react': specifier: 18.0.15 @@ -4349,6 +4352,14 @@ packages: tslib: 2.6.2 dev: false + /use-sync-external-store@1.2.2(react@18.2.0): + resolution: {integrity: sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + react: 18.2.0 + dev: false + /v8-compile-cache@2.3.0: resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==} dev: true