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

extraInformation is undefined #555

Closed
7system7 opened this issue May 16, 2024 · 10 comments · Fixed by #556
Closed

extraInformation is undefined #555

7system7 opened this issue May 16, 2024 · 10 comments · Fixed by #556
Labels

Comments

@7system7
Copy link

7system7 commented May 16, 2024

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
@PawelSuwinski
Copy link
Contributor

PawelSuwinski commented May 16, 2024

Can you dump content of params ?

extraInformation = params.meta;

It seems that it should be declared in this way (?):

const extraInformation: { hasFileField?: boolean } = params.meta ?? {};

@7system7
Copy link
Author

7system7 commented May 16, 2024

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 ?? {}

@7system7
Copy link
Author

Yes, I can confirm that, if I change this line, the problem seems solved.

@PawelSuwinski
Copy link
Contributor

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

@7system7
Copy link
Author

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 😞

create('partner_accounts', {
  data: {
     // big object
  },
}, { meta: {} });

Meanwhile the forms are OK, w/ this workarond

<Edit mutationOptions={{ meta: {} }}>

@PawelSuwinski
Copy link
Contributor

meta prop should make it work
Meanwhile the forms are OK, w/ this workarond

<Edit mutationOptions={{ meta: {} }}>

Yes, this is what I wrote about.

@7system7
Copy link
Author

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',
    ),
  )
;

@PawelSuwinski
Copy link
Contributor

PawelSuwinski commented May 17, 2024

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.

@papppeter
Copy link

papppeter commented May 28, 2024

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);
  }

@cblokland90
Copy link

Waiting for a release... In meantime need to inline the dp I guess?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants