Skip to content

Conversation

DipakHalkude
Copy link

…eForm

  • Fix useForm hook to combine internal enabled condition with external queryOptions.enabled using AND operation
  • Prevents API calls with undefined IDs when external enabled is true
  • Maintains backward compatibility and user control over query execution
  • Add comprehensive test cases for queryOptions.enabled behavior

Fixes #6867

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

What is the new behavior?

fixes (issue)

Notes for reviewers

…eForm

- Fix useForm hook to combine internal enabled condition with external queryOptions.enabled using AND operation
- Prevents API calls with undefined IDs when external enabled is true
- Maintains backward compatibility and user control over query execution
- Add comprehensive test cases for queryOptions.enabled behavior

Fixes refinedev#6867
@DipakHalkude DipakHalkude requested a review from a team as a code owner September 23, 2025 16:48
Copy link

changeset-bot bot commented Sep 23, 2025

⚠️ No Changeset found

Latest commit: 753b0ac

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Sep 23, 2025

Deploy Preview for refine-doc-live-previews ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 753b0ac
🔍 Latest deploy log https://app.netlify.com/projects/refine-doc-live-previews/deploys/68d2cf7d303248000835ebf9
😎 Deploy Preview https://deploy-preview-7021--refine-doc-live-previews.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.

@DipakHalkude
Copy link
Author

Description

Fixes the bug where useForm hook allows external queryOptions.enabled to override the internal ID safety check, potentially causing API calls with undefined IDs.

Problem

The useForm hook was passing queryOptions to useOne like this:

enabled: !isCreate && id !== undefined,
...props.queryOptions,

This resulted in the internal enabled condition being overridden if the user passes a custom enabled flag through queryOptions. As a result, if the custom enabled is set to true but id is still undefined, the hook proceeds to make an API call with an invalid or missing ID.

Solution

Changed the logic to combine both conditions using AND operation:

enabled: (!isCreate && id !== undefined) && (props.queryOptions?.enabled ?? true),
...props.queryOptions,

This ensures:

  • ✅ Internal ID safety check is never bypassed
  • ✅ External enabled control is still respected
  • ✅ Backward compatibility is maintained
  • ✅ Default behavior is preserved

Changes Made

  1. Fixed logic in useForm hook (packages/core/src/hooks/form/index.ts)

    • Combined internal and external enabled conditions using AND operation
    • Used nullish coalescing (?? true) to maintain default behavior
  2. Added comprehensive test cases (packages/core/src/hooks/form/index.spec.tsx)

    • Test for main bug scenario (external enabled=true, id=undefined)
    • Test for normal operation (both conditions true)
    • Test for external disabled behavior
    • Test for default behavior preservation
    • Test for edge cases

Testing

  • ✅ Logic verification through test script
  • ✅ All existing tests should continue to pass
  • ✅ New test cases cover the bug scenario and edge cases

Related Issue

Fixes #6867

Breaking Changes

None - this is a bug fix that maintains backward compatibility.

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.

[BUG] useForm Hook Allows external enabled to override Internal ID Check, Causing API calls with undefined ID
1 participant