Skip to content

fix: preserve keys with undefined values in copyWithStructuralSharing#5274

Open
cyphercodes wants to merge 1 commit into
reduxjs:masterfrom
cyphercodes:master
Open

fix: preserve keys with undefined values in copyWithStructuralSharing#5274
cyphercodes wants to merge 1 commit into
reduxjs:masterfrom
cyphercodes:master

Conversation

@cyphercodes
Copy link
Copy Markdown

Fixes #5271

Problem

When using useLazyQuery, if the trigger is called with args that contain explicit undefined values (e.g. { triggeredAddress: undefined, page: 1 }), the hook's isFetching stays false and data never updates — even though the network request fires and the returned promise resolves with correct data.

Root Cause

copyWithStructuralSharing used Object.keys() which doesn't include keys with undefined values. This caused { triggeredAddress: undefined, page: 1 } and { page: 1 } to be treated as the same object, breaking the hook's ability to track the new cache entry's pending state.

Solution

Use Object.getOwnPropertyNames() instead of Object.keys() to include all keys, including those with undefined values.

Changes

  • Modified copyWithStructuralSharing.ts to use Object.getOwnPropertyNames()
  • Added tests for preserving undefined keys

Testing

  • Added unit tests for copyWithStructuralSharing with undefined values
  • All existing tests pass
  • Build succeeds

Fixes reduxjs#5271 where useLazyQuery's isFetching stayed false when trigger args
contained explicit undefined values. The issue was that Object.keys() doesn't
include keys with undefined values, causing structural sharing to treat
{ triggeredAddress: undefined, page: 1 } and { page: 1 } as the same object.

Changes:
- Use Object.getOwnPropertyNames() instead of Object.keys() to include all keys
- Added tests for preserving undefined keys in copyWithStructuralSharing
@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Apr 5, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@aryaemami59 aryaemami59 changed the title fix: preserve keys with undefined values in copyWithStructuralSharing fix: preserve keys with undefined values in copyWithStructuralSharing Apr 5, 2026
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Apr 5, 2026

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 5a87a7a:

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

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 5, 2026

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

Name Link
🔨 Latest commit 5a87a7a
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/69d1bb4e65422b000806ff5b
😎 Deploy Preview https://deploy-preview-5274--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@aryaemami59 aryaemami59 added the RTK-Query Issues related to Redux-Toolkit-Query label Apr 5, 2026
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.

useLazyQuery: isFetching stays false when trigger args contain undefined values

2 participants