Skip to content

perf(utils): ignore stale useFetch responses#539

Closed
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-use-fetch-stale-runs-pr
Closed

perf(utils): ignore stale useFetch responses#539
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-use-fetch-stale-runs-pr

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Add a latest-run guard to useFetch so older in-flight window.electron.httpRequest responses cannot update data, errors, loading state, or callbacks after a newer request starts.
  • Invalidate active runs when execute flips false or the hook unmounts.
  • Refetch function-valued URLs when their resolved initial request URL changes, while skipping duplicate internal rerenders for the same resolved URL/options.
  • Add a focused hook harness covering stale revalidate responses and function URL request-input changes.

Why

Rapid revalidate, pagination, or request-input changes can leave multiple HTTP requests in flight. Before this patch, an older response could resolve after a newer run and overwrite newer data or invoke stale callbacks.

Compatibility impact

  • useFetch return shape and option names are unchanged.
  • No abort signal is added to the Electron HTTP request path; stale responses are ignored when they settle.
  • Function URL behavior remains conservative: a fresh function identity does not refetch by itself if it resolves to the same initial request URL with the same request options.

How tested

  • Before evidence: node --test scripts/test-use-fetch-stale-runs.mjs failed before the hook change because stale data overwrote the latest result, and a changed function URL request input did not start a second request.
  • After evidence: node --test scripts/test-use-fetch-stale-runs.mjs passes on this PR branch.
  • Stack validation from the integration branch: node --test scripts/test-use-fetch-stale-runs.mjs scripts/test-abortable-promise-hooks.mjs scripts/test-menubar-storage-remounts.mjs scripts/test-raycast-cache-size-index.mjs passed 20 tests.
  • Clean PR branch note: the nearby stack test scripts are not present on current origin/main yet, so the focused useFetch test was rerun here.
  • LSP diagnostics: no TypeScript errors reported for src/renderer/src/raycast-api/hooks/use-fetch.ts.

Stack validation

Draft until the consolidation stack lands. This targets upstream main and depends on #530, #531, #532, #533, #534, and #535.

@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated upstream PR #555.

@JustYannicc JustYannicc closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant