diff --git a/core/package.json b/core/package.json index 2c8982424..e706c484e 100644 --- a/core/package.json +++ b/core/package.json @@ -17,6 +17,7 @@ "clean": "rimraf dist" }, "peerDependencies": { + "client-only": "*", "swr": "*", "react": "*", "use-sync-external-store": "*" diff --git a/core/src/env.d.ts b/core/src/env.d.ts new file mode 100644 index 000000000..6aec8a9b9 --- /dev/null +++ b/core/src/env.d.ts @@ -0,0 +1 @@ +declare module 'client-only' diff --git a/core/src/index.ts b/core/src/index.ts index 40a2c772c..d7fc5c387 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -1,4 +1,4 @@ -'use client' +import 'client-only' // useSWR import useSWR from './use-swr' diff --git a/immutable/src/index.ts b/immutable/src/index.ts index 64da6ac71..d39e8d6ba 100644 --- a/immutable/src/index.ts +++ b/immutable/src/index.ts @@ -1,5 +1,3 @@ -'use client' - import type { Middleware } from 'swr' import useSWR from 'swr' import { withMiddleware } from 'swr/_internal' diff --git a/infinite/src/index.ts b/infinite/src/index.ts index 033f6399f..dfc76df81 100644 --- a/infinite/src/index.ts +++ b/infinite/src/index.ts @@ -1,5 +1,3 @@ -'use client' - // We have to several type castings here because `useSWRInfinite` is a special // hook where `key` and return type are not like the normal `useSWR` types. diff --git a/mutation/src/index.ts b/mutation/src/index.ts index 5e6040528..16637386f 100644 --- a/mutation/src/index.ts +++ b/mutation/src/index.ts @@ -1,5 +1,3 @@ -'use client' - import { useCallback, useRef } from 'react' import useSWR, { useSWRConfig } from 'swr' import type { Middleware, Key } from 'swr/_internal' diff --git a/package.json b/package.json index fcfbd8af4..f8527d5d0 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,7 @@ "trailingComma": "none" }, "dependencies": { + "client-only": "^0.0.1", "use-sync-external-store": "^1.2.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 942bc131f..f6963d8ed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ importers: .: dependencies: + client-only: + specifier: ^0.0.1 + version: 0.0.1 use-sync-external-store: specifier: ^1.2.0 version: 1.2.0(react@18.2.0) @@ -2131,7 +2134,6 @@ packages: /client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} - dev: true /cliui@7.0.4: resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} diff --git a/subscription/src/index.ts b/subscription/src/index.ts index 85bca31f7..b01552c9a 100644 --- a/subscription/src/index.ts +++ b/subscription/src/index.ts @@ -1,5 +1,3 @@ -'use client' - import type { Key, SWRHook, Middleware, SWRConfiguration, SWRConfig } from 'swr' import type { SWRSubscriptionOptions,