Skip to content

test(svelte-query/createQuery): fix 'it.todo' for different stale times by advancing timer before query creation - #10396

Merged
sukvvon merged 3 commits into
mainfrom
test/svelte-query-createQuery-fix-stale-times-todo
Apr 6, 2026
Merged

test(svelte-query/createQuery): fix 'it.todo' for different stale times by advancing timer before query creation#10396
sukvvon merged 3 commits into
mainfrom
test/svelte-query-createQuery-fix-stale-times-todo

Conversation

@sukvvon

@sukvvonsukvvon commented Apr 6, 2026

Copy link
Copy Markdown
Member

🎯 Changes

  • Resolve it.todo test "should be able to set different stale times for a query"
  • The test was failing due to a timing issue, not a race condition in query-core as previously suspected
  • Root cause: under fake timers, no time passes between prefetchQuery completion and query creation, so secondQuery (staleTime: 10) saw prefetched data as fresh instead of stale, preventing refetch
  • Fix: advance timer by 11ms after prefetch to ensure secondQuery sees stale data and triggers refetch
  • Avoid fake timer deadlock by storing prefetchQuery promise and awaiting it after advanceTimersByTimeAsync

✅ 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
    • Enabled a previously skipped test covering two query instances that share a key but use different stale-time settings
    • Added assertions confirming correct data updates and stale/fresh transitions for both instances over time
    • Removed prior race-condition workarounds to improve test clarity and reliability

@coderabbitai

coderabbitaiBot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20c9cc0f-9b94-4d3a-b5c0-992eda39ff2a

📥 Commits

Reviewing files that changed from the base of the PR and between 5504f91 and 107238a.

📒 Files selected for processing (1)
  • packages/svelte-query/tests/createQuery.svelte.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/svelte-query/tests/createQuery.svelte.test.ts

📝 Walkthrough

Walkthrough

Converted a skipped it.todo test into an active test in packages/svelte-query/tests/createQuery.svelte.test.ts that prefetches a shared query key, mounts two createQuery instances with different staleTime values, advances fake timers, and asserts their state and stale transitions.

Changes

Cohort / File(s)Summary
Test Implementation
packages/svelte-query/tests/createQuery.svelte.test.ts
Replaced a skipped/TODO test with an active test. Prefetches a query, mounts two createQuery instances sharing a key with staleTime: 100 and staleTime: 10, advances fake timers, and asserts data, isStale flags, and recorded effect-root state sequences. Removed prior vi.waitFor/workaround logic and TODO block.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A TODO turned to test tonight,
Timers jump forward, states take flight,
Two queries hum in timed duet,
Fresh then stale — no workaround yet,
Hooray, the rabbit hops with delight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly describes the main change: converting a skipped test into an active test by fixing a timing issue with fake timers and stale times.
Description check✅ PassedThe description follows the template with all major sections completed: Changes section explains the issue and fix, both checklist items are filled out (one checked, one unchecked with justification), and Release Impact is properly addressed.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/svelte-query-createQuery-fix-stale-times-todo

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

@nx-cloud

nx-cloudBot commented Apr 6, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 107238a

CommandStatusDurationResult
nx run-many --target=build --exclude=examples/*...✅ Succeeded<1sView ↗
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded24sView ↗

☁️ Nx Cloud last updated this comment at 2026-04-06 00:55:06 UTC

@github-actions

github-actionsBot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new

pkg-pr-newBot commented Apr 6, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10396

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 107238a

@github-actions

github-actionsBot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
react full11.98 KB (0%)
react minimal9.01 KB (0%)

@sukvvonsukvvon self-assigned this Apr 6, 2026
@sukvvon
sukvvon merged commit e76d476 into mainApr 6, 2026
8 checks passed
@sukvvon
sukvvon deleted the test/svelte-query-createQuery-fix-stale-times-todo branch April 6, 2026 01:05
Sign up for freeto 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

@sukvvon