Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should serialize subscription fn key #2711

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: should serialize subscription fn key
promer94 committed Jul 13, 2023
commit 5f6a735f7fa3f6435e1c66bbc2ed8fa8cb0eec8b
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()
4 changes: 2 additions & 2 deletions subscription/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/use-swr-subscription.test.tsx
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ describe('useSWRSubscription', () => {
}

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