Skip to content

Conversation

Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Aug 19, 2025

It turns out the 'hover preload, then navigate, w/ async loaders' test in packages/react-router/tests/store-updates-during-navigation.test.tsx was sometimes (but very rarely) yielding 16 updates instead of the expected 15. This PR makes minimal changes to this test so that it's now reliably 14.

I'm not exactly sure where we lost that 1 update, so we might not be measuring exactly the same thing. But it's still worth it to have a robust test suite.

Summary by CodeRabbit

  • Tests
    • Improved reliability of hover preloading and navigation behavior tests by introducing realistic loader delays and aligning interaction timing, reducing flakiness.
    • Updated assertions for store updates during navigation to reflect observed behavior, ensuring more stable and predictable test outcomes.

Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

The test for hover-preload in packages/react-router/tests/store-updates-during-navigation.test.tsx adds a 100ms delayed loader, inserts a 50ms wait after focusing a link before clicking, and updates the expected store update count from 15 to 14.

Changes

Cohort / File(s) Summary
Test timing adjustments
packages/react-router/tests/store-updates-during-navigation.test.tsx
Loader changed to resolveAfter(100,...), added 50ms delay after focus before click, and adjusted expected update count from 15 to 14.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

package: router-core, package: react-router

Suggested reviewers

  • schiller-manuel

Poem

I hopped through tests with timing neat,
A hundred ticks before the treat.
Fifty more to pause my feet—
Then fourteen beats, a tidy feat.
In routes I roam, with ears alert,
Preloading dreams in buffered spurt.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test-router-core-store-updates-flaky

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Aug 19, 2025

View your CI Pipeline Execution ↗ for commit fb9fc25

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 5m 23s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 33s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-19 07:16:39 UTC

Copy link

pkg-pr-new bot commented Aug 19, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@4995

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@4995

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@4995

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@4995

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@4995

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@4995

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@4995

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@4995

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@4995

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@4995

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@4995

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@4995

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@4995

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@4995

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@4995

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@4995

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@4995

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@4995

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@4995

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@4995

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@4995

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@4995

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@4995

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@4995

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@4995

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@4995

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@4995

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@4995

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@4995

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@4995

@tanstack/start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@4995

@tanstack/start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@4995

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@4995

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@4995

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@4995

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@4995

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@4995

commit: fb9fc25

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/react-router/tests/store-updates-during-navigation.test.tsx (4)

199-201: Replace wall-time sleep with a state-based wait to reduce flakiness

Sleeping for 50ms is still sensitive to CI load. Wait for the first store update triggered by focus instead, which is what we actually need before clicking.

Apply this diff:

 fireEvent.focus(link)
-    await new Promise((resolve) => setTimeout(resolve, 50))
+    await waitFor(() => {
+      expect(select.mock.calls.length).toBeGreaterThan(before)
+    })

212-212: Make the assertion non-brittle: assert an upper bound

The surrounding comment says “should be as small as possible.” Asserting an exact count invites future flakiness due to timing nuance. Use an upper bound aligned with your target.

Apply this diff:

-    expect(updates).toBe(14)
+    expect(updates).toBeLessThanOrEqual(14)

107-109: Type correctness: resolveAfter resolves a value but returns Promise

This currently resolves a value while declaring Promise. Tighten types to prevent accidental misuse and improve editor help.

Apply this diff:

-function resolveAfter(ms: number, value: any) {
-  return new Promise<void>((resolve) => setTimeout(() => resolve(value), ms))
-}
+function resolveAfter<T>(ms: number, value: T): Promise<T> {
+  return new Promise<T>((resolve) => setTimeout(() => resolve(value), ms))
+}

199-199: Test name vs. stimulus mismatch (hover vs. focus)

The test title mentions “hover”, but it uses focus(). Either update the name or simulate hover to better reflect the scenario.

If you want to align with the name using minimal changes:

-    fireEvent.focus(link)
+    fireEvent.mouseEnter(link)

Note: switching to hover may change the update count and require re-tuning the expectation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 83ab173 and fb9fc25.

📒 Files selected for processing (1)
  • packages/react-router/tests/store-updates-during-navigation.test.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (1)
packages/react-router/tests/store-updates-during-navigation.test.tsx (1)

192-192: Delay in loader looks good to stabilize preload overlap

Switching the loader to a 100ms delay makes the preload overlap with the navigation consistently. Good call.

@Sheraff Sheraff merged commit 3f05c0b into main Aug 19, 2025
6 checks passed
@Sheraff Sheraff deleted the test-router-core-store-updates-flaky branch August 19, 2025 07:18
tannerlinsley pushed a commit that referenced this pull request Aug 26, 2025
…ate' test (#4995)

It turns out the 'hover preload, then navigate, w/ async loaders' test
in
`packages/react-router/tests/store-updates-during-navigation.test.tsx`
was sometimes (but very rarely) yielding 16 updates instead of the
expected 15. This PR makes minimal changes to this test so that it's now
reliably 14.

I'm not exactly sure where we lost that 1 update, so we might not be
measuring exactly the same thing. But it's still worth it to have a
robust test suite.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Improved reliability of hover preloading and navigation behavior tests
by introducing realistic loader delays and aligning interaction timing,
reducing flakiness.
* Updated assertions for store updates during navigation to reflect
observed behavior, ensuring more stable and predictable test outcomes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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