Skip to content

fix(raycast): guard stale promise hook runs#551

Closed
JustYannicc wants to merge 38 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-promise-latest-run-guards
Closed

fix(raycast): guard stale promise hook runs#551
JustYannicc wants to merge 38 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-promise-latest-run-guards

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Added an internal latest-run id to usePromise and useCachedPromise so stale completions cannot update data, error, isLoading, onData, or onError when callers do not pass abortable.
  • Kept the existing AbortController guard in place for abortable callers.
  • Extended the focused promise hook harness with default non-abortable overlap coverage for stale success, loading, and error paths.

Why

Default Raycast-style hook usage can overlap executions through revalidate() or argument changes without passing abortable. The previous current-run check treated every non-abortable run as current, so an older completion could overwrite a newer result or callback state.

Compatibility impact

  • Hook return shapes and options are unchanged.
  • Abortable callers still receive an AbortController.
  • Starting a newer abortable run still aborts the previous run and clears refs on completion/unmount.

How tested

  • Before the fix, the new default overlap tests failed in node --test scripts/test-abortable-promise-hooks.mjs: both default usePromise and useCachedPromise let stale data overwrite latest.
  • node --test scripts/test-abortable-promise-hooks.mjs now passes 12/12.
  • ./node_modules/.bin/tsc -p tsconfig.renderer.json --noEmit --pretty false
  • LSP diagnostics on both changed hook files: no errors.

Stack validation

This is a stacked draft PR. It depends on #530, #531, #532, #533, #534, #535, and JustYannicc:codex/perf-consolidated-integration-stack.

A clean codex/perf-promise-latest-run-guards-pr branch from origin/main was attempted, but cherry-picking this scoped commit conflicted because origin/main does not yet contain the abortable hook lifecycle changes or scripts/test-abortable-promise-hooks.mjs.

…s' into codex/perf-consolidated-integration-stack
…nd-menubar' into codex/perf-consolidated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/hooks/use-cached-promise.ts
…emoji' into codex/perf-consolidated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime-renderers.tsx
#	src/renderer/src/raycast-api/list-runtime.tsx
… into codex/perf-consolidated-integration-stack
…tus' into codex/perf-consolidated-integration-stack
… into codex/perf-consolidated-integration-stack

# Conflicts:
#	src/renderer/src/CameraExtension.tsx
@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