{"record":{"id":"83545d5426b6f710","repo":"vercel/swr","slug":"the-subscribe-function-must-return-a-function-to","errorCode":null,"errorMessage":"The `subscribe` function must return a function to unsubscribe.","messagePattern":"The `subscribe` function must return a function to unsubscribe\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/subscription/index.ts","lineNumber":77,"sourceCode":"      const next: SWRSubscriptionOptions<Data, Error>['next'] = (\n        error,\n        data\n      ) => {\n        if (error !== null && typeof error !== 'undefined') {\n          set({ error })\n        } else {\n          set({ error: undefined })\n          swr.mutate(data, false)\n        }\n      }\n\n      // Increment the ref count.\n      subscriptions.set(subscriptionKey, refCount + 1)\n\n      if (!refCount) {\n        const dispose = subscribe(args, { next })\n        if (typeof dispose !== 'function') {\n          throw new Error(\n            'The `subscribe` function must return a function to unsubscribe.'\n          )\n        }\n        disposers.set(subscriptionKey, dispose)\n      }\n\n      return () => {\n        const count = subscriptions.get(subscriptionKey)! - 1\n\n        subscriptions.set(subscriptionKey, count)\n\n        // Dispose if it's the last one.\n        if (!count) {\n          const dispose = disposers.get(subscriptionKey)\n          dispose?.()\n\n          // Remove both entries, so the internal states only retain the\n          // subscription keys that currently have active subscribers.","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/vercel/swr/blob/7173e55b2a175dee455612c5fa067383345c392f/src/subscription/index.ts#L59-L95","documentation":"Error \"The `subscribe` function must return a function to unsubscribe.\" thrown in vercel/swr.","triggerScenarios":"Thrown at src/subscription/index.ts:77 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7173e55b2a175dee455612c5fa067383345c392f","analyzedAt":"2026-08-27T20:47:56.280Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}