trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

Realtime internal `useSWR` hooks can inadvertently use global SWRConfig fetcher and cause issues

Open ericallam opened this issue 6 months ago • 1 comments

We need to look into how to prevent global SWRConfig fetchers be invoked by our useSWR hooks: https://swr.vercel.app/docs/global-configuration

ericallam avatar Jul 02 '25 13:07 ericallam

Running into this in our app when using the useRealtimeRunsWithTag. We use a global SWRConfig to add custom fetch caching, tracking, error utilities etc.

Not really sure why this is happening though because looking into the code for useRealtimeRunsWithTag, useSWR is being passed a null fetcher. I guess it falls back to the global fetcher when the provided fetcher is null

EDIT

~Getting around this for now by modifying the global fetcher to check if the resource being requested is a "string", and returning null if it isn't... though that's not really a robust solution and might not work for everyone. Maybe providing a noop function might work?~

Having the global fetcher return null was just overriding the mutated data to null any time the trigger.dev hooks updated their data. That's unfortunately NOT a solution (dunno why I didn't realize that earlier).

If you are going to continue to use useSWR for caching, then the fetchers need to be updated, probably to return data from the cache itself, or to something else.

pkabra avatar Aug 21 '25 22:08 pkabra