Skip to content

Commit

Permalink
fix: should serialize subscription fn key
Browse files Browse the repository at this point in the history
  • Loading branch information
promer94 committed Jul 13, 2023
1 parent 2efed28 commit 5f6a735
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions _internal/src/utils/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { stableHash } from './hash'
import { isFunction } from './shared'

import type { Key } from '../types'
import type { Key, Arguments } from '../types'

export const serialize = (key: Key): [string, Key] => {
export const serialize = (key: Key): [string, Arguments] => {
if (isFunction(key)) {
try {
key = key()
Expand Down
4 changes: 2 additions & 2 deletions subscription/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const subscription = (<Data = any, Error = any>(useSWRNext: SWRHook) =>
subscribe: SWRSubscription<any, Data, Error>,
config: SWRConfiguration & typeof SWRConfig.defaultValue
): SWRSubscriptionResponse<Data, Error> => {
const [key] = serialize(_key)
const originKey = _key
const [key, args] = serialize(_key)
const originKey = args

// Prefix the key to avoid conflicts with other SWR resources.
const subscriptionKey = key ? SUBSCRIPTION_PREFIX + key : undefined
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-subscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('useSWRSubscription', () => {
}

function Page() {
const { data, error } = useSWRSubscription([swrKey], subscribe, {
const { data, error } = useSWRSubscription(() => [swrKey], subscribe, {
fallbackData: 'fallback'
})
return (
Expand Down

0 comments on commit 5f6a735

Please sign in to comment.