Skip to content

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Aug 10, 2025

Related change in #4150, the error show not directly throw when key is falsy like disabled mode

Fixes #4155

@huozhi huozhi requested a review from shuding as a code owner August 10, 2025 19:24
Copy link

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.

@huozhi huozhi requested a review from promer94 August 10, 2025 19:25
@promer94 promer94 requested a review from Copilot August 11, 2025 12:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where SWR incorrectly threw a "Fallback data is required when using Suspense in SSR" error even when the key was disabled (falsy), which should not trigger suspense behavior.

  • Moved the hasKeyButNoData calculation earlier in the suspense block
  • Modified the SSR error condition to only throw when there's actually a key but no data
  • Added comprehensive e2e tests to verify the fix works correctly

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/index/use-swr.ts Fixed SSR error condition to only throw when key exists but data is undefined
e2e/test/suspense-undefined-key.test.ts Added e2e test verifying suspense behavior with undefined keys
e2e/site/app/suspense-undefined-key/page.tsx Test page demonstrating the undefined key scenario

@huozhi huozhi merged commit 4320796 into main Aug 11, 2025
6 checks passed
@huozhi huozhi deleted the fix/error-thrown-cond branch August 11, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

encounter "Fallback data is required when using Suspense in SSR." in suspense mode with 2.3.5
2 participants