Skip to content

fix: correct useEducationStatus query cache configuration#30416

Merged
lyzno1 merged 3 commits intomainfrom
fix/education-status-query-config
Dec 31, 2025
Merged

fix: correct useEducationStatus query cache configuration#30416
lyzno1 merged 3 commits intomainfrom
fix/education-status-query-config

Conversation

@lyzno1
Copy link
Member

@lyzno1 lyzno1 commented Dec 31, 2025

Part of #30414
Fixes #30415

Summary

Replaced ineffective gcTime: 0 with proper cache controls for provider-level query.

Changes

Hook Configuration

  • ❌ Removed gcTime: 0 (ineffective for active queries)
  • ✅ Added staleTime: 0 (ensures data marked stale immediately)

Component Usage

  • ✅ Use isFetchedAfterMount to prevent displaying cached data before fresh fetch

Why

Per TanStack Query docs, gcTime only applies to inactive queries. Provider-level queries remain active, making gcTime: 0 ineffective.

Testing

  • ✅ pnpm lint:fix
  • ✅ pnpm type-check:tsgo
- Replace ineffective gcTime: 0 with proper cache controls - Add staleTime: 0, refetchOnMount, and refetchOnWindowFocus - Use isFetchedAfterMount to prevent stale data display - Follows TanStack Query best practices for provider-level queries
Copilot AI review requested due to automatic review settings December 31, 2025 04:37
@lyzno1 lyzno1 requested a review from iamjoel as a code owner December 31, 2025 04:37
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 31, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lyzno1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the useEducationStatus query was not consistently providing up-to-date information due to incorrect TanStack Query cache settings. By adjusting the query options to ensure immediate staleness and aggressive refetching, and by conditionally rendering data only after a fresh fetch, this change guarantees that users always see the most current education account status, improving data reliability across various user interaction scenarios.

Highlights

  • Cache Configuration Fix: Corrected the useEducationStatus query cache configuration to ensure data freshness.
  • TanStack Query Options: Replaced the ineffective gcTime: 0 with staleTime: 0, refetchOnMount: true, and refetchOnWindowFocus: true for proper cache control.
  • Data Display Logic: Implemented isFetchedAfterMount in ProviderContextProvider to prevent displaying potentially stale cached data before a fresh fetch completes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a caching issue with the useEducationStatus query by updating the TanStack Query configuration to ensure data is always fresh. The use of isFetchedAfterMount to prevent displaying stale data is a good improvement. I've found one potential bug related to the use of the logical OR operator || instead of the nullish coalescing operator ??, which could lead to incorrect data handling for falsy values. My suggestion addresses this.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the query cache configuration for useEducationStatus by replacing the ineffective gcTime: 0 with proper cache controls. The change addresses an issue where gcTime (garbage collection time) was being used to prevent stale data, but this setting only affects inactive queries and was therefore ineffective for the provider-level query that remains active.

Key Changes:

  • Replaced gcTime: 0 with staleTime: 0 to ensure data is immediately marked as stale
  • Added explicit refetch configurations to handle component mount and window focus scenarios
  • Modified the provider context to use isFetchedAfterMount flag to prevent displaying cached data before fresh fetch completes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
web/service/use-education.ts Updated query configuration to use staleTime: 0 and added explicit refetch options instead of ineffective gcTime: 0
web/context/provider-context.tsx Added conditional logic using isFetchedAfterMount to prevent displaying cached education data before fresh fetch completes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Replace || with ?? to prevent issues with falsy values - Fixes potential bug where expire_at: 0 would be incorrectly converted to null - Improves code clarity and follows best practices
- Remove refetchOnMount (default: true) - Remove refetchOnWindowFocus (default: true) - Keep only non-default configuration: staleTime: 0
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 31, 2025
@lyzno1 lyzno1 merged commit f28a08a into main Dec 31, 2025
15 checks passed
@lyzno1 lyzno1 deleted the fix/education-status-query-config branch December 31, 2025 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

3 participants