Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem recap
SWR lets applications supply a global
fetcher
via<SWRConfig value={{ fetcher }}>
.Our realtime hooks (
useRealtime*
) were callinguseSWR(key, null)
which:fetcher
when one exists.If an app wrapped in an
SWRConfig
defines a global fetcher, every realtime-subscription hook triggered an unexpected HTTP request before the firstmutate
, causing race-conditions and 404/500 noise.Root-cause analysis (considered sources)
null
) still inherit the global fetcher.trigger-swr.ts
share the same SWR context as the host app.mutate
s.Most-likely issues: (1) & (2).
Fix strategy
Give every internal realtime call its own inert fetcher so the global one is never consulted.
Code changes (all in
packages/react-hooks/src/hooks/useRealtime.ts
)• For every
useSWR
/useSWRMutation
that is meant to be “write-only”:– keep the
null
second argument (still disables local revalidation)– add a third-argument config
{ fetcher: () => undefined as any }
– when a config object already existed (
fallbackData
), extend it.This guarantees:
• Type-safe: the dummy fetcher satisfies
BareFetcher<T>
while returning nothing.• Behaviour-safe: the function is never executed (because revalidation is disabled) but it blocks inheritance of the global fetcher.
All lints now pass.
Next steps / validation
useRealtime*
hook.→ You should see zero outbound requests until the first
mutate
we perform internally.If you still notice stray requests, enable logging in SWR by adding
inside the config we just added to verify that our dummy fetcher is never executed.
That should permanently decouple the Trigger.dev realtime hooks from any global SWR fetcher the host application defines.