extraInformation is undefined
API Platform version(s) affected: 3.2
Description
I got TypeError: extraInformation is undefined for every built-in queries that modifies something. (i.e. POST, PUT)
How to reproduce
If I have these versions:
- @api-platform/admin: 3.4.7
- react-admin: 4.16.17
And you create a request i.e.
import { useCreate } from 'react-admin';
const [create] = useCreate();
create(
'partner_accounts', {
data: {
// your data
},
}, {
onSuccess: (data) => {
// do sg
},
},
);
I got this error:
TypeError: extraInformation is undefined
pnpm vendors-node_modules_pnpm_fortawesome_react-fontawesome_0_2_0__fortawesome_fontawesome-svg-co-fcd754.js:303103
promise callback*transformReactAdminDataToRequestBody dataProvider.js:149
convertReactAdminRequestToHydraRequest dataProvider.js:307
fetchApi dataProvider.js:403
[yc-api.local:12714:25](https://yc-api.local/#/deals/%2Fapi%2Fdeals%2F6260)
overrideMethod (index):12714
get useDataProvider.js:104
(Async: promise callback)
get useDataProvider.js:102
mutation useUpdate.js:184
fn mutation.js:132
run retryer.js:95
Retryer retryer.js:156
executeMutation mutation.js:126
Mutation mutation.js:86
(Async: promise callback)
execute mutation.js:85
mutate mutationObserver.js:83
update useUpdate.js:274
step useUpdate.js:43
verb useUpdate.js:24
__awaiter useUpdate.js:18
__awaiter useUpdate.js:14
update useUpdate.js:256
useEvent useEvent.js:23
getMutateWithMiddlewares useMutationMiddlewares.js:90
save useEditController.js:148
step useEditController.js:43
verb useEditController.js:24
__awaiter useEditController.js:18
__awaiter useEditController.js:14
save useEditController.js:138
(Async: promise callback)
save useEditController.js:138
handleSubmit SaveButton.js:117
step SaveButton.js:43
verb SaveButton.js:24
__awaiter SaveButton.js:18
__awaiter SaveButton.js:14
handleSubmit SaveButton.js:111
handleSubmit index.esm.mjs:2228
handleClick SaveButton.js:143
step SaveButton.js:43
verb SaveButton.js:24
__awaiter SaveButton.js:18
Possible Solution
Downgrade (?)
Additional Context
Before this, I got these versions w/o any error...
- @api-platform/admin: 3.4.5
- react-admin: 4.16.12
Can you dump content of params ?
https://github.com/api-platform/admin/blob/0d173f58ac74fbdbff4ebc16bfb5b0539ca33236/src/hydra/dataProvider.ts#L355
It seems that it should be declared in this way (?):
const extraInformation: { hasFileField?: boolean } = params.meta ?? {};
Sure.
{
"id": "/api/deals/7631"
"meta": undefined
"data": {
// very long object
},
"previousData": {
// very long object
}
}
And I think, you are right w/ this part: params?.meta ?? {}
Yes, I can confirm that, if I change this line, the problem seems solved.
Thanks. While waiting for fixed version passing empty object as meta prop should make it work without downgrade.
https://marmelab.com/react-admin/Edit.html#mutationoptions
meta prop should make it work without downgrade.
Sadly, (if I try it well) it does not work here
const [create] = useCreate(undefined, undefined, {
meta: {},
onSuccess: data => {
// do sg
},
});
nor here :disappointed:
create('partner_accounts', {
data: {
// big object
},
}, { meta: {} });
Meanwhile the forms are OK, w/ this workarond
<Edit mutationOptions={{ meta: {} }}>
meta prop should make it work Meanwhile the forms are OK, w/ this workarond
<Edit mutationOptions={{ meta: {} }}>
Yes, this is what I wrote about.
Btw, I found another workaround. I replace the file w/ the webpack Encore. I added this line to the config and changed that line you mentioned. (Actually I copied the lines from the PR.)
const webpack = require('webpack');
Encore
.addPlugin(
new webpack.NormalModuleReplacementPlugin(
/@api-platform\/admin\/lib\/hydra\/dataProvider.js/,
'../../../../../assets/js/moduleOverrides/dataProvider.js',
),
)
;
Btw, I found another workaround...
pnpm patch is also a nice tool and first of all useOnSubmit() hook should work if AP on submit logic is enough here.
Is there any permanent solution to this problem? I experience the same thing.
i just use data provider directly with ra admin.
i meantime i solved it with following code change:
if (
!extraInformation**?**.hasFileField &&
!values.some((value) => containFile(value))
) {
return JSON.stringify(hydraData);
}
Waiting for a release... In meantime need to inline the dp I guess?