GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(react-query): hoist every staleTime into a named exported constant by waleedlatif1 · Pull Request #5427 · simstudioai/sim

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New repo-wide convention: every staleTime in hooks/queries/** must come from a named exported constant, never an inline numeric literal
  • Reason: PR fix(sidebar): prefetch folders and workspace permissions on cold load #5426's review caught useFolders duplicating the same duration as a separate server-side prefetch as a raw literal — if one changes and the other doesn't, the prefetched cache entry silently drifts out of sync with the client hook reading it
  • Documented the rule in .claude/rules/sim-queries.md, root CLAUDE.md, and the react-query-best-practices skill/command (.agents/skills/, .claude/commands/, .cursor/commands/)
  • Applied it mechanically across all ~47 files in hooks/queries/** (~140 call sites) and their 6 prefetch.ts consumers under app/workspace/[workspaceId]/**
  • Deliberately left staleTime: 0/Infinity alone — those are deliberate always-refetch/never-refetch idioms, not durations that can drift
  • Moved TABLE_LIST_STALE_TIME into the non-'use client' hooks/queries/utils/table-keys.ts (not hooks/queries/tables.ts, which is 'use client') so the tables prefetch can import it without a client-boundary violation
  • No numeric value was changed anywhere — this is a pure rename/hoist, zero behavior change

Type of Change

  • Refactor / consistency

Testing

  • bunx tsc --noEmit clean
  • bun run check:client-boundary and bun run check:react-query both pass
  • bunx biome check clean on all touched files
  • 582 existing tests across hooks/queries/** and the tables/settings/knowledge/files/home pages pass unmodified

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@waleedlatif1
refactor(react-query): hoist every staleTime into a named exported co…
29090e5
…nstant

Adds a repo-wide convention (documented in .claude/rules/sim-queries.md,
CLAUDE.md, and the react-query-best-practices skill/command) that every
staleTime value must come from a named exported constant instead of an
inline numeric literal. This prevents a server-side prefetch and its
client hook from independently duplicating the same duration and
drifting out of sync, which Greptile caught on PR #5426.

Applies the convention across all of hooks/queries/** and their
prefetch.ts consumers.
@vercel

vercel Bot commented Jul 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 5, 2026 5:39pm

Request Review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cursor

cursor Bot commented Jul 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

PR Summary

Low Risk
Mechanical rename with unchanged durations and no auth or data-path logic changes; risk is limited to import/boundary mistakes, which CI checks are meant to catch.

Overview
Introduces a repo-wide React Query convention: every staleTime must come from a named exported constant (no inline millisecond literals), and server prefetch.ts helpers must import the same constant as the client hook for that query key so hydration and client reads never drift.

The rule is documented in sim-queries.md, root CLAUDE.md, and the react-query best-practices skill/commands. The change is applied mechanically across hooks/queries/** (~140 call sites) and six workspace prefetch.ts modules (files, home, knowledge, settings, tables, etc.), including in-hook prefetchQuery helpers. TABLE_LIST_STALE_TIME lives in non–'use client' utils/table-keys.ts so the tables page prefetch can import it safely.

No numeric staleTime values were changed; staleTime: 0 / Infinity idioms were left as-is.

Reviewed by Cursor Bugbot for commit 661efac. Configure here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot deployed to Preview July 5, 2026 04:05
View deployment
@greptile-apps

greptile-apps Bot commented Jul 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR mechanically hoists every inline staleTime numeric literal in hooks/queries/** (~140 call sites across ~47 files) into a named exported constant, and updates the six server-side prefetch.ts consumers to import those constants instead of restating the number — eliminating the cache-drift hazard where a prefetch and its client hook could silently diverge.

  • Core change: each query file now exports one constant per query type (e.g. LOG_DETAIL_STALE_TIME, TABLE_LIST_STALE_TIME); staleTime: 0 and staleTime: Infinity are intentionally left as literals since they are semantic idioms, not durations.
  • Client-boundary split: TABLE_LIST_STALE_TIME is placed in the non-'use client' utils/table-keys.ts module (while TABLE_DETAIL_STALE_TIME etc. stay in the 'use client' tables.ts) so the server-side tables prefetch can import it without triggering the client-boundary guard.
  • Documentation: the convention is codified in CLAUDE.md, .claude/rules/sim-queries.md, and the react-query-best-practices skill so future hooks will follow it from the start.

Confidence Score: 5/5

Pure rename/hoist refactor — no numeric values changed, no behavior change, TypeScript clean, client-boundary check passes.

Every changed line is a mechanical substitution of an inline literal with its newly-named constant; no query logic, fetch functions, or cache keys were touched. The tricky TABLE_LIST_STALE_TIME split across the client-boundary is handled correctly. The only residual gap is a handful of component files outside the stated scope that still carry inline literals duplicating the new constants, but that does not affect correctness of the change itself.

logs.tsx and knowledge-base-selector.tsx still carry inline staleTime literals that duplicate the new constants — worth a follow-up pass to extend the convention outside hooks/queries.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/utils/table-keys.ts Adds TABLE_LIST_STALE_TIME constant in a non-'use client' module so both the server-side prefetch and the client hook can import it without a boundary violation
apps/sim/hooks/queries/tables.ts Imports TABLE_LIST_STALE_TIME from utils/table-keys and adds TABLE_DETAIL_STALE_TIME, TABLE_RUN_STATE_STALE_TIME, TABLE_ROWS_STALE_TIME, TABLE_EXPORT_JOBS_STALE_TIME; all inline literals replaced
apps/sim/app/workspace/[workspaceId]/tables/prefetch.ts Imports TABLE_LIST_STALE_TIME from utils/table-keys to stay in sync with client hook staleTime
apps/sim/app/workspace/[workspaceId]/settings/[section]/prefetch.ts All three prefetch functions now import GENERAL_SETTINGS_STALE_TIME, SUBSCRIPTION_DATA_STALE_TIME, USER_PROFILE_STALE_TIME from their respective non-'use client' hook modules
apps/sim/hooks/queries/subscription.ts Exports SUBSCRIPTION_DATA_STALE_TIME, USAGE_LIMIT_STALE_TIME, INVOICES_STALE_TIME; the hook's optional staleTime parameter default is also wired to the constant
apps/sim/hooks/queries/workspace.ts Exports five workspace stale-time constants; prefetchWorkspaceSettings and useWorkspaceSettings both reference WORKSPACE_SETTINGS_STALE_TIME, keeping them in sync
apps/sim/hooks/queries/workflow-search-replace.ts Adds 14 separate stale-time constants (one per semantically distinct query); fallback literals for definition.staleTime also reference constants
apps/sim/hooks/queries/kb/knowledge.ts Exports nine knowledge-base stale-time constants; knowledge/prefetch.ts imports KNOWLEDGE_BASE_LIST_STALE_TIME to match client hook
apps/sim/hooks/queries/organization.ts Eight organization stale-time constants replace eight identical 30 * 1000 inline literals across the file

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["hooks/queries/entity.ts\n(no 'use client')"] -->|"exports"| B["ENTITY_LIST_STALE_TIME = 60 * 1000"]
    A -->|"exports"| C["useEntityList hook"]
    B -->|"staleTime: ENTITY_LIST_STALE_TIME"| C
    D["app/.../prefetch.ts\n(server-side)"] -->|"imports"| B
    D -->|"staleTime: ENTITY_LIST_STALE_TIME"| E["queryClient.prefetchQuery"]

    subgraph special ["Client-boundary exception: tables"]
        F["hooks/queries/tables.ts\n('use client')"] -->|"imports TABLE_LIST_STALE_TIME"| G
        G["hooks/queries/utils/table-keys.ts\n(no 'use client')\nexports TABLE_LIST_STALE_TIME"]
        H["app/.../tables/prefetch.ts\n(server-side)"] -->|"imports TABLE_LIST_STALE_TIME"| G
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["hooks/queries/entity.ts\n(no 'use client')"] -->|"exports"| B["ENTITY_LIST_STALE_TIME = 60 * 1000"]
    A -->|"exports"| C["useEntityList hook"]
    B -->|"staleTime: ENTITY_LIST_STALE_TIME"| C
    D["app/.../prefetch.ts\n(server-side)"] -->|"imports"| B
    D -->|"staleTime: ENTITY_LIST_STALE_TIME"| E["queryClient.prefetchQuery"]

    subgraph special ["Client-boundary exception: tables"]
        F["hooks/queries/tables.ts\n('use client')"] -->|"imports TABLE_LIST_STALE_TIME"| G
        G["hooks/queries/utils/table-keys.ts\n(no 'use client')\nexports TABLE_LIST_STALE_TIME"]
        H["app/.../tables/prefetch.ts\n(server-side)"] -->|"imports TABLE_LIST_STALE_TIME"| G
    end
Loading

Reviews (3): Last reviewed commit: "refactor(react-query): use FOLDER_LIST_S..." | Re-trigger Greptile

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot]
greptile-apps Bot reviewed Jul 5, 2026
View reviewed changes
Comment thread apps/sim/hooks/queries/workflow-search-replace.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@waleedlatif1

waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@waleedlatif1

waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Jul 5, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 29090e5. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@waleedlatif1
refactor(react-query): use FOLDER_LIST_STALE_TIME in folders.ts hooks
661efac
useFolders and useFolderMap still used inline 60 * 1000 despite folders.ts
already exporting FOLDER_LIST_STALE_TIME — the same prefetch-drift gap this
refactor closes everywhere else. Same value, no behavior change.
@vercel
vercel Bot temporarily deployed to Preview July 5, 2026 17:39 Inactive
@waleedlatif1

waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the folders.ts finding in 661efac — useFolders and useFolderMap now use the already-exported FOLDER_LIST_STALE_TIME instead of inline 60 * 1000 (same value, closes the last prefetch-drift gap). Re-running review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@waleedlatif1

waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@waleedlatif1

waleedlatif1 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Jul 5, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 661efac. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@waleedlatif1
waleedlatif1 merged commit 487166f into staging Jul 5, 2026
18 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@waleedlatif1
waleedlatif1 deleted the react-query-staletime-constants branch July 5, 2026 17:59
@waleedlatif1 waleedlatif1 mentioned this pull request Jul 7, 2026
v0.7.24: frontend perf improvements, md editor fixes, mailer fix, tools audit #5458
Merged

This branch was previously deployed

1 inactive deployment
Preview — 661efac3 Deployed Jul 5, 2026 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments
@cursor cursor[bot] cursor[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@waleedlatif1
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.