fix: prevent infinite loop when onSuccess is explicitly undefined#4231
Open
MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
Open
fix: prevent infinite loop when onSuccess is explicitly undefined#4231MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
Conversation
When a user passes `{ onSuccess: undefined }` (e.g. from an optional
callback in a custom hook wrapper), the spread merge in mergeConfigs
overwrites the default `noop` callback with `undefined`. This causes a
TypeError when the successful fetch tries to call `config.onSuccess()`,
which is caught by the error handler, triggering an error retry, which
succeeds again and throws again -- creating an infinite request loop.
Strip undefined values from user config before merging so they don't
override defaults.
Fixes vercel#4218
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #4218
When
onSuccess: undefinedis explicitly passed in the options (a common pattern when wrappinguseSWRin a custom hook with optional callbacks),mergeConfigsspreads the user config over the defaults, which causesonSuccess: undefinedto override the defaultnoopcallback. This results in aTypeErrorwhen the successful fetch attempts to callconfig.onSuccess(). The error is caught by the catch block, which triggersonErrorRetry, which re-fetches successfully, which callsundefined()again — creating an infinite request loop.Fix
Strip
undefinedvalues from the user config object inmergeConfigsbefore spread-merging, so explicitly passingundefinedbehaves the same as omitting the property entirely.Tests
Added 3 test cases:
onSuccess: undefineddoes not cause infinite requestsonError: undefineddoes not cause infinite requestsonSuccessthat isundefinedAll 3 tests fail without the fix and pass with it.
🤖 Generated with Claude Code