Skip to content

fix: Ensure preload runs only on client#4213

Merged
shuding merged 3 commits intomainfrom
copilot/ensure-preload-is-noop-on-server
Jan 30, 2026
Merged

fix: Ensure preload runs only on client#4213
shuding merged 3 commits intomainfrom
copilot/ensure-preload-is-noop-on-server

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 29, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Make sure preload() run only on the client (typeof window !== 'undefined'), and make it noop in other cases


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jan 29, 2026

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.

@shuding
Copy link
Copy Markdown
Member

shuding commented Jan 30, 2026

@copilot where are you?

Copilot AI and others added 2 commits January 30, 2026 12:08
Co-authored-by: shuding <3676859+shuding@users.noreply.github.com>
Co-authored-by: shuding <3676859+shuding@users.noreply.github.com>
@shuding shuding marked this pull request as ready for review January 30, 2026 17:41
@shuding shuding changed the title [WIP] Ensure preload runs only on client fix: Ensure preload runs only on client Jan 30, 2026
@shuding shuding requested review from Copilot and removed request for huozhi January 30, 2026 17:46
Copy link
Copy Markdown

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 adds server-side safety to the preload() function by making it a no-op when executed on the server. The implementation uses the existing IS_SERVER flag to detect server environments and returns undefined without executing the fetcher or modifying cache state.

Changes:

  • Added early return in preload() function when IS_SERVER is true
  • Added test coverage to verify server-side no-op behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/_internal/utils/preload.ts Adds server-side check to return undefined early, preventing fetcher execution and cache modifications on the server
test/use-swr-server.test.tsx Adds test suite to verify that preload returns undefined and doesn't call the fetcher in server environments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shuding shuding merged commit f864770 into main Jan 30, 2026
12 checks passed
@shuding shuding deleted the copilot/ensure-preload-is-noop-on-server branch January 30, 2026 17:55
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.

3 participants