Repository navigation
useSubscription should abort when input changes - #6770
Conversation
WalkthroughA new helper function, Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Case
participant Component as SubscriptionComponent
participant Helpers as Test Helpers
participant Providers as Query/TRPC Providers
participant AppRouter as Subscription Logic
Test->>Helpers: renderApp(ui)
Helpers->>Providers: Wrap ui with Providers
Providers->>Component: Render with input 1
Component->>AppRouter: Start subscription (input 1)
AppRouter-->>Component: Send data
Test->>Helpers: rerenderApp(renderResult, ui with input 2)
Helpers->>Providers: Rerender ui with Providers
Providers->>Component: Render with input 2
Component->>AppRouter: Abort subscription (input 1)
AppRouter->>Helpers: Mark abortState[input 1] = 'aborted'
Component->>AppRouter: Start subscription (input 2)
Test->>Helpers: Unmount component
Component->>AppRouter: Abort subscription (input 2)
AppRouter->>Helpers: Mark abortState[input 2] = 'aborted'
Poem
Note β‘οΈ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note β‘οΈ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (1)
π§ Files skipped from review as they are similar to previous changes (1)
β° Context from checks skipped due to timeout of 90000ms (19)
β¨ Finishing Touches
πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
π Deployed to the trpc-pr-6770 environment in trpc-sse-and-websockets
|
@trpc/client
@trpc/next
@trpc/server
@trpc/react-query
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
There was a problem hiding this comment.
Actionable comments posted: 0
π§Ή Nitpick comments (2)
packages/tanstack-react-query/test/__helpers.tsx (1)
6-6: Update the import to use type-only imports.The
RenderResultis only used as a type, so it should use TypeScript's type-only import syntax.-import { render, RenderResult } from '@testing-library/react'; +import { render } from '@testing-library/react'; +import type { RenderResult } from '@testing-library/react';π§° Tools
πͺ ESLint
[error] 6-6: Imports "RenderResult" are only used as type.
(@typescript-eslint/consistent-type-imports)
packages/tanstack-react-query/test/useSubscription.test.tsx (1)
4-4: Remove unused import.The
inputimport from@testing-library/user-event/dist/types/eventis not used anywhere in the code.-import { input } from '@testing-library/user-event/dist/types/event';
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
packages/tanstack-react-query/test/__helpers.tsx(2 hunks)packages/tanstack-react-query/test/useSubscription.test.tsx(5 hunks)
π§° Additional context used
πͺ ESLint
packages/tanstack-react-query/test/__helpers.tsx
[error] 6-6: Imports "RenderResult" are only used as type.
(@typescript-eslint/consistent-type-imports)
β° Context from checks skipped due to timeout of 90000ms (20)
- GitHub Check: E2E-tests (nuxt)
- GitHub Check: E2E-tests (express-server)
- GitHub Check: E2E-tests (express-minimal)
- GitHub Check: E2E-tests (.test/diagnostics-big-router)
- GitHub Check: E2E-tests (.test/ssg)
- GitHub Check: E2E-tests (fastify-server)
- GitHub Check: E2E-tests (.experimental/next-app-dir)
- GitHub Check: E2E-tests (.test/internal-types-export)
- GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
- GitHub Check: Test a monorepo using built declaration files
- GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
- GitHub Check: Release using pkg.pr.new
- GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
- GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
- GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
- GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
- GitHub Check: E2E-tests (Deno) (deno-deploy)
- GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
- GitHub Check: test
- GitHub Check: Analyze (typescript)
π Additional comments (7)
packages/tanstack-react-query/test/__helpers.tsx (2)
43-51: LGTM! The new rerenderApp function is a useful addition.The implementation correctly maintains the same context providers when rerendering components, which ensures consistent client and context usage during tests.
58-58: LGTM! Correct addition to the return object.The
rerenderAppfunction is properly exported in the return object, making it available for tests.packages/tanstack-react-query/test/useSubscription.test.tsx (5)
9-9: LGTM! Necessary import for abort handling.This import is needed for the new abort error detection in the subscription handler.
62-63: LGTM! Good approach to track aborted subscriptions.Using an object to track the abort state by subscription input is a clean approach and allows for precise verification in tests.
80-92: LGTM! Proper handling of abort errors.The try-catch block correctly identifies abort errors and updates the abort state, without swallowing other errors. This allows the test to verify that subscriptions are properly aborted when inputs change.
131-131: LGTM! Exposing abort state for test verification.Returning the abort state makes it accessible for assertions in the tests.
396-468: LGTM! Comprehensive test for subscription abort behavior.This test thoroughly verifies two important behaviors:
- When a subscription's input changes, the previous subscription is properly aborted
- When a component unmounts, all active subscriptions are aborted
The test uses the new
rerenderApphelper appropriately to trigger the input change scenario.
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #
π― Changes
What changes are made in this PR? Is it a feature or a bug fix?
β Checklist
Summary by CodeRabbit