Skip to content

Fix resetApiState for skipped query hooks#5296

Open
cyphercodes wants to merge 2 commits into
reduxjs:masterfrom
cyphercodes:fix-reset-skipped-query-last-result
Open

Fix resetApiState for skipped query hooks#5296
cyphercodes wants to merge 2 commits into
reduxjs:masterfrom
cyphercodes:fix-reset-skipped-query-last-result

Conversation

@cyphercodes
Copy link
Copy Markdown

Summary

  • Fix skipped query hooks so api.util.resetApiState() clears retained data from the hook's previous lastResult
  • Track the last non-skipped result separately so reset detection still works after the skipped render has dropped endpoint metadata
  • Add a regression test for resetting while a useQuery hook is skipped

Fixes #5295.

Testing

  • yarn workspace @reduxjs/toolkit test src/query/tests/buildHooks.test.tsx
  • DISABLE_V8_COMPILE_CACHE=1 yarn workspace @reduxjs/toolkit eslint src/query/react/buildHooks.ts src/query/tests/buildHooks.test.tsx
  • git diff --check

@aryaemami59 aryaemami59 changed the title Fix resetApiState for skipped query hooks Fix resetApiState for skipped query hooks May 18, 2026
@aryaemami59 aryaemami59 added the RTK-Query Issues related to Redux-Toolkit-Query label May 18, 2026
@cyphercodes
Copy link
Copy Markdown
Author

Updated this PR to fix the CI/type-generation failure:

  • Added an explicit return undefined for the skipped/reset selector fallback path in buildHooks.ts, resolving TS7030 (Not all code paths return a value).

Local verification:

  • corepack prepare yarn@4.4.1 --activate && yarn install --immutable
  • yarn workspace @reduxjs/toolkit build
  • yarn workspace @reduxjs/toolkit vitest --typecheck --run src/query/tests/buildHooks.test.tsx -t "resetApiState"
  • git diff --check

Note: I also attempted targeted ESLint locally, but this agent image hits an ESLint 7 / Node 22 module-loading error before linting project code (async-function/require.mjs: Cannot use import statement outside a module).

@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit f0b0e4d
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/6a0b461227bd8300088a593a
😎 Deploy Preview https://deploy-preview-5296--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f0b0e4d:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RTK-Query Issues related to Redux-Toolkit-Query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

queryStatePreSelector does not reset lastResult after resetApiState() when hook is in skipped state (v2 regression from v1.9)

2 participants