Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 3, 2025

Hiding Copilot summary since it's bad. Tests are rewritten by Hiroshi

Adds comprehensive test coverage for React.cache functionality in the React Server Components plugin. This ensures that the React 19 caching API works correctly in the RSC environment.

What's Added

New Test Route

  • packages/plugin-rsc/examples/basic/src/routes/react-cache/server.tsx:
    • TestReactCacheFn: Interactive form that tests React.cache() with different arguments and server actions
    • TestReactCacheComponent: Demonstrates React.cache working within server component render cycles
    • Shows caching behavior with async functions and multiple calls

E2E Test Coverage

  • Updated packages/plugin-rsc/e2e/basic.test.ts:
    • Tests React.cache function interactivity via form submissions
    • Tests React.cache in server component rendering context
    • Validates functionality works in both dev and build modes
    • All tests passing (4/4)

Integration

  • Updated packages/plugin-rsc/examples/basic/src/routes/root.tsx to include the new test component

Example Usage

The implementation demonstrates React.cache working correctly:

const testCacheFn = React.cache(async (arg: unknown) => {
  cacheFnCount++
  await new Promise((resolve) => setTimeout(resolve, 20))
  return arg
})

// Multiple calls with same argument use cache
await testCacheFn('same-arg')
await testCacheFn('same-arg') // Cached result

This provides confidence that developers can use React.cache() in their RSC applications with @vitejs/plugin-rsc without issues.

Fixes #619.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Add React.cache test feat(plugin-rsc): add React.cache test coverage Aug 3, 2025
@Copilot Copilot AI requested a review from hi-ogawa August 3, 2025 23:51
Copilot finished work on behalf of hi-ogawa August 3, 2025 23:51
@hi-ogawa hi-ogawa changed the title feat(plugin-rsc): add React.cache test coverage test(plugin-rsc): test React.cache Aug 4, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review August 4, 2025 01:15
@hi-ogawa hi-ogawa changed the title test(plugin-rsc): test React.cache test(rsc): test React.cache Aug 4, 2025
@hi-ogawa hi-ogawa merged commit 26ad4ad into main Aug 4, 2025
21 checks passed
@hi-ogawa hi-ogawa deleted the copilot/fix-619 branch August 4, 2025 03:00
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.

Add React.cache test

2 participants