Skip to content

test(preact-query/useSuspenseQueries): align cached data test with react-query to verify background refetch#10195

Open
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/preact-query-useSuspenseQueries-cached-data
Open

test(preact-query/useSuspenseQueries): align cached data test with react-query to verify background refetch#10195
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/preact-query-useSuspenseQueries-cached-data

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Feb 27, 2026

🎯 Changes

Align the should only suspend queries that are pending when some already have cached data test in preact-query with the react-query version (#10126).

Previously, the preact test used the same QUERY_DURATION for both queries and only verified the initial suspend/resolve. The updated test uses different durations for each query (matching react-query) and verifies that the background refetch completes and updates key1 from 'cached' to 'data1'.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for multi-query suspense scenarios with improved timing validation and background refetch simulation.

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: da9191a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Feb 27, 2026

View your CI Pipeline Execution ↗ for commit da9191a

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 9s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-27 00:35:17 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

This change modifies the useSuspenseQueries test in preact-query to use explicit timing values instead of constants and adds a background refetch simulation step. It tests behavior when data is partially cached and subsequently refetched in the background with specific timing assertions.

Changes

Cohort / File(s) Summary
Test Timing & Refetch Logic
packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx
Replaced generic QUERY_DURATION constants with explicit values (2000ms and 1000ms), adjusted timer advancement logic, and added background refetch simulation for cached data with subsequent assertions validating data updates from cached to fresh state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

package: preact-query

Suggested reviewers

  • TkDodo
  • manudeli

Poem

🐰 Hopping through timing with care,
Background fetches fill the air,
Cached data dances, fresh and new,
Two thousand ticks, then one rings true!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: aligning a preact-query test with react-query to verify background refetch behavior.
Description check ✅ Passed The description provides clear context about changes, includes all required checklist items checked, and specifies release impact as dev-only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 27, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10195

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10195

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10195

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10195

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10195

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10195

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10195

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10195

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10195

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10195

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10195

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10195

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10195

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10195

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10195

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10195

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10195

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10195

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10195

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10195

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10195

commit: da9191a

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx (1)

870-874: Consider replacing timing literals with local named constants.

The test is clear, but extracting 2000/1000 into local constants would reduce drift risk between queryFn durations and timer advances.

♻️ Suggested refactor
   it('should only suspend queries that are pending when some queries already have data', async () => {
     const key1 = queryKey()
     const key2 = queryKey()
+    const key1FetchMs = 2000
+    const key2FetchMs = 1000

     queryClient.setQueryData(key1, 'cached')

     function Page() {
       const [result1, result2] = useSuspenseQueries({
         queries: [
           {
             queryKey: key1,
-            queryFn: () => sleep(2000).then(() => 'data1'),
+            queryFn: () => sleep(key1FetchMs).then(() => 'data1'),
           },
           {
             queryKey: key2,
-            queryFn: () => sleep(1000).then(() => 'data2'),
+            queryFn: () => sleep(key2FetchMs).then(() => 'data2'),
           },
         ],
       })
@@
-    await vi.advanceTimersByTimeAsync(1000)
+    await vi.advanceTimersByTimeAsync(key2FetchMs)
@@
-    await vi.advanceTimersByTimeAsync(1000)
+    await vi.advanceTimersByTimeAsync(key1FetchMs - key2FetchMs)
@@
-    await vi.advanceTimersByTimeAsync(2000)
+    await vi.advanceTimersByTimeAsync(key1FetchMs)

Also applies to: 897-907

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx` around lines
870 - 874, Extract the numeric time literals used in the test into named local
constants (e.g., const DURATION_LONG = 2000, const DURATION_SHORT = 1000) and
use those constants in the queryFn sleep calls and any corresponding timer
advances/assertions; update the two query objects (the ones with queryFn: () =>
sleep(2000)... and queryFn: () => sleep(1000)...) to call sleep(DURATION_LONG) /
sleep(DURATION_SHORT) and replace matching advanceTimersByTime or wait calls
elsewhere in useSuspenseQueries.test.tsx (also apply the same refactor to the
similar block around lines 897-907) so durations stay consistent and
maintainable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx`:
- Around line 870-874: Extract the numeric time literals used in the test into
named local constants (e.g., const DURATION_LONG = 2000, const DURATION_SHORT =
1000) and use those constants in the queryFn sleep calls and any corresponding
timer advances/assertions; update the two query objects (the ones with queryFn:
() => sleep(2000)... and queryFn: () => sleep(1000)...) to call
sleep(DURATION_LONG) / sleep(DURATION_SHORT) and replace matching
advanceTimersByTime or wait calls elsewhere in useSuspenseQueries.test.tsx (also
apply the same refactor to the similar block around lines 897-907) so durations
stay consistent and maintainable.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0da627b and da9191a.

📒 Files selected for processing (1)
  • packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant