Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] useUpdate throws an error when using empty id #6505

Open
itaysmalia opened this issue Nov 18, 2024 · 3 comments · May be fixed by #6514
Open

[BUG] useUpdate throws an error when using empty id #6505

itaysmalia opened this issue Nov 18, 2024 · 3 comments · May be fixed by #6514
Assignees
Labels
bug Something isn't working

Comments

@itaysmalia
Copy link

itaysmalia commented Nov 18, 2024

Describe the bug

I have a page that edits a strapi single type using the useForm hook
after I have upgraded the "@refinedev/core" package this page has stopped working and throwing an Error in the browser console that "id" is not provided.
I cannot provide an id because I want to edit a strapi single type instance and strapi's rest api does not accept an id in the url path.
until now I passed an empty string any everything worked fine.
I researched and it looks like this bug (or an api-breaking feature...) is because of this commit in this line

Steps To Reproduce

  1. use the useForm or useUpdate hooks
  2. pass an empty string as the id argument

Expected behavior

the hook does not throws an error and sends the request using the data provider

Packages

  • @refinedev/core

Additional Context

I am importing the "useForm" hook from @refinedev/antd but I don't think that the problem is there...

@itaysmalia itaysmalia added the bug Something isn't working label Nov 18, 2024
@alicanerdurmaz
Copy link
Member

alicanerdurmaz commented Nov 19, 2024

Hello @itaysmalia, thanks for the bug report.

I'm sorry for your trouble, the last thing we want while developing is to introduce breaking changes in minor or patch versions.

The reason I added that id check in this PR is that id was already required on the TypeScript in previous versions. Are you using JavaScript?

@itaysmalia
Copy link
Author

itaysmalia commented Nov 19, 2024

Hi @alicanerdurmaz!
thanks for responding this fast...
Looks like my explanation wasn't detailed enough 😅
I am using typescript, and I am passing an empty string as the id, something like this:

const {...} = useForm({id: '', ...});

and typescript allowed it...
The problem is probably because !"" evaluates to true then the "missing id" error is thrown.
I am using an empty string because in strapi-v4 data provider the id part of the api requests is empty, then then the path ends with ...<resource>/ and it works with the single types rest api paths of strapi.
The possible solution might be checking for null/undefined value in this if statement...
Thank you very much!

@alicanerdurmaz
Copy link
Member

Hello again @itaysmalia, thank you for the detailed explanation!

You're absolutely right, the mentioned PR introduced a breaking change due to a bug. We're targeting the December release to address this issue.

Here's how it should have been handled:
7e71f12#diff-85aeb33cfc5f222b2eca2e2667b6c2ac7a7c639e6f32cdb8c74abc34bde20e5eR324

- if (!id) throw missingIdError;
+ if (typeof id === "undefined") throw missingIdError;

We also believe that making the ID optional is the right approach, but implementing this change affects several parts of the core. We plan to introduce this improvement with Refine 5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants