Skip to content

Conversation

@alicanerdurmaz
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

The useCustom hook returns an empty object ({}) for result.data while loading, but the TypeScript type indicates it's CustomResponse<TData>["data"]. This causes TypeScript to miss runtime errors when accessing properties or methods on result.data without proper null checks.

For example, when expecting an array, calling result.data.map() fails at runtime with result.data.map is not a function.

What is the new behavior?

Now result.data returns undefined while loading with the correct type CustomResponse<TData>["data"] | undefined. This forces developers to use proper null checks like result.data?.map(), preventing runtime errors.

fixes #7088

Notes for reviewers

  • Updated return type definition in useCustom.ts
  • Removed EMPTY_OBJECT fallback in favor of returning undefined
  • Added test case to verify result.data is undefined during loading state
  • Updated existing test to check data is defined after successful load

- Changed result.data to return undefined instead of empty object while loading
- Updated type to CustomResponse<TData>[data] | undefined
- Added test to verify undefined data during loading state

Resolves #7088
@alicanerdurmaz alicanerdurmaz requested a review from a team as a code owner November 11, 2025 10:32
@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 010654f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

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

@netlify
Copy link

netlify bot commented Nov 11, 2025

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

Name Link
🔨 Latest commit 010654f
🔍 Latest deploy log https://app.netlify.com/projects/refine-doc-live-previews/deploys/691310b46fab430007691fed
😎 Deploy Preview https://deploy-preview-7109--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.

@cypress
Copy link

cypress bot commented Nov 11, 2025

refine    Run #12335

Run Properties:  status check passed Passed #12335  •  git commit 76d5761d5f ℹ️: Merge 010654f891b185ef1aa3ecc6031cf9bebdeb095c into 3edacb0832090c5d0cfd36f933cb...
Project refine
Branch Review fix/use-custom-return-value-and-type
Run status status check passed Passed #12335
Run duration 18m 49s
Commit git commit 76d5761d5f ℹ️: Merge 010654f891b185ef1aa3ecc6031cf9bebdeb095c into 3edacb0832090c5d0cfd36f933cb...
Committer Alican Erdurmaz
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 22
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 265
View all changes introduced in this branch ↗︎

@alicanerdurmaz alicanerdurmaz marked this pull request as draft November 11, 2025 11:41
@alicanerdurmaz
Copy link
Member Author

closed in favor of #7110

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] useCustom return type is incorrect and undocumented v5 breaking change

2 participants